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:
@@ -1,10 +1,11 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ExportDXF
|
namespace ExportDXF
|
||||||
{
|
{
|
||||||
public class DrawingInfo
|
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 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; }
|
public string EquipmentNo { get; set; }
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ namespace ExportDXF
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(DrawingNo))
|
||||||
|
return EquipmentNo ?? string.Empty;
|
||||||
return $"{EquipmentNo} {DrawingNo}";
|
return $"{EquipmentNo} {DrawingNo}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +38,21 @@ namespace ExportDXF
|
|||||||
var match = drawingFormatRegex.Match(input);
|
var match = drawingFormatRegex.Match(input);
|
||||||
|
|
||||||
if (match.Success == false)
|
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;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var dwg = new DrawingInfo();
|
var dwg = new DrawingInfo();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user