浏览代码

修改生成检验申请表附表为word格式

LT069288 3 月之前
父节点
当前提交
f93ec9fa52

二进制
UniformMaterialManagementSystem/Template/军需物资质量检验申请表模板_附表.docx


+ 10 - 0
UniformMaterialManagementSystem/Utils/CommonUtil.cs

@@ -13,6 +13,16 @@ namespace UniformMaterialManagementSystem.Utils
         ProductCompany,
         Supervision
     }
+
+    /// <summary>
+    /// 单据状态
+    /// </summary>
+    public enum BillStatus
+    {
+        Add,
+        Modify
+    }
+
     public static class CommonUtil
     {
         

+ 7 - 7
UniformMaterialManagementSystem/Utils/InspectApplyUtil.cs

@@ -170,31 +170,31 @@ namespace UniformMaterialManagementSystem.Utils
         /// <summary>
         /// 导出检验申请表附表
         /// </summary>
-        public static void ExportInspectApplyAttachedPdf(InspectApply inspectApply)
+        public static void ExportInspectApplyAttached(InspectApply inspectApply)
         {
             var templateFilePath = "Template\\军需物资质量检验申请表模板_附表.docx";
 
             SaveFileDialog saveFileDialog = new SaveFileDialog()
             {
                 FileName = "被装材料检验申请-附表-" + inspectApply.ApplyNo + "-" + WordUtil.GenerateFileSerialNumber(),
-                Filter = "PDF文件格式 (*.pdf)|*.pdf",
+                Filter = "word文件格式 (*.docx)|*.docx",
                 Title = "请选择检验申请表导出的位置"
             };
             if (saveFileDialog.ShowDialog() == false) return;
             var destinationFile = saveFileDialog.FileName;
 
-            var tempFile = $"Template\\temp_{WordUtil.GenerateFileSerialNumber()}.docx";
+            //var tempFile = $"Template\\temp_{WordUtil.GenerateFileSerialNumber()}.docx";
 
-            File.Copy(templateFilePath, tempFile);
+            File.Copy(templateFilePath, destinationFile);
             //将申请表明细行,包号、数量组成list
             var packetNoList = GetPacketNoList(inspectApply);
 
-            GenerateInspectApplyAttachedFile(tempFile, packetNoList, inspectApply);
+            GenerateInspectApplyAttachedFile(destinationFile, packetNoList, inspectApply);
 
             //将tempFile转换成pdf文件
-            WordUtil.SaveWordToPdf(tempFile, destinationFile);
+            //WordUtil.SaveWordToPdf(tempFile, destinationFile);
             //删除临时文件
-            File.Delete(tempFile);
+            //File.Delete(tempFile);
 
             MessageBox.Show("文档已生成!");
         }

+ 23 - 22
UniformMaterialManagementSystem/ViewModels/ContractPageViewModel.cs

@@ -78,7 +78,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         [ObservableProperty]
         private ContractModel? _selectedUnExportContract;
 
-        private string _contactStatus = "Add";//Add:新增 Modify:修改
+        private BillStatus _contactStatus = BillStatus.Add;
 
         #endregion
 
@@ -199,7 +199,7 @@ namespace UniformMaterialManagementSystem.ViewModels
 
             ClearInput();
 
-            _contactStatus = "Add";
+            _contactStatus = BillStatus.Add;
         }
 
         /// <summary>
@@ -215,7 +215,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             //绑定数据源
             BindSelectedContractAndDetail();
 
-            _contactStatus = "Modify";
+            _contactStatus = BillStatus.Modify;
         }
 
         private void BindSelectedContractAndDetail()
@@ -231,8 +231,9 @@ namespace UniformMaterialManagementSystem.ViewModels
             Attachment = SelectedUnExportContract.Attachment;
             ApplyAttachment = SelectedUnExportContract.ApplyAttachment;
 
+            var existDetails = _contractDetailService.QueryNoTracking(x => x.ContractGuid == SelectedUnExportContract.Guid).Include(x=>x.Material).ToList();
             ContractDetails.Clear();
-            foreach (var detail in SelectedUnExportContract.ContractDetails)
+            foreach (var detail in existDetails)
             {
                 ContractDetails.Add(detail);
             }
@@ -274,7 +275,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                 return;
             }
 
-            if ("Add".Equals(_contactStatus))  //新增
+            if (_contactStatus == BillStatus.Add)  //新增
             {
                 var success = SaveContractAndDetail();
                 if (success == null || !(bool)success) return;
@@ -286,7 +287,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                 /* 清空界面数据 */
                 ClearInput();
             }
-            else if ("Modify".Equals(_contactStatus)) //修改
+            else if (_contactStatus == BillStatus.Modify) //修改
             {
                 if (SelectedUnExportContract == null)
                 {
@@ -702,20 +703,20 @@ namespace UniformMaterialManagementSystem.ViewModels
                 return;
             }
 
-            if ("Modify".Equals(_contactStatus))
-            {
-                //var detail = _contractDetailService?.Get(x => x.Guid == _selectedContractDetail.Guid);
-                //if (detail != null)
-                //{
-                //    _contractDetailService?.Delete(_selectedContractDetail);
-                //}
-
-                var detail = SelectedUnExportContract?.ContractDetails.FirstOrDefault(x => x.Guid == _selectedContractDetail.Guid);
-                if (detail != null)
-                {
-                    SelectedUnExportContract?.ContractDetails.Remove(detail);
-                }
-            }
+            //if ("Modify".Equals(_contactStatus))
+            //{
+            //    //var detail = _contractDetailService?.Get(x => x.Guid == _selectedContractDetail.Guid);
+            //    //if (detail != null)
+            //    //{
+            //    //    _contractDetailService?.Delete(_selectedContractDetail);
+            //    //}
+
+            //    var detail = SelectedUnExportContract?.ContractDetails.FirstOrDefault(x => x.Guid == _selectedContractDetail.Guid);
+            //    if (detail != null)
+            //    {
+            //        SelectedUnExportContract?.ContractDetails.Remove(detail);
+            //    }
+            //}
 
             ContractDetails.Remove(_selectedContractDetail);
         }
@@ -788,7 +789,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             }
 
             /* 校验材料合同号不重复 */
-            if ("Add".Equals(_contactStatus))
+            if (_contactStatus == BillStatus.Add)
             {
                 var contract = _contractService.Get(x => x.ContractNo == ContractNo);
                 if (contract != null)
@@ -796,7 +797,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                     errorMessage.Append($"材料合同号【{ContractNo}】已存在,不允许重复录入!\n");
                 }
             }
-            else if ("Modify".Equals(_contactStatus))
+            else if (_contactStatus == BillStatus.Modify)
             {
                 var count = _contractService.GetAll(x => x.ContractNo == ContractNo).ToList().Count;
                 if (count > 1)

+ 2 - 2
UniformMaterialManagementSystem/ViewModels/InspectionRecordPageViewModel.cs

@@ -306,14 +306,14 @@ namespace UniformMaterialManagementSystem.ViewModels
         /// 测试导出检验申请表附表
         /// </summary>
         [RelayCommand]
-        private void ExportInspectApplyAttachedPdf()
+        private void ExportInspectApplyAttached()
         {
             if (InspectApply == null)
             {
                 MessageBox.Show("请先选中一条数据,再执行删除操作!");
                 return;
             }
-            InspectApplyUtil.ExportInspectApplyAttachedPdf(InspectApply);
+            InspectApplyUtil.ExportInspectApplyAttached(InspectApply);
 
         }
 

+ 1 - 1
UniformMaterialManagementSystem/Views/InspectionRecordPage.xaml

@@ -292,7 +292,7 @@
                                         </ControlTemplate>
                                     </Button.Template>
                                 </Button>
-                                <Button Command="{Binding ExportInspectApplyAttachedPdfCommand}">
+                                <Button Command="{Binding ExportInspectApplyAttachedCommand}">
                                     <Button.Template>
                                         <ControlTemplate>
                                             <Border