|
@@ -58,19 +58,19 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
LoadData();
|
|
|
}
|
|
|
|
|
|
- partial void OnSelectedInspectionReportChanging(InspectionReportModel? oldValue, InspectionReportModel? newValue)
|
|
|
- {
|
|
|
- if (oldValue == null) return;
|
|
|
- bool isChanged = IsCurrentReportChanged(oldValue);
|
|
|
- if (isChanged)
|
|
|
- {
|
|
|
- if (!AskIsSave())
|
|
|
- {
|
|
|
- //取消变更新行
|
|
|
- SelectedInspectionReport = oldValue;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //partial void OnSelectedInspectionReportChanging(InspectionReportModel? oldValue, InspectionReportModel? newValue)
|
|
|
+ //{
|
|
|
+ // if (oldValue == null) return;
|
|
|
+ // bool isChanged = IsCurrentReportChanged(oldValue);
|
|
|
+ // if (isChanged)
|
|
|
+ // {
|
|
|
+ // if (!AskIsSave())
|
|
|
+ // {
|
|
|
+ // //取消变更新行
|
|
|
+ // SelectedInspectionReport = oldValue;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ //}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 加载数据
|
|
@@ -79,7 +79,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
private void LoadData()
|
|
|
{
|
|
|
//询问是否保存
|
|
|
- if(!AskIsSave()) return;
|
|
|
+ //if(!AskIsSave()) return;
|
|
|
|
|
|
var inspectionReports = _inspectionReportService.Query()
|
|
|
.Include(x => x.InspectionReportDetails)
|
|
@@ -254,10 +254,13 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
//删除
|
|
|
_inspectionReportService.Delete(x=>x.Guid == SelectedInspectionReport.Guid); //删除主表时会级联删除子表
|
|
|
- _inspectionReportService.SaveChanges();
|
|
|
+ var success = _inspectionReportService.SaveChanges();
|
|
|
|
|
|
- //重新加载数据
|
|
|
- LoadData();
|
|
|
+ if (success)
|
|
|
+ {
|
|
|
+ MessageBox.Show("删除成功!");
|
|
|
+ InspectionReports.Remove(SelectedInspectionReport);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -268,7 +271,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
{
|
|
|
if (SelectedInspectionReport == null) return;
|
|
|
|
|
|
- if (!AskIsSave()) return;
|
|
|
+ //if (!AskIsSave()) return;
|
|
|
|
|
|
InspectionReportUtil.ExportInspectionReportFile(SelectedInspectionReport);
|
|
|
}
|
|
@@ -412,56 +415,56 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
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);
|
|
|
+ ///// <summary>
|
|
|
+ ///// 询问是否保存更改
|
|
|
+ ///// </summary>
|
|
|
+ //private bool AskIsSave()
|
|
|
+ //{
|
|
|
+ // if (SelectedInspectionReport == null) return true;
|
|
|
+ // var isChanged = IsCurrentReportChanged(SelectedInspectionReport);
|
|
|
+ // if (!isChanged) return true;
|
|
|
|
|
|
- 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;
|
|
|
- }
|
|
|
+ // 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)
|
|
|
{
|