소스 검색

优化材料合同、检验申请导入导出数据包

LT069288 3 달 전
부모
커밋
192b6b9614

+ 18 - 7
UniformMaterialManagementSystem/ViewModels/ContractPageViewModel.cs

@@ -575,7 +575,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         /// 导出数据包
         /// </summary>
         [RelayCommand]
-        private async Task ExportDataPacket()
+        private void ExportDataPacket()
         {
             if (UnExportContracts.Count == 0) return;
 
@@ -617,9 +617,6 @@ namespace UniformMaterialManagementSystem.ViewModels
                 contract.ExportStatus = true;
             }
 
-            var success = _contractService.SaveChanges();
-            if (!success) return;
-
             //导出合同数据包
             var contracts = contractList.ToArray();
             var materialCompanies = contracts.Select(x => x.Company).Distinct().ToArray();//材料企业
@@ -656,11 +653,24 @@ namespace UniformMaterialManagementSystem.ViewModels
             }
 
             //对导出数据进行加密,用户选择保存位置
-           await DataBaseUtil.ExportData();
+           var path = DataBaseUtil.ExportData();
+           if (string.IsNullOrEmpty(path))
+           {
+                //取消保存,将选中合同修改为未导出状态
+                foreach (var contract in contractList)
+                {
+                    contract.ExportStatus = false;
+                }
+                return;
+           }
+           
            MessageBox.Show("材料合同数据包导出成功!");
 
-           //重新加载数据
-           LoadUnExportData();
+           //保存导出状态
+           _contractService.SaveChanges();
+
+            //重新加载数据
+            LoadUnExportData();
         }
 
         /// <summary>
@@ -670,6 +680,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         private async Task ImportDataPacket()
         {
             var path = DataBaseUtil.ImportData();
+            if (string.IsNullOrEmpty(path)) return;
 
              var contracts = DataBaseUtil.QueryAll<Contract>(path, q =>
                             q.Include(x => x.Company)

+ 15 - 4
UniformMaterialManagementSystem/ViewModels/InspectionRecordPageViewModel.cs

@@ -204,6 +204,7 @@ namespace UniformMaterialManagementSystem.ViewModels
 
             //导入并解密db文件
             var path = DataBaseUtil.ImportData();
+            if (string.IsNullOrEmpty(path)) return;
 
             var inspectApplies = DataBaseUtil.QueryAll<InspectApply>(path, p => p
                 .Include(x => x.Material)
@@ -247,7 +248,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         /// 导出报检数据包
         /// </summary>
         [RelayCommand]
-        private async Task ExportInspectApplyData()
+        private void ExportInspectApplyData()
         {
             var result = MessageBox.Show("确认导出报检数据包吗?(仅导出“导出状态”为“未导出”的检验申请单)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
             if (result != MessageBoxResult.OK) return;
@@ -269,8 +270,6 @@ namespace UniformMaterialManagementSystem.ViewModels
             {
                 inspect.ExportStatus = true;
             }
-            var success = _inspectService.SaveChanges();
-            if (!success) return;
 
             var serialNumbers = _serialService.Query().ToArray();
 
@@ -316,7 +315,19 @@ namespace UniformMaterialManagementSystem.ViewModels
                 DataBaseUtil.ExportTable(serialNumbers, "SerialNumbers");
             }
 
-            await DataBaseUtil.ExportData();
+            var path = DataBaseUtil.ExportData();
+            if (string.IsNullOrEmpty(path))
+            {
+                //将导出状态更新为未导出
+                foreach (var inspect in inspectApplies)
+                {
+                    inspect.ExportStatus = false;
+                }
+
+                return;
+            }
+
+            _inspectService.SaveChanges();
 
             MessageBox.Show("报检数据包导出成功!");
         }