|
@@ -1,26 +1,30 @@
|
|
-using System.Collections.ObjectModel;
|
|
|
|
-using System.Text;
|
|
|
|
-using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
+using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
+using System.Collections.ObjectModel;
|
|
|
|
+using System.ComponentModel.DataAnnotations;
|
|
|
|
+using System.Text;
|
|
|
|
+using UniformMaterialManagementSystem.Custom;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
using UniformMaterialManagementSystem.Services;
|
|
using UniformMaterialManagementSystem.Services;
|
|
|
|
|
|
namespace UniformMaterialManagementSystem.ViewModels
|
|
namespace UniformMaterialManagementSystem.ViewModels
|
|
{
|
|
{
|
|
- public partial class InspectionReportInputPageViewModel : ObservableObject
|
|
|
|
|
|
+ public partial class InspectionReportInputPageViewModel : ObservableValidator
|
|
{
|
|
{
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _reportNo;
|
|
|
|
|
|
+ private string _reportNo = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _department;
|
|
|
|
|
|
+ [Required(ErrorMessage = "检验部门不能为空")]
|
|
|
|
+ private string _department = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
|
|
+ [Required(ErrorMessage = "检验时间不能为空")]
|
|
private DateTime _reportTime;
|
|
private DateTime _reportTime;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _inspectCategory;
|
|
|
|
|
|
+ private string _inspectCategory = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private string? _purchaseCompanyNames;
|
|
private string? _purchaseCompanyNames;
|
|
@@ -29,21 +33,36 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
private string? _contractNos;
|
|
private string? _contractNos;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string? _reportBasis;
|
|
|
|
|
|
+ [Required(ErrorMessage = "检验依据不能为空")]
|
|
|
|
+ private string _reportBasis = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private bool _isSample;
|
|
private bool _isSample;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _reportDesc;
|
|
|
|
|
|
+ [Required(ErrorMessage = "检验情况及主要问题不能为空")]
|
|
|
|
+ private string _reportDesc = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _conclusion;
|
|
|
|
|
|
+ private string _conclusion = string.Empty;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private string _conclusionDesc;
|
|
|
|
|
|
+ [Required(ErrorMessage = "检验结论不能为空")]
|
|
|
|
+ private string _conclusionDesc = string.Empty;
|
|
|
|
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private string _editUser = string.Empty;
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private ObservableCollection<InspectionReportDetail> _inspectionReportDetails = [];
|
|
|
|
|
|
|
|
+ private InspectionReportDetail? _selectedInspectionReportDetail;
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private List<string> _jobCategories = [];
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private List<string> _userNames = [];
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private ObservableCollection<InspectApply> _inspectApplies = [];
|
|
private ObservableCollection<InspectApply> _inspectApplies = [];
|
|
@@ -53,9 +72,24 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
private readonly IDataBaseService<InspectApply> _inspectApplyService;
|
|
private readonly IDataBaseService<InspectApply> _inspectApplyService;
|
|
|
|
|
|
- public InspectionReportInputPageViewModel(IDataBaseService<InspectApply> inspectApplyService)
|
|
|
|
|
|
+ private readonly IDataBaseService<InspectionReport> _inspectionReportService;
|
|
|
|
+
|
|
|
|
+ public InspectionReportInputPageViewModel(IDataBaseService<InspectApply> inspectApplyService, IDataBaseService<User> userService,IDataBaseService<InspectionReport> inspectionReportService)
|
|
{
|
|
{
|
|
_inspectApplyService = inspectApplyService;
|
|
_inspectApplyService = inspectApplyService;
|
|
|
|
+ _inspectionReportService = inspectionReportService;
|
|
|
|
+
|
|
|
|
+ //检验组
|
|
|
|
+ JobCategories.Add("组长");
|
|
|
|
+ JobCategories.Add("成员");
|
|
|
|
+
|
|
|
|
+ //姓名
|
|
|
|
+ var users = userService.QueryNoTracking(
|
|
|
|
+ x => x.IsEnabled && x.SupervisionUnitGuid == App.CurrentUser.SupervisionUnitGuid).ToList();
|
|
|
|
+ foreach (var user in users)
|
|
|
|
+ {
|
|
|
|
+ UserNames.Add(user.UserName);
|
|
|
|
+ }
|
|
|
|
|
|
LoadData();
|
|
LoadData();
|
|
}
|
|
}
|
|
@@ -68,7 +102,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
{
|
|
{
|
|
var inspectApplyList = _inspectApplyService.QueryNoTracking()
|
|
var inspectApplyList = _inspectApplyService.QueryNoTracking()
|
|
.Include(x => x.Material)
|
|
.Include(x => x.Material)
|
|
- .Include(x=>x.InspectApplyContractDetails)
|
|
|
|
|
|
+ .Include(x => x.InspectApplyContractDetails)
|
|
.Where(x => x.Year == App.CurrentUser.WorkYear && !x.ReportStatus).ToList();
|
|
.Where(x => x.Year == App.CurrentUser.WorkYear && !x.ReportStatus).ToList();
|
|
|
|
|
|
InspectApplies.Clear();
|
|
InspectApplies.Clear();
|
|
@@ -84,18 +118,167 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
private void SaveInspectionReport()
|
|
private void SaveInspectionReport()
|
|
{
|
|
{
|
|
- int i = 0;
|
|
|
|
|
|
+ //校验是否选择检验申请单
|
|
|
|
+ if (SelectedInspectApply == null)
|
|
|
|
+ {
|
|
|
|
+ MessageEx.ShowWarningDialog("请双击检验申请表行数据进行新增,再执行保存!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //校验所有属性
|
|
|
|
+ ValidateAllProperties();
|
|
|
|
+ if (HasErrors)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //校验验收组
|
|
|
|
+ Dictionary<string, string> dictionary = CustomValidate();
|
|
|
|
+ if (dictionary.ContainsKey("result") && !string.IsNullOrEmpty(dictionary["result"]))
|
|
|
|
+ {
|
|
|
|
+ MessageEx.ShowWarningDialog(dictionary["result"]);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //新增检验报告
|
|
|
|
+ AddInspectionReportAndDetail();
|
|
|
|
+
|
|
|
|
+ //反写检验申请表的检验报告状态
|
|
|
|
+ var inspect = _inspectApplyService.Get(x => x.Guid == SelectedInspectApply.Guid);
|
|
|
|
+ if (inspect == null) return;
|
|
|
|
+ inspect.ReportStatus = true;
|
|
|
|
+
|
|
|
|
+ var result = _inspectionReportService.SaveChanges();
|
|
|
|
+ if (result)
|
|
|
|
+ {
|
|
|
|
+ MessageEx.ShowInformation("保存成功!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //重新加载检验申请列表
|
|
|
|
+ LoadData();
|
|
|
|
+
|
|
|
|
+ //清空录入内容
|
|
|
|
+ ClearInput();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ClearInput()
|
|
|
|
+ {
|
|
|
|
+ SelectedInspectApply = null;
|
|
|
|
+
|
|
|
|
+ ReportNo = string.Empty;
|
|
|
|
+ Department = string.Empty;
|
|
|
|
+ ReportTime = DateTime.Now;
|
|
|
|
+ InspectCategory = string.Empty;
|
|
|
|
+ PurchaseCompanyNames = string.Empty;
|
|
|
|
+ ContractNos = string.Empty;
|
|
|
|
+ ReportBasis = string.Empty;
|
|
|
|
+ IsSample = false;
|
|
|
|
+ Conclusion = string.Empty;
|
|
|
|
+ ReportDesc = string.Empty;
|
|
|
|
+ ConclusionDesc = string.Empty;
|
|
|
|
+ EditUser = string.Empty;
|
|
|
|
+ InspectionReportDetails.Clear();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void AddInspectionReportAndDetail()
|
|
|
|
+ {
|
|
|
|
+ InspectionReport report = new()
|
|
|
|
+ {
|
|
|
|
+ InspectApplyGuid = SelectedInspectApply.Guid,
|
|
|
|
+ ReportNo = ReportNo,
|
|
|
|
+ Department = Department,
|
|
|
|
+ ReportTime = ReportTime,
|
|
|
|
+ ReportBasis = ReportBasis,
|
|
|
|
+ IsSample = IsSample,
|
|
|
|
+ ReportDesc = ReportDesc,
|
|
|
|
+ Conclusion = Conclusion,
|
|
|
|
+ ConclusionDesc = ConclusionDesc,
|
|
|
|
+ EditUser = EditUser,
|
|
|
|
+ InspectionReportDetails = []
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ foreach (var detail in InspectionReportDetails)
|
|
|
|
+ {
|
|
|
|
+ report.InspectionReportDetails.Add(detail);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _inspectionReportService.Insert(report);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 选择检验申请单行改变事件
|
|
|
|
|
|
+ /// 自定义校验
|
|
/// </summary>
|
|
/// </summary>
|
|
- [RelayCommand]
|
|
|
|
- private void InspectApplySelectionChanged(InspectApply inspectApply)
|
|
|
|
|
|
+ private Dictionary<string, string> CustomValidate()
|
|
{
|
|
{
|
|
- SelectedInspectApply = inspectApply;
|
|
|
|
|
|
+ Dictionary<string, string> result = new Dictionary<string, string>();
|
|
|
|
+ StringBuilder errorMessage = new StringBuilder();
|
|
|
|
+
|
|
|
|
+ //校验验收组
|
|
|
|
+ var details = InspectionReportDetails;
|
|
|
|
+ if (details == null || details.Count == 0)
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append("验收组不允许为空!\n");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ int leaderCount = 0;
|
|
|
|
+ int memberCount = 0;
|
|
|
|
+ for (int i = 0; i < details.Count; i++)
|
|
|
|
+ {
|
|
|
|
+ var detail = details[i];
|
|
|
|
+ if (string.IsNullOrEmpty(detail.JobCategory))
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append($"验收组中第{i + 1}行检验组不允许为空!\n");
|
|
|
|
+ }
|
|
|
|
+ if (string.IsNullOrEmpty(detail.SupervisionUnit))
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append($"验收组中第{i + 1}行单位不允许为空!\n");
|
|
|
|
+ }
|
|
|
|
+ if (string.IsNullOrEmpty(detail.Inspector))
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append($"验收组中第{i + 1}行姓名不允许为空!\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (detail.JobCategory == "组长")
|
|
|
|
+ {
|
|
|
|
+ leaderCount++;
|
|
|
|
+ }
|
|
|
|
+ else if (detail.JobCategory == "成员")
|
|
|
|
+ {
|
|
|
|
+ memberCount++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (leaderCount != 1)
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append("验收组中至少包含1名组长,不能超过1名组长!\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (memberCount < 1)
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append("验收组中至少包含1名成员!\n");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var isRepeat = InspectionReportDetails.GroupBy(x => x.Inspector).Any(g => g.Count() > 1);
|
|
|
|
+ if (isRepeat != null && (bool)isRepeat)
|
|
|
|
+ {
|
|
|
|
+ errorMessage.Append("验收组姓名有重复,请检查!\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ result.Add("result", errorMessage.ToString());
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 选择检验申请单行改变事件
|
|
|
|
+ /// </summary>
|
|
|
|
+ //[RelayCommand]
|
|
|
|
+ //private void InspectApplySelectionChanged(InspectApply inspectApply)
|
|
|
|
+ //{
|
|
|
|
+ // SelectedInspectApply = inspectApply;
|
|
|
|
+ //}
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 鼠标双击事件
|
|
/// 鼠标双击事件
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -115,7 +298,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
Conclusion = "合格";
|
|
Conclusion = "合格";
|
|
ReportDesc = "检验情况及主要问题";
|
|
ReportDesc = "检验情况及主要问题";
|
|
ConclusionDesc = "请录入检验结论";
|
|
ConclusionDesc = "请录入检验结论";
|
|
-
|
|
|
|
|
|
+ EditUser = App.CurrentUser.UserName;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -124,7 +307,12 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
private void AddInspectionReportDetail()
|
|
private void AddInspectionReportDetail()
|
|
{
|
|
{
|
|
|
|
+ InspectionReportDetail detail = new InspectionReportDetail()
|
|
|
|
+ {
|
|
|
|
+ SupervisionUnit = App.CurrentUser.SupervisionUnit.Name,
|
|
|
|
+ };
|
|
|
|
|
|
|
|
+ InspectionReportDetails.Add(detail);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -133,7 +321,19 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
private void RemoveInspectionReportDetail()
|
|
private void RemoveInspectionReportDetail()
|
|
{
|
|
{
|
|
|
|
+ if (_selectedInspectionReportDetail == null)
|
|
|
|
+ {
|
|
|
|
+ MessageEx.ShowWarningDialog("请选中一行,再执行删除操作!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ InspectionReportDetails.Remove(_selectedInspectionReportDetail);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [RelayCommand]
|
|
|
|
+ private void SelectedInspectionReportDetailChanged(InspectionReportDetail detail)
|
|
|
|
+ {
|
|
|
|
+ _selectedInspectionReportDetail = detail;
|
|
}
|
|
}
|
|
|
|
|
|
private string GetPurchaseCompanyNames(InspectApply inspectApply)
|
|
private string GetPurchaseCompanyNames(InspectApply inspectApply)
|