From 2ca013bcb5f2f81553823e572bca69acf2e577cd Mon Sep 17 00:00:00 2001 From: "qianhao.xu" Date: Fri, 21 Feb 2025 17:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MES/Order/OrderPurchaseService.cs | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/DOAN.Service/MES/Order/OrderPurchaseService.cs b/DOAN.Service/MES/Order/OrderPurchaseService.cs index bf0b377..c9f24e1 100644 --- a/DOAN.Service/MES/Order/OrderPurchaseService.cs +++ b/DOAN.Service/MES/Order/OrderPurchaseService.cs @@ -105,8 +105,8 @@ namespace DOAN.Service.MES.order // 将单元格的数字值转换为DateTime - importDate = cell.DateCellValue.Value; - + importDate = cell?.DateCellValue?? DateTime.MinValue; + importDate = importDate.Date; // 遍历每一行 for (int row = 4; row <= sheet.LastRowNum; row++) @@ -120,12 +120,13 @@ namespace DOAN.Service.MES.order model.PurchaseOrderErp = currentRow.GetCell(1)?.ToString(); model.Poitem = currentRow.GetCell(2)?.ToString(); model.Variety = currentRow.GetCell(3)?.ToString(); - string specordindicator= currentRow.GetCell(4)?.ToString(); - if(!string.IsNullOrEmpty(specordindicator)&&specordindicator=="是") + + string specordindicator = currentRow.GetCell(4)?.ToString(); + if (!string.IsNullOrEmpty(specordindicator) && specordindicator == "是") { model.Specordindicator = 1; } - else if(!string.IsNullOrEmpty(specordindicator) && specordindicator == "否") + else if (!string.IsNullOrEmpty(specordindicator) && specordindicator == "否") { model.Specordindicator = 0; } @@ -133,17 +134,25 @@ namespace DOAN.Service.MES.order { model.Specordindicator = -1; } + model.KdType = currentRow.GetCell(5)?.ToString(); - model.DocumentDate = currentRow.GetCell(6).DateCellValue.Value; + model.DocumentDate = currentRow.GetCell(6)?.DateCellValue; // 直接赋值,如果为 null 则保持 null model.Seller = currentRow.GetCell(7)?.ToString(); model.SalesArea = currentRow.GetCell(8)?.ToString(); model.MaterialName = currentRow.GetCell(9)?.ToString(); model.MaterialCode = currentRow.GetCell(10)?.ToString(); - model.DemandQuantity = (int)currentRow.GetCell(11).NumericCellValue; - model.DeliveryDate= currentRow.GetCell(12).DateCellValue.Value; - model.DeliveryQuantity = (int)currentRow.GetCell(13).NumericCellValue; - model.StartDate = currentRow.GetCell(14).DateCellValue.Value; - model.EndDate = currentRow.GetCell(15).DateCellValue.Value; + + var demandQuantityCell = currentRow.GetCell(11); + model.DemandQuantity = demandQuantityCell != null && demandQuantityCell.CellType == CellType.Numeric ? (int)demandQuantityCell.NumericCellValue : 0; + + model.DeliveryDate = currentRow.GetCell(12)?.DateCellValue; // 直接赋值,如果为 null 则保持 null + + var deliveryQuantityCell = currentRow.GetCell(13); + model.DeliveryQuantity = deliveryQuantityCell != null && deliveryQuantityCell.CellType == CellType.Numeric ? (int)deliveryQuantityCell.NumericCellValue : 0; + + model.StartDate = currentRow.GetCell(14)?.DateCellValue; // 直接赋值,如果为 null 则保持 null + model.EndDate = currentRow.GetCell(15)?.DateCellValue; // 直接赋值,如果为 null 则保持 null + string Orderindicator = currentRow.GetCell(16)?.ToString(); if (!string.IsNullOrEmpty(Orderindicator) && Orderindicator == "是") { @@ -157,11 +166,13 @@ namespace DOAN.Service.MES.order { model.Orderindicator = -1; } + model.RouteCode = currentRow.GetCell(17)?.ToString(); model.Remark = currentRow.GetCell(18)?.ToString(); model.ImportDate = importDate; model.CreatedTime = importDate; model.CreatedBy = username; + orderPurchases.Add(model); } @@ -175,7 +186,14 @@ namespace DOAN.Service.MES.order if(orderPurchases.Count>0) { - return Context.Insertable(orderPurchases).ExecuteCommand(); + int result = 0; + UseTran2(() => + { + Context.Deleteable().Where(x => x.ImportDate == importDate).ExecuteCommand(); + result= Context.Insertable(orderPurchases).ExecuteCommand(); + }); + return result; + } else {