Prechádzať zdrojové kódy

检验报告导出文档功能

LT069288 3 mesiacov pred
rodič
commit
5cf588f637

BIN
Document/被装材料业务系统需求描述 v1.docx


BIN
Document/被装材料数据库设计.docx


BIN
UniformMaterialManagementSystem/Template/军需物资质量监督检验报告模板.docx


+ 3 - 0
UniformMaterialManagementSystem/UniformMaterialManagementSystem.csproj

@@ -71,6 +71,9 @@
 		<None Update="Template\军需物资质量检验申请表模板.docx">
 			<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 		</None>
+		<None Update="Template\军需物资质量监督检验报告模板.docx">
+		  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+		</None>
 		<None Update="Template\附件1被装材料采购合同明细数据模板.xlsx">
 		  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 		</None>

+ 124 - 3
UniformMaterialManagementSystem/ViewModels/InspectionReportPageViewModel.cs

@@ -2,11 +2,15 @@
 using CommunityToolkit.Mvvm.Input;
 using Microsoft.EntityFrameworkCore;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Text;
 using System.Windows;
+using Microsoft.Win32;
 using UniformMaterialManagementSystem.Entities;
 using UniformMaterialManagementSystem.Services;
 using UniformMaterialManagementSystem.Views;
+using UniformMaterialManagementSystem.Utils;
+using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
 
 namespace UniformMaterialManagementSystem.ViewModels
 {
@@ -28,6 +32,12 @@ namespace UniformMaterialManagementSystem.ViewModels
         [ObservableProperty]
         private List<int> _years = [];
 
+        [ObservableProperty]
+        private List<string> _jobCategories = [];
+
+        [ObservableProperty]
+        private List<string> _userNames = [];
+
         [ObservableProperty]
         private int _selectedYear = DateTime.Now.Year;
 
@@ -39,7 +49,7 @@ namespace UniformMaterialManagementSystem.ViewModels
 
         private readonly IDataBaseService<InspectApply> _inspectApplyService;
 
-        public InspectionReportPageViewModel(IDataBaseService<InspectionReport> inspectionReportService, IDataBaseService<InspectionReportDetail> inspectionReportDetailService, IDataBaseService<InspectApply> inspectApplyService)
+        public InspectionReportPageViewModel(IDataBaseService<InspectionReport> inspectionReportService, IDataBaseService<InspectionReportDetail> inspectionReportDetailService, IDataBaseService<InspectApply> inspectApplyService, IDataBaseService<User> userService)
         {
             _inspectionReportService = inspectionReportService;
             _inspectionReportDetailService = inspectionReportDetailService;
@@ -52,6 +62,18 @@ namespace UniformMaterialManagementSystem.ViewModels
                 Years.Add(i);
             }
 
+            //初始化职位类别
+            JobCategories.Add("组长");
+            JobCategories.Add("成员");
+
+            //初始化人员
+            var userList = userService.QueryNoTracking(x =>
+                x.IsEnabled && x.SupervisionUnitGuid == App.CurrentUser!.SupervisionUnitGuid && string.IsNullOrEmpty(x.CompanyName)).ToList();
+            foreach (var user in userList)
+            {
+                UserNames.Add(user.UserName);
+            }
+
             /* 加载数据 */
             LoadData();
         }
@@ -235,7 +257,8 @@ namespace UniformMaterialManagementSystem.ViewModels
 
             InspectionReportDetail newDetail = new InspectionReportDetail
             {
-                InspectionReportGuid = SelectedInspectionReport.Guid
+                InspectionReportGuid = SelectedInspectionReport.Guid,
+                SupervisionUnit = App.CurrentUser!.SupervisionUnit.Name
             };
 
             SelectedInspectionReport.InspectionReportDetails.Add(newDetail); //sql执行update操作,有异常
@@ -319,6 +342,104 @@ namespace UniformMaterialManagementSystem.ViewModels
             }
         }
 
+        /// <summary>
+        /// 导出检验报告
+        /// </summary>
+        [RelayCommand]
+        private void ExportInspectionReport()
+        {
+            if (SelectedInspectionReport == null) return;
+
+            const string templateFilePath = "Template\\军需物资质量监督检验报告模板.docx";
+            SaveFileDialog saveFileDialog = new SaveFileDialog()
+            {
+                Title = "请选择检验报告保存位置",
+                FileName = "被装材料检验报告-" + SelectedInspectionReport.ReportNo + "-" + WordUtil.GenerateFileSerialNumber(),
+                Filter = "PDF文件格式 (*.pdf)|*.pdf",
+            };
+            if (saveFileDialog.ShowDialog() == false) return;
+            var destinationFile = saveFileDialog.FileName;
+
+            var dictionary = CreateDictionary(SelectedInspectionReport);
+            var tempFile = "Template\\temp.docx";
+
+            WordUtil.GenerateWordByTemplate(templateFilePath, tempFile, dictionary);
+            WordUtil.SaveWordToPdf(tempFile, destinationFile);
+
+            //删除临时文件
+            File.Delete(tempFile);
+
+            MessageBox.Show("文档已生成!");
+
+
+
+        }
+
+        private Dictionary<string, string> CreateDictionary(InspectionReport inspectionReport)
+        {
+            Dictionary<string, string> dictionary = new Dictionary<string, string>();
+            dictionary.Add("ReportNo", inspectionReport.ReportNo);
+            dictionary.Add("Department", inspectionReport.Department);
+            dictionary.Add("ReportTime", inspectionReport.ReportTime.ToString("yyyy-MM-dd"));
+            //检验类别
+            switch (inspectionReport.InspectApply.InspCategory)
+            {
+                case "报样检验":
+                    dictionary.Add("FirstSelected", "\u25a0");//选中框
+                    break;
+                case "首批检验":
+                    dictionary.Add("SecondSelected", "\u25a0");//选中框
+                    break;
+                case "过程检验":
+                    dictionary.Add("ThirdSelected", "\u25a0");//选中框
+                    break;
+                case "出厂检验":
+                    dictionary.Add("ForthSelected", "\u25a0");//选中框
+                    break;
+            }
+            dictionary.Add("ProductName", inspectionReport.InspectApply.ProductName);
+            dictionary.Add("Company", inspectionReport.InspectApply.Company);
+            dictionary.Add("InspQuantity", inspectionReport.InspectApply.InspQuantity + inspectionReport.InspectApply.Material.MeasureUnit);
+            dictionary.Add("ProductDate", inspectionReport.InspectApply.StartProductDate.ToString("yyyy-MM") + "至" + inspectionReport.InspectApply.EndProductDate.ToString("yyyy-MM"));
+
+            //采购机构、合同号
+            StringBuilder purchaseCompanies = new StringBuilder();
+            StringBuilder contractNos = new StringBuilder();
+            foreach (var detail in inspectionReport.InspectApply.InspectApplyContractDetails)
+            {
+                purchaseCompanies.Append(detail.PurchaseCompanyShortName).Append("、");
+                contractNos.Append(detail.ContractNo).Append("、");
+            }
+            dictionary.Add("PurchaseCompany", purchaseCompanies.ToString().Substring(0, purchaseCompanies.Length - 1));
+            dictionary.Add("ContractNumber", contractNos.ToString().Substring(0, contractNos.Length - 1));
+
+            dictionary.Add("ReportBasis", inspectionReport.ReportBasis);
+            dictionary.Add("ReportDesc", inspectionReport.ReportDesc);
+            dictionary.Add("ConclusionDesc", inspectionReport.ConclusionDesc);
+
+            //验收组
+            for (int i = 0; i < 5; i++)
+            {
+                if (i< inspectionReport.InspectionReportDetails.Count)
+                {
+                    var detail = inspectionReport.InspectionReportDetails[i];
+                    dictionary.Add("JobCategory" + i, detail.JobCategory);
+                    dictionary.Add("SupervisionUnit" + i, detail.SupervisionUnit);
+                    dictionary.Add("Inspector" + i, detail.Inspector);
+                }
+                else
+                {
+                    dictionary.Add("JobCategory" + i, string.Empty);
+                    dictionary.Add("SupervisionUnit" + i, string.Empty);
+                    dictionary.Add("Inspector" + i, string.Empty);
+                }
+            }
+
+            dictionary.Add("EditUser",inspectionReport.EditUser);
+
+            return dictionary;
+        }
+
         /// <summary>
         /// 自定义校验
         /// </summary>
@@ -375,7 +496,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                     }
                     if (string.IsNullOrEmpty(detail.SupervisionUnit))
                     {
-                        errorMessage.Append($"验收组中第{i+1}行单位不允许为空!\n");
+                        errorMessage.Append($"验收组中第{i + 1}行单位不允许为空!\n");
                     }
                     if (string.IsNullOrEmpty(detail.Inspector))
                     {

+ 56 - 10
UniformMaterialManagementSystem/Views/InspectionReportPage.xaml

@@ -365,6 +365,31 @@
                                 </ControlTemplate>
                             </Button.Template>
                         </Button>
+                        <Separator />
+                        <Button Command="{Binding ExportInspectionReportCommand}">
+                            <Button.Template>
+                                <ControlTemplate>
+                                    <Border
+                                        Width="60"
+                                        Background="{TemplateBinding Background}"
+                                        CornerRadius="5">
+                                        <StackPanel HorizontalAlignment="Center" Orientation="Vertical">
+                                            <TextBlock
+                                                HorizontalAlignment="Center"
+                                                FontFamily="{StaticResource FluentSystemIconsRegular}"
+                                                FontSize="20"
+                                                Text="{x:Static utils:RegularFontUtil.Dock_20}" />
+                                            <TextBlock Text="导出报告" />
+                                        </StackPanel>
+                                    </Border>
+                                    <ControlTemplate.Triggers>
+                                        <Trigger Property="IsMouseOver" Value="True">
+                                            <Setter Property="Background" Value="LightGray" />
+                                        </Trigger>
+                                    </ControlTemplate.Triggers>
+                                </ControlTemplate>
+                            </Button.Template>
+                        </Button>
                     </ToolBar>
                 </ToolBarPanel>
             </Border>
@@ -810,7 +835,7 @@
                                 </Style>
                             </DataGrid.Resources>
                             <DataGrid.Columns>
-                                <!--<DataGridTemplateColumn Width="100" Header="检验组">
+                                <DataGridTemplateColumn Width="100" Header="检验组">
                                     <DataGridTemplateColumn.CellTemplate>
                                         <DataTemplate>
                                             <TextBlock
@@ -824,31 +849,52 @@
                                             <ComboBox
                                                 Height="25"
                                                 Background="White"
-                                                SelectedItem="{Binding JobCategory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
-                                                <ComboBoxItem Content="组长" IsSelected="True" />
-                                                <ComboBoxItem Content="成员" />
-                                            </ComboBox>
+                                                ItemsSource="{Binding DataContext.JobCategories, RelativeSource={RelativeSource AncestorType=UserControl}}"
+                                                SelectedItem="{Binding JobCategory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                         </DataTemplate>
                                     </DataGridTemplateColumn.CellEditingTemplate>
-                                </DataGridTemplateColumn>-->
-                                <DataGridTextColumn
+                                </DataGridTemplateColumn>
+
+                                <!--<DataGridTextColumn
                                     Width="100"
                                     Binding="{Binding JobCategory, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                                     ElementStyle="{StaticResource TextColumnElementStyle}"
-                                    Header="检验组" />
+                                    Header="检验组" />-->
+
                                 <DataGridTextColumn
                                     Width="300"
                                     Binding="{Binding SupervisionUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                                     ElementStyle="{StaticResource TextColumnElementStyle}"
                                     Header="单位" />
-                                <DataGridTextColumn
+
+                                <!--<DataGridTextColumn
                                     Width="100"
                                     Binding="{Binding Inspector, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                     EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                                     ElementStyle="{StaticResource TextColumnElementStyle}"
-                                    Header="姓名" />
+                                    Header="姓名" />-->
+                                <DataGridTemplateColumn Width="100" Header="姓名">
+                                    <DataGridTemplateColumn.CellTemplate>
+                                        <DataTemplate>
+                                            <TextBlock
+                                                HorizontalAlignment="Center"
+                                                VerticalAlignment="Center"
+                                                Text="{Binding Inspector}" />
+                                        </DataTemplate>
+                                    </DataGridTemplateColumn.CellTemplate>
+                                    <DataGridTemplateColumn.CellEditingTemplate>
+                                        <DataTemplate>
+                                            <ComboBox
+                                                Height="25"
+                                                Background="White"
+                                                IsEditable="True"
+                                                ItemsSource="{Binding DataContext.UserNames, RelativeSource={RelativeSource AncestorType=UserControl}}"
+                                                SelectedItem="{Binding Inspector, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                                        </DataTemplate>
+                                    </DataGridTemplateColumn.CellEditingTemplate>
+                                </DataGridTemplateColumn>
                             </DataGrid.Columns>
                         </DataGrid>
                     </Grid>

+ 0 - 4
UniformMaterialManagementSystem/Views/InspectionReportPage.xaml.cs

@@ -15,10 +15,6 @@ namespace UniformMaterialManagementSystem.Views
 
             this.DataContext = App.Current.Services.GetService<InspectionReportPageViewModel>();
 
-            //JobCategoryCombo.ItemsSource = new List<string>()
-            //{
-            //    "组长","成员"
-            //};
         }
 
         private void InspectTypeText_TextChanged(object sender, TextChangedEventArgs e)