|
@@ -2,11 +2,15 @@
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
|
|
+using System.IO;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
|
|
+using Microsoft.Win32;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
using UniformMaterialManagementSystem.Services;
|
|
using UniformMaterialManagementSystem.Services;
|
|
using UniformMaterialManagementSystem.Views;
|
|
using UniformMaterialManagementSystem.Views;
|
|
|
|
+using UniformMaterialManagementSystem.Utils;
|
|
|
|
+using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
|
|
|
|
|
namespace UniformMaterialManagementSystem.ViewModels
|
|
namespace UniformMaterialManagementSystem.ViewModels
|
|
{
|
|
{
|
|
@@ -28,6 +32,12 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private List<int> _years = [];
|
|
private List<int> _years = [];
|
|
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private List<string> _jobCategories = [];
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private List<string> _userNames = [];
|
|
|
|
+
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private int _selectedYear = DateTime.Now.Year;
|
|
private int _selectedYear = DateTime.Now.Year;
|
|
|
|
|
|
@@ -39,7 +49,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
private readonly IDataBaseService<InspectApply> _inspectApplyService;
|
|
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;
|
|
_inspectionReportService = inspectionReportService;
|
|
_inspectionReportDetailService = inspectionReportDetailService;
|
|
_inspectionReportDetailService = inspectionReportDetailService;
|
|
@@ -52,6 +62,18 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
Years.Add(i);
|
|
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();
|
|
LoadData();
|
|
}
|
|
}
|
|
@@ -235,7 +257,8 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
InspectionReportDetail newDetail = new InspectionReportDetail
|
|
InspectionReportDetail newDetail = new InspectionReportDetail
|
|
{
|
|
{
|
|
- InspectionReportGuid = SelectedInspectionReport.Guid
|
|
|
|
|
|
+ InspectionReportGuid = SelectedInspectionReport.Guid,
|
|
|
|
+ SupervisionUnit = App.CurrentUser!.SupervisionUnit.Name
|
|
};
|
|
};
|
|
|
|
|
|
SelectedInspectionReport.InspectionReportDetails.Add(newDetail); //sql执行update操作,有异常
|
|
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>
|
|
/// 自定义校验
|
|
/// 自定义校验
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -375,7 +496,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(detail.SupervisionUnit))
|
|
if (string.IsNullOrEmpty(detail.SupervisionUnit))
|
|
{
|
|
{
|
|
- errorMessage.Append($"验收组中第{i+1}行单位不允许为空!\n");
|
|
|
|
|
|
+ errorMessage.Append($"验收组中第{i + 1}行单位不允许为空!\n");
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(detail.Inspector))
|
|
if (string.IsNullOrEmpty(detail.Inspector))
|
|
{
|
|
{
|