Feature: send sheet metal properties and upload all BOM items
Enhanced DXF export to send thickness and kfactor properties from SolidWorks to the CutFab API, and ensures all BOM items are uploaded regardless of whether they have DXF files. Changes: - Modified UploadDxfZipAsync to accept and send thickness/kfactor parameters - Updated DxfExportService to extract thickness/kfactor from Item and pass to API - Refactored BOM item creation to happen for all items, not just those with DXF files - This ensures purchased parts, hardware, and other non-sheet-metal items are uploaded 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ namespace ExportDXF.Services
|
||||
Task<int?> CreateDrawingAsync(int equipmentId, string drawingNumber);
|
||||
Task<CutFabApiClient.ApiResponse<int?>> CreateDrawingWithInfoAsync(int equipmentId, string drawingNumber);
|
||||
Task<bool> UploadDrawingPdfAsync(string drawingNumber, string pdfPath, string uploadedBy = null, string notes = null);
|
||||
Task<bool> UploadDxfZipAsync(int drawingId, string zipPath);
|
||||
Task<bool> UploadDxfZipAsync(int drawingId, string zipPath, double? thickness = null, double? kfactor = null);
|
||||
Task<int?> CreateBomItemAsync(object upsertBomItemDto);
|
||||
Task<bool> AutoLinkTemplatesAsync(int drawingId);
|
||||
Task<List<ApiEquipment>> GetEquipmentAsync();
|
||||
@@ -162,7 +162,7 @@ namespace ExportDXF.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> UploadDxfZipAsync(int drawingId, string zipPath)
|
||||
public async Task<bool> UploadDxfZipAsync(int drawingId, string zipPath, double? thickness = null, double? kfactor = null)
|
||||
{
|
||||
if (!File.Exists(zipPath)) return false;
|
||||
using (var form = new MultipartFormDataContent())
|
||||
@@ -172,6 +172,12 @@ namespace ExportDXF.Services
|
||||
var fileName = Path.GetFileName(zipPath);
|
||||
form.Add(fileContent, "file", fileName);
|
||||
|
||||
// Add thickness and kfactor if provided
|
||||
if (thickness.HasValue)
|
||||
form.Add(new StringContent(thickness.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)), "thickness");
|
||||
if (kfactor.HasValue)
|
||||
form.Add(new StringContent(kfactor.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)), "kfactor");
|
||||
|
||||
var resp = await _http.PostAsync($"{_baseUrl}/api/Drawings/{drawingId}/upload-dxf-templates", form).ConfigureAwait(false);
|
||||
return resp.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
@@ -352,11 +352,32 @@ namespace ExportDXF.Services
|
||||
// PartExporter will handle template drawing creation through context
|
||||
_partExporter.ExportItem(item, saveDirectory, context);
|
||||
|
||||
// Always create BOM item first if we have a drawing
|
||||
if (drawingId.HasValue)
|
||||
{
|
||||
var dto = new
|
||||
{
|
||||
DrawingID = drawingId.Value,
|
||||
ItemNo = item.ItemNo,
|
||||
PartNo = !string.IsNullOrEmpty(item.FileName) ? item.FileName : item.PartName,
|
||||
Qty = (int?)item.Quantity,
|
||||
Description = string.IsNullOrWhiteSpace(item.Description) ? null : item.Description,
|
||||
PartName = string.IsNullOrWhiteSpace(item.PartName) ? null : item.PartName,
|
||||
ConfigurationName = string.IsNullOrWhiteSpace(item.Configuration) ? null : item.Configuration,
|
||||
Material = string.IsNullOrWhiteSpace(item.Material) ? null : item.Material,
|
||||
SortOrder = 0,
|
||||
CutTemplateID = (int?)null,
|
||||
FormProgramID = (int?)null
|
||||
};
|
||||
var bomId = _apiClient.CreateBomItemAsync(dto).GetAwaiter().GetResult();
|
||||
LogProgress(context, bomId.HasValue ? $"Created BOM item for {item.ItemNo ?? item.PartName}" : $"Failed to create BOM item for {item.ItemNo ?? item.PartName}", bomId.HasValue ? Color.Green : Color.Red);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(item.FileName))
|
||||
{
|
||||
successCount++;
|
||||
|
||||
// If we know the drawing, upload DXF and BOM row immediately
|
||||
// If we know the drawing, upload DXF
|
||||
if (drawingId.HasValue)
|
||||
{
|
||||
var dxfPath = Path.Combine(saveDirectory, item.FileName + ".dxf");
|
||||
@@ -366,31 +387,16 @@ namespace ExportDXF.Services
|
||||
string zipPath = CreateZipWithSingleFile(dxfPath);
|
||||
try
|
||||
{
|
||||
var okZip = _apiClient.UploadDxfZipAsync(drawingId.Value, zipPath).GetAwaiter().GetResult();
|
||||
// Pass thickness and kfactor from the item
|
||||
double? thickness = item.Thickness > 0 ? item.Thickness : (double?)null;
|
||||
double? kfactor = item.KFactor > 0 ? item.KFactor : (double?)null;
|
||||
var okZip = _apiClient.UploadDxfZipAsync(drawingId.Value, zipPath, thickness, kfactor).GetAwaiter().GetResult();
|
||||
LogProgress(context, okZip ? $"Uploaded DXF: {Path.GetFileName(dxfPath)}" : $"Failed to upload DXF: {Path.GetFileName(dxfPath)}", okZip ? Color.Green : Color.Red);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { if (File.Exists(zipPath)) File.Delete(zipPath); } catch { }
|
||||
}
|
||||
|
||||
// Create BOM item
|
||||
var dto = new
|
||||
{
|
||||
DrawingID = drawingId.Value,
|
||||
ItemNo = item.ItemNo,
|
||||
PartNo = item.FileName,
|
||||
Qty = (int?)item.Quantity,
|
||||
Description = string.IsNullOrWhiteSpace(item.Description) ? null : item.Description,
|
||||
PartName = string.IsNullOrWhiteSpace(item.PartName) ? null : item.PartName,
|
||||
ConfigurationName = string.IsNullOrWhiteSpace(item.Configuration) ? null : item.Configuration,
|
||||
Material = string.IsNullOrWhiteSpace(item.Material) ? null : item.Material,
|
||||
SortOrder = 0,
|
||||
CutTemplateID = (int?)null,
|
||||
FormProgramID = (int?)null
|
||||
};
|
||||
var bomId = _apiClient.CreateBomItemAsync(dto).GetAwaiter().GetResult();
|
||||
LogProgress(context, bomId.HasValue ? $"Created BOM item for {item.ItemNo ?? item.PartName}" : $"Failed to create BOM item for {item.ItemNo ?? item.PartName}", bomId.HasValue ? Color.Green : Color.Red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user