fix(parts): normalize drawing names for matching

- Strip directories and extensions and compare using ToUpperInvariant
- Improves resilience when sources differ in path/casing/extension formatting
- Ensures accurate QtyNested across plates with duplicates
This commit is contained in:
2025-10-29 11:04:08 -04:00
parent 67d4342e0f
commit 0486ebfdbe

View File

@@ -117,14 +117,30 @@ namespace PepApi.Core
part.QtyNested = 0; part.QtyNested = 0;
var nestedOn = new List<int>(); var nestedOn = new List<int>();
var partName = part.Name.ToUpper(); // Normalize drawing names by stripping directories and extensions
// to make matching resilient to format differences between sources.
string Normalize(string? name)
{
if (string.IsNullOrWhiteSpace(name)) return string.Empty;
try
{
var fileOnly = System.IO.Path.GetFileNameWithoutExtension(name);
return fileOnly.ToUpperInvariant();
}
catch
{
return name.Trim().ToUpperInvariant();
}
}
var partName = Normalize(part.Name);
for (int i = 0; i < nest.Plates.Count; i++) for (int i = 0; i < nest.Plates.Count; i++)
{ {
var plate = nest.Plates[i]; var plate = nest.Plates[i];
var qtyNested = 0; var qtyNested = 0;
qtyNested = plate.Parts.Count(p => p.DrawingName?.ToUpper() == partName); qtyNested = plate.Parts.Count(p => Normalize(p.DrawingName) == partName);
// plate.Duplicates is actually the quantity, so 1 Duplicate = 1 plate // plate.Duplicates is actually the quantity, so 1 Duplicate = 1 plate
qtyNested *= plate.Duplicates; qtyNested *= plate.Duplicates;