diff --git a/ExportDXF/Services/CutFabApiClient.cs b/ExportDXF/Services/CutFabApiClient.cs index ecfe4c4..3b14cd5 100644 --- a/ExportDXF/Services/CutFabApiClient.cs +++ b/ExportDXF/Services/CutFabApiClient.cs @@ -18,7 +18,7 @@ namespace ExportDXF.Services Task CreateDrawingAsync(int equipmentId, string drawingNumber); Task> CreateDrawingWithInfoAsync(int equipmentId, string drawingNumber); Task UploadDrawingPdfAsync(string drawingNumber, string pdfPath, string uploadedBy = null, string notes = null); - Task UploadDxfZipAsync(int drawingId, string zipPath); + Task UploadDxfZipAsync(int drawingId, string zipPath, double? thickness = null, double? kfactor = null); Task CreateBomItemAsync(object upsertBomItemDto); Task AutoLinkTemplatesAsync(int drawingId); Task> GetEquipmentAsync(); @@ -162,7 +162,7 @@ namespace ExportDXF.Services } } - public async Task UploadDxfZipAsync(int drawingId, string zipPath) + public async Task 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; } diff --git a/ExportDXF/Services/DxfExportService.cs b/ExportDXF/Services/DxfExportService.cs index 7f481e6..eec4e29 100644 --- a/ExportDXF/Services/DxfExportService.cs +++ b/ExportDXF/Services/DxfExportService.cs @@ -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); } } }