Przeglądaj źródła

fix: 解决删除后和导出数据包异常退出的问题

JaneDoe 2 miesięcy temu
rodzic
commit
36c9f6b0d2

+ 8 - 12
UniformMaterialManagementSystem/ViewModels/DeliveryReceiptViewModel.cs

@@ -391,10 +391,9 @@ namespace UniformMaterialManagementSystem.ViewModels
             // 新增行直接删除
             if (CurrDeliveryReceipt.IsNewRow)
             {
-                // todo 直接删除会切换行
                 _isExcute = false;
                 DeliveryReceipts.Remove(CurrDeliveryReceipt);
-                //CurrDeliveryReceipt = null;
+                fdgDelivery.Items.Refresh();
                 return;
             }
 
@@ -420,6 +419,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             string currContracNo = CurrDeliveryReceipt.ContractNo;
             string currProductName = CurrDeliveryReceipt.ProductName;
             DeliveryReceipts.Remove(CurrDeliveryReceipt);
+            fdgDelivery.Items.Refresh();
 
             // 保存到数据库
             _service.Delete(CurrDeliveryReceipt);
@@ -429,7 +429,6 @@ namespace UniformMaterialManagementSystem.ViewModels
                 MessageBox.Show("删除失败!");
                 return;
             }
-
             MessageBox.Show("删除成功");
 
             // 删除后反写到数据库
@@ -655,10 +654,8 @@ namespace UniformMaterialManagementSystem.ViewModels
             bool isNeedRollback = true;
             try
             {
-                // 需要存在 bin\DataBase 目录,且目录下存在一份 .db 文件,需要存在表
-                // 选择的发货单导出到 .db 文件:根据主键判断,存在数据则更新,不存在则插入
-                var deliveries = DeliveryReceipts;
-                DataBaseUtil.ExportTable(deliveries, "DeliveryReceipts"); // 数据库表名输错会抛出异常,但在本方法里获取不到抛出异常
+                // 选择的发货单导出到 .db 文件:自动迁移数据库
+                DataBaseUtil.ExportTable(selectedDeliveries, "DeliveryReceipts", true);
 
                 // 选择发货单的明细导出到 .db 文件
                 List<DeliveryReceiptDetail> details = new List<DeliveryReceiptDetail>();
@@ -666,7 +663,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                 {
                     details.AddRange(delivery.DeliveryReceiptDetails);
                 }
-                DataBaseUtil.ExportTable(details, "DeliveryReceiptDetails");
+                DataBaseUtil.ExportTable(details, "DeliveryReceiptDetails", false);
 
                 // 将选择的数据导出为加密数据包
                 string exportPath = DataBaseUtil.ExportData();
@@ -909,6 +906,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                 }
             }
 
+            // 未选择行,直接返回
             if (selectedCount == 0) { return; }
 
             // 只删除新增行,则更新数据后直接返回
@@ -919,7 +917,6 @@ namespace UniformMaterialManagementSystem.ViewModels
                 CurrDeliveryReceipt.ShippedQty = details.Select(x => x.ShippedQuantity).Sum();
                 OnPropertyChanged(nameof(CurrDeliveryReceipt));
                 fdgDeliveryDetail.Items.Refresh(); // 刷新子表索引
-
                 return;
             }
 
@@ -949,7 +946,6 @@ namespace UniformMaterialManagementSystem.ViewModels
             fdgDeliveryDetail.Items.Refresh();
             CurrDeliveryReceipt.ShippedPackets = details.Count;
             CurrDeliveryReceipt.ShippedQty = details.Select(x => x.ShippedQuantity).Sum();
-            //OnCurrDeliveryReceiptChanged(CurrDeliveryReceipt);
             OnPropertyChanged(nameof(CurrDeliveryReceipt));
 
             // 保存到数据库
@@ -965,7 +961,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             // 删除成功提示
             MessageBox.Show($"删除 {savedRows.Count} 行已保存行。");
 
-            // 反写
+            // 反写合同明细、检验申请明细
             bool isSuccCD = UpdataContractDetail(CurrDeliveryReceipt.ContractNo, CurrDeliveryReceipt.ProductName);
             bool isSuccAD = UpdateApplyDetail(packBatckNos, false);
             if (isSuccCD && isSuccAD)
@@ -1596,7 +1592,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             var details = CurrDeliveryReceipt!.DeliveryReceiptDetails;
             if (CurrDeliveryReceipt.ShippedPackets == 0 || CurrDeliveryReceipt.ShippedQty == 0 || details == null || details.Count == 0)
             {
-                MessageBox.Show("发货单明细为空,不允许保存!");
+                MessageBox.Show("发运数量 或 发运包数为 0 ,不允许保存!");
                 return false;
             }