fix: parse equipment number from part names without drawing number

Add equipmentOnlyRegex fallback so names like "5028 Prox switch bracket"
correctly extract equipment number 5028 even without a drawing number.
Handle null DrawingNo in ToString and UI dropdown population.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 20:37:28 -05:00
parent 5ec66f9039
commit 2721c33a39

View File

@@ -1,10 +1,11 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
namespace ExportDXF
{
public class DrawingInfo
{
private static Regex drawingFormatRegex = new Regex(@"(?<equipmentNo>[345]\d{3}(-\d+\w{1,2})?)\s?(?<dwgNo>[ABEP]\d+(-?(\d+[A-Z]?))?)", RegexOptions.IgnoreCase);
private static Regex equipmentOnlyRegex = new Regex(@"^(?<equipmentNo>[345]\d{3}(-\d+\w{1,2})?)\b", RegexOptions.IgnoreCase);
public string EquipmentNo { get; set; }
@@ -14,6 +15,8 @@ namespace ExportDXF
public override string ToString()
{
if (string.IsNullOrEmpty(DrawingNo))
return EquipmentNo ?? string.Empty;
return $"{EquipmentNo} {DrawingNo}";
}
@@ -35,7 +38,21 @@ namespace ExportDXF
var match = drawingFormatRegex.Match(input);
if (match.Success == false)
{
// Try matching just the equipment number (e.g. "5028 Prox switch bracket")
var eqMatch = equipmentOnlyRegex.Match(input);
if (eqMatch.Success)
{
return new DrawingInfo
{
EquipmentNo = eqMatch.Groups["equipmentNo"].Value,
DrawingNo = null,
Source = input
};
}
return null;
}
var dwg = new DrawingInfo();
@@ -46,4 +63,4 @@ namespace ExportDXF
return dwg;
}
}
}
}