|
@@ -1,16 +1,14 @@
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
-using Microsoft.Win32;
|
|
|
using System.Collections.ObjectModel;
|
|
|
-using System.IO;
|
|
|
using System.Text;
|
|
|
using System.Windows;
|
|
|
+using UniformMaterialManagementSystem.Custom;
|
|
|
using UniformMaterialManagementSystem.Entities;
|
|
|
using UniformMaterialManagementSystem.Models;
|
|
|
using UniformMaterialManagementSystem.Services;
|
|
|
using UniformMaterialManagementSystem.Utils;
|
|
|
-using UniformMaterialManagementSystem.Views;
|
|
|
|
|
|
namespace UniformMaterialManagementSystem.ViewModels
|
|
|
{
|
|
@@ -23,18 +21,12 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
[ObservableProperty]
|
|
|
private InspectionReportModel? _selectedInspectionReport;
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
- private List<int> _years = [];
|
|
|
-
|
|
|
[ObservableProperty]
|
|
|
private List<string> _jobCategories = [];
|
|
|
|
|
|
[ObservableProperty]
|
|
|
private List<string> _userNames = [];
|
|
|
|
|
|
- [ObservableProperty]
|
|
|
- private int _selectedYear = DateTime.Now.Year;
|
|
|
-
|
|
|
private InspectionReportDetail? _selectedInspectionReportDetail;
|
|
|
|
|
|
private readonly IDataBaseService<InspectionReport> _inspectionReportService;
|
|
@@ -49,13 +41,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
_inspectionReportDetailService = inspectionReportDetailService;
|
|
|
_inspectApplyService = inspectApplyService;
|
|
|
|
|
|
- //初始化年份
|
|
|
- int currYear = DateTime.Now.Year;
|
|
|
- for (int i = currYear - 10; i <= currYear + 1; i++)
|
|
|
- {
|
|
|
- Years.Add(i);
|
|
|
- }
|
|
|
-
|
|
|
//初始化职位类别
|
|
|
JobCategories.Add("组长");
|
|
|
JobCategories.Add("成员");
|
|
@@ -79,7 +64,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
private void LoadData()
|
|
|
{
|
|
|
//询问是否保存
|
|
|
- //AskIsSave();
|
|
|
+ if(!AskIsSave()) return;
|
|
|
|
|
|
var inspectionReports = _inspectionReportService.Query()
|
|
|
.Include(x => x.InspectionReportDetails)
|
|
@@ -87,7 +72,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
.ThenInclude(x => x.Material)
|
|
|
.Include(x => x.InspectApply)
|
|
|
.ThenInclude(x => x.InspectApplyContractDetails)
|
|
|
- .Where(x => x.InspectApply.Year == SelectedYear)
|
|
|
+ .Where(x => x.InspectApply.Year == App.CurrentUser.WorkYear)
|
|
|
.ToList();
|
|
|
|
|
|
InspectionReports.Clear();
|
|
@@ -97,155 +82,44 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- ///判断单据是否有修改,true:已修改 false:未修改
|
|
|
- /// </summary>
|
|
|
- private bool IsCurrentReportChanged(InspectionReportModel inspectionReportModel)
|
|
|
- {
|
|
|
- var inspectionReport = _inspectionReportService.Get(x => x.Guid == inspectionReportModel.Guid);
|
|
|
- if (inspectionReport == null) //新增
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- inspectionReportModel.ModifyInspectionReport(inspectionReport);
|
|
|
- var state = _inspectionReportService.Entry(inspectionReport);
|
|
|
- if (state == EntityState.Modified)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- //判断明细表是否新增、修改或删除
|
|
|
- var reportDetails = inspectionReportModel.InspectionReportDetails;
|
|
|
- var existDetails = _inspectionReportDetailService.Query(x => x.InspectionReportGuid == inspectionReportModel.Guid).ToList();
|
|
|
-
|
|
|
- foreach (var detail in reportDetails) //新增行或修改行操作
|
|
|
- {
|
|
|
- var detailState = _inspectionReportDetailService.Entry(detail);
|
|
|
- if (detailState != EntityState.Unchanged)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var detail in existDetails) //删除行操作
|
|
|
- {
|
|
|
- var detailState = _inspectionReportDetailService.Entry(detail);
|
|
|
- if (detailState == EntityState.Deleted)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 询问是否保存更改
|
|
|
- /// </summary>
|
|
|
- private bool AskIsSave()
|
|
|
- {
|
|
|
- if (SelectedInspectionReport == null) return true;
|
|
|
- var isChanged = IsCurrentReportChanged(SelectedInspectionReport);
|
|
|
- if (!isChanged) return true;
|
|
|
-
|
|
|
- var result = MessageBox.Show($"检验报告编号【{SelectedInspectionReport?.ReportNo}】已修改,是否保存修改?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- if (result == MessageBoxResult.Yes)
|
|
|
- {
|
|
|
- Dictionary<string, string> dictionary = CustomValidate();
|
|
|
- if (dictionary.ContainsKey("result") && !string.IsNullOrEmpty(dictionary["result"]))
|
|
|
- {
|
|
|
- MessageBox.Show(dictionary["result"], "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
- return false;
|
|
|
- }
|
|
|
- //保存修改
|
|
|
- SaveInspectionReport();
|
|
|
- }
|
|
|
- else if (result == MessageBoxResult.No) //放弃更改
|
|
|
- {
|
|
|
- var inspectionReport = _inspectionReportService.Get(x => x.Guid == SelectedInspectionReport!.Guid);
|
|
|
-
|
|
|
- if (inspectionReport == null) //新增行直接移除
|
|
|
- {
|
|
|
- if (SelectedInspectionReport != null) InspectionReports.Remove(SelectedInspectionReport);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- _inspectionReportService.SetEntryState(inspectionReport, EntityState.Unchanged);
|
|
|
-
|
|
|
- if (SelectedInspectionReport != null)
|
|
|
- {
|
|
|
- ModifyModelFromInspectReport(SelectedInspectionReport, inspectionReport);
|
|
|
-
|
|
|
- var details = _inspectionReportDetailService
|
|
|
- .GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
|
|
|
- SelectedInspectionReport.InspectionReportDetails.Clear();
|
|
|
- foreach (var detail in details) //重新将数据库的数据赋值过来,并设置跟踪状态Unchanged
|
|
|
- {
|
|
|
- SelectedInspectionReport.InspectionReportDetails.Add(detail);
|
|
|
- _inspectionReportDetailService.SetEntryState(detail, EntityState.Unchanged);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- private void ModifyModelFromInspectReport(InspectionReportModel model, InspectionReport report)
|
|
|
- {
|
|
|
- model.ReportNo = report.ReportNo;
|
|
|
- model.Department = report.Department;
|
|
|
- model.ReportTime = report.ReportTime;
|
|
|
- model.ReportBasis = report.ReportBasis;
|
|
|
- model.IsSample = report.IsSample;
|
|
|
- model.ReportDesc = report.ReportDesc;
|
|
|
- model.Conclusion = report.Conclusion;
|
|
|
- model.ConclusionDesc = report.ConclusionDesc;
|
|
|
- model.EditUser = report.EditUser;
|
|
|
- model.InspectionReportDetails = report.InspectionReportDetails;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// 新增检验报告
|
|
|
- /// </summary>
|
|
|
- [RelayCommand]
|
|
|
- public void AddInspectionReport()
|
|
|
- {
|
|
|
- if (!AskIsSave()) return;
|
|
|
-
|
|
|
- /* 打开窗口,展示检验报告状态未生成的检验申请列表,选择检验申请,携带检验申请数据 */
|
|
|
- SelectInspectApplyWindowViewModel viewModel =
|
|
|
- new SelectInspectApplyWindowViewModel(_inspectApplyService, "InspectionReport");
|
|
|
- SelectInspectApplyWindow inspectApplyWindow = new SelectInspectApplyWindow(viewModel);
|
|
|
-
|
|
|
- var result = inspectApplyWindow.ShowDialog();
|
|
|
- if (result == null || !(bool)result) return;
|
|
|
-
|
|
|
- var inspectApply = inspectApplyWindow.DataGridMain.SelectedItem as InspectApply;
|
|
|
- if (inspectApply == null) return;
|
|
|
-
|
|
|
- //新增检验报告并设置默认值
|
|
|
- InspectionReport inspectionReport = new InspectionReport
|
|
|
- {
|
|
|
- InspectApply = inspectApply,
|
|
|
- InspectApplyGuid = inspectApply.Guid,
|
|
|
- ReportNo = inspectApply.ApplyNo.Replace("申请", ""),
|
|
|
- Department = App.CurrentUser!.SupervisionUnit.Name,
|
|
|
- ReportTime = DateTime.Now,
|
|
|
- ReportBasis = "依据" + inspectApply.Material.NormName,
|
|
|
- Conclusion = "合格",
|
|
|
- EditUser = App.CurrentUser.UserName,
|
|
|
- InspectionReportDetails = []
|
|
|
- };
|
|
|
-
|
|
|
- InspectionReportModel model = new InspectionReportModel(inspectionReport);
|
|
|
- InspectionReports.Add(model);
|
|
|
-
|
|
|
- //选中当前行
|
|
|
- SelectedInspectionReport = model;
|
|
|
- }
|
|
|
+ ///// <summary>
|
|
|
+ ///// 新增检验报告
|
|
|
+ ///// </summary>
|
|
|
+ //public void AddInspectionReport()
|
|
|
+ //{
|
|
|
+ // if (!AskIsSave()) return;
|
|
|
+
|
|
|
+ // /* 打开窗口,展示检验报告状态未生成的检验申请列表,选择检验申请,携带检验申请数据 */
|
|
|
+ // SelectInspectApplyWindowViewModel viewModel =
|
|
|
+ // new SelectInspectApplyWindowViewModel(_inspectApplyService, "InspectionReport");
|
|
|
+ // SelectInspectApplyWindow inspectApplyWindow = new SelectInspectApplyWindow(viewModel);
|
|
|
+
|
|
|
+ // var result = inspectApplyWindow.ShowDialog();
|
|
|
+ // if (result == null || !(bool)result) return;
|
|
|
+
|
|
|
+ // var inspectApply = inspectApplyWindow.DataGridMain.SelectedItem as InspectApply;
|
|
|
+ // if (inspectApply == null) return;
|
|
|
+
|
|
|
+ // //新增检验报告并设置默认值
|
|
|
+ // InspectionReport inspectionReport = new InspectionReport
|
|
|
+ // {
|
|
|
+ // InspectApply = inspectApply,
|
|
|
+ // InspectApplyGuid = inspectApply.Guid,
|
|
|
+ // ReportNo = inspectApply.ApplyNo.Replace("申请", ""),
|
|
|
+ // Department = App.CurrentUser!.SupervisionUnit.Name,
|
|
|
+ // ReportTime = DateTime.Now,
|
|
|
+ // ReportBasis = "依据" + inspectApply.Material.NormName,
|
|
|
+ // Conclusion = "合格",
|
|
|
+ // EditUser = App.CurrentUser.UserName,
|
|
|
+ // InspectionReportDetails = []
|
|
|
+ // };
|
|
|
+
|
|
|
+ // InspectionReportModel model = new InspectionReportModel(inspectionReport);
|
|
|
+ // InspectionReports.Add(model);
|
|
|
+
|
|
|
+ // //选中当前行
|
|
|
+ // SelectedInspectionReport = model;
|
|
|
+ //}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新增验收组
|
|
@@ -261,7 +135,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
SupervisionUnit = App.CurrentUser!.SupervisionUnit.Name
|
|
|
};
|
|
|
|
|
|
- SelectedInspectionReport.InspectionReportDetails.Add(newDetail); //sql执行update操作,有异常
|
|
|
+ SelectedInspectionReport.InspectionReportDetails.Add(newDetail);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -305,25 +179,18 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
|
|
|
var inspectionReport = _inspectionReportService.Get(x => x.Guid == SelectedInspectionReport.Guid);
|
|
|
- if (inspectionReport == null) //新增行
|
|
|
- {
|
|
|
- InspectionReport newInspectionReport = new InspectionReport();
|
|
|
- SelectedInspectionReport.ModifyInspectionReport(newInspectionReport);
|
|
|
- _inspectionReportService.Insert(newInspectionReport);
|
|
|
- }
|
|
|
- else //判断是否修改
|
|
|
- {
|
|
|
- SelectedInspectionReport.ModifyInspectionReport(inspectionReport);
|
|
|
+ if (inspectionReport == null) return;
|
|
|
+
|
|
|
+ SelectedInspectionReport.ModifyInspectionReport(inspectionReport);
|
|
|
|
|
|
- ////处理明细表新增行(无法跟踪明细表的新增行)
|
|
|
- var existReportDetails = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == inspectionReport.Guid).ToList();
|
|
|
- foreach (var detail in SelectedInspectionReport.InspectionReportDetails)
|
|
|
+ ////处理明细表新增行(无法跟踪明细表的新增行)
|
|
|
+ var existReportDetails = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == inspectionReport.Guid).ToList();
|
|
|
+ foreach (var detail in SelectedInspectionReport.InspectionReportDetails)
|
|
|
+ {
|
|
|
+ var existDetail = existReportDetails.FirstOrDefault(x => x.Guid == detail.Guid);
|
|
|
+ if (existDetail == null)
|
|
|
{
|
|
|
- var existDetail = existReportDetails.FirstOrDefault(x => x.Guid == detail.Guid);
|
|
|
- if (existDetail == null)
|
|
|
- {
|
|
|
- _inspectionReportDetailService.Insert(detail);
|
|
|
- }
|
|
|
+ _inspectionReportDetailService.Insert(detail);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -342,102 +209,47 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 导出检验报告
|
|
|
+ /// 删除检验报告
|
|
|
/// </summary>
|
|
|
[RelayCommand]
|
|
|
- private void ExportInspectionReport()
|
|
|
+ private void RemoveInspectionReport()
|
|
|
{
|
|
|
- if (SelectedInspectionReport == null) return;
|
|
|
-
|
|
|
- if (!AskIsSave()) return;
|
|
|
-
|
|
|
- const string templateFilePath = "Template\\军需物资质量监督检验报告模板.docx";
|
|
|
- SaveFileDialog saveFileDialog = new SaveFileDialog()
|
|
|
+ if (SelectedInspectionReport == null)
|
|
|
{
|
|
|
- Title = "请选择检验报告保存位置",
|
|
|
- FileName = "被装材料检验报告-" + SelectedInspectionReport.ReportNo + "-" + WordUtil.GenerateFileSerialNumber(),
|
|
|
- Filter = "PDF文件格式 (*.pdf)|*.pdf",
|
|
|
- };
|
|
|
- if (saveFileDialog.ShowDialog() == false) return;
|
|
|
- var destinationFile = saveFileDialog.FileName;
|
|
|
+ MessageBox.Show("请选中一行,再执行删除操作!", "提示",MessageBoxButton.OK,MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- var dictionary = CreateDictionary(SelectedInspectionReport);
|
|
|
- var tempFile = $"Template\\temp_{WordUtil.GenerateFileSerialNumber()}.docx";
|
|
|
+ var result = MessageBox.Show($"确定删除编号为【{SelectedInspectionReport.ReportNo}】的检验报告吗?", "提示", MessageBoxButton.OKCancel,
|
|
|
+ MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.OK) return;
|
|
|
|
|
|
- WordUtil.GenerateWordByTemplate(templateFilePath, tempFile, dictionary);
|
|
|
- WordUtil.SaveWordToPdf(tempFile, destinationFile);
|
|
|
+ //反写检验申请单的检验报告生成状态
|
|
|
+ var inspectApply = _inspectApplyService.Get(x => x.Guid == SelectedInspectionReport.InspectApplyGuid);
|
|
|
+ if (inspectApply != null)
|
|
|
+ {
|
|
|
+ inspectApply.ReportStatus = false;
|
|
|
+ }
|
|
|
|
|
|
- //删除临时文件
|
|
|
- File.Delete(tempFile);
|
|
|
+ //删除
|
|
|
+ _inspectionReportService.Delete(x=>x.Guid == SelectedInspectionReport.Guid); //删除主表时会级联删除子表
|
|
|
+ _inspectionReportService.SaveChanges();
|
|
|
|
|
|
- MessageBox.Show("文档已生成!");
|
|
|
+ //重新加载数据
|
|
|
+ LoadData();
|
|
|
}
|
|
|
|
|
|
- private Dictionary<string, string> CreateDictionary(InspectionReportModel inspectionReport)
|
|
|
+ /// <summary>
|
|
|
+ /// 导出检验报告
|
|
|
+ /// </summary>
|
|
|
+ [RelayCommand]
|
|
|
+ private void ExportInspectionReport()
|
|
|
{
|
|
|
- Dictionary<string, string> dictionary = new()
|
|
|
- {
|
|
|
- { "ReportNo", inspectionReport.ReportNo },
|
|
|
- { "Department", inspectionReport.Department },
|
|
|
- { "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-dd") + "至" + inspectionReport.InspectApply.EndProductDate.ToString("yyyy-MM-dd"));
|
|
|
-
|
|
|
- //采购机构、合同号
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (SelectedInspectionReport == null) return;
|
|
|
|
|
|
- dictionary.Add("EditUser", inspectionReport.EditUser);
|
|
|
+ if (!AskIsSave()) return;
|
|
|
|
|
|
- return dictionary;
|
|
|
+ InspectionReportUtil.ExportInspectionReportFile(SelectedInspectionReport);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -533,5 +345,115 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
result.Add("result", errorMessage.ToString());
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ ///判断单据是否有修改,true:已修改 false:未修改
|
|
|
+ /// </summary>
|
|
|
+ private bool IsCurrentReportChanged(InspectionReportModel inspectionReportModel)
|
|
|
+ {
|
|
|
+ var inspectionReport = _inspectionReportService.Get(x => x.Guid == inspectionReportModel.Guid);
|
|
|
+ if (inspectionReport == null) //新增
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ inspectionReportModel.ModifyInspectionReport(inspectionReport);
|
|
|
+ var state = _inspectionReportService.Entry(inspectionReport);
|
|
|
+ if (state == EntityState.Modified)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断明细表是否新增、修改或删除
|
|
|
+ var reportDetails = inspectionReportModel.InspectionReportDetails;
|
|
|
+ var existDetails = _inspectionReportDetailService.Query(x => x.InspectionReportGuid == inspectionReportModel.Guid).ToList();
|
|
|
+
|
|
|
+ foreach (var detail in reportDetails) //新增行或修改行操作
|
|
|
+ {
|
|
|
+ var detailState = _inspectionReportDetailService.Entry(detail);
|
|
|
+ if (detailState != EntityState.Unchanged)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var detail in existDetails) //删除行操作
|
|
|
+ {
|
|
|
+ var detailState = _inspectionReportDetailService.Entry(detail);
|
|
|
+ if (detailState == EntityState.Deleted)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 询问是否保存更改
|
|
|
+ /// </summary>
|
|
|
+ private bool AskIsSave()
|
|
|
+ {
|
|
|
+ if (SelectedInspectionReport == null) return true;
|
|
|
+ var isChanged = IsCurrentReportChanged(SelectedInspectionReport);
|
|
|
+ if (!isChanged) return true;
|
|
|
+
|
|
|
+ var result = MessageBox.Show($"检验报告编号【{SelectedInspectionReport?.ReportNo}】已修改,是否保存修改?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
+ if (result == MessageBoxResult.Yes)
|
|
|
+ {
|
|
|
+ Dictionary<string, string> dictionary = CustomValidate();
|
|
|
+ if (dictionary.ContainsKey("result") && !string.IsNullOrEmpty(dictionary["result"]))
|
|
|
+ {
|
|
|
+ MessageBox.Show(dictionary["result"], "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //保存修改
|
|
|
+ SaveInspectionReport();
|
|
|
+ }
|
|
|
+ else if (result == MessageBoxResult.No) //放弃更改
|
|
|
+ {
|
|
|
+ var inspectionReport = _inspectionReportService.Get(x => x.Guid == SelectedInspectionReport!.Guid);
|
|
|
+
|
|
|
+ if (inspectionReport == null) //新增行直接移除
|
|
|
+ {
|
|
|
+ if (SelectedInspectionReport != null) InspectionReports.Remove(SelectedInspectionReport);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _inspectionReportService.SetEntryState(inspectionReport, EntityState.Unchanged);
|
|
|
+
|
|
|
+ if (SelectedInspectionReport != null)
|
|
|
+ {
|
|
|
+ ModifyModelFromInspectReport(SelectedInspectionReport, inspectionReport);
|
|
|
+
|
|
|
+ var details = _inspectionReportDetailService
|
|
|
+ .GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
|
|
|
+ SelectedInspectionReport.InspectionReportDetails.Clear();//detail被跟踪,clear之后变为Deleted状态
|
|
|
+ foreach (var detail in details) //重新将数据库的数据赋值过来,并设置跟踪状态Unchanged
|
|
|
+ {
|
|
|
+ SelectedInspectionReport.InspectionReportDetails.Add(detail);
|
|
|
+ _inspectionReportDetailService.SetEntryState(detail, EntityState.Unchanged);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ModifyModelFromInspectReport(InspectionReportModel model, InspectionReport report)
|
|
|
+ {
|
|
|
+ model.ReportNo = report.ReportNo;
|
|
|
+ model.Department = report.Department;
|
|
|
+ model.ReportTime = report.ReportTime;
|
|
|
+ model.ReportBasis = report.ReportBasis;
|
|
|
+ model.IsSample = report.IsSample;
|
|
|
+ model.ReportDesc = report.ReportDesc;
|
|
|
+ model.Conclusion = report.Conclusion;
|
|
|
+ model.ConclusionDesc = report.ConclusionDesc;
|
|
|
+ model.EditUser = report.EditUser;
|
|
|
+ model.InspectionReportDetails = report.InspectionReportDetails;
|
|
|
+ }
|
|
|
}
|
|
|
}
|