CalibrationResultViewModel.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using Prism.Commands;
  2. using Prism.Events;
  3. using Prism.Ioc;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Windows;
  11. using TeamAAS_VP.Core;
  12. using TeamAAS_VP.Models;
  13. using TeamAAS_VP;
  14. namespace TeamAAS_VP.ViewModels.Calibration
  15. {
  16. public class CalibrationResultViewModel : BindableBase
  17. {
  18. IRegionManager _regionManager;
  19. IRegionNavigationService _regionNavigationService;
  20. IContainerProvider _container;
  21. IDialogService _dialogService;
  22. IEventAggregator _eventAggregator;
  23. #region 属性
  24. private CalibrationInfo _SelectCalibration;
  25. public CalibrationInfo SelectCalibration
  26. {
  27. get { return _SelectCalibration; }
  28. set { SetProperty(ref _SelectCalibration, value); }
  29. }
  30. private CalibrationResult _Result;
  31. public CalibrationResult Result
  32. {
  33. get { return _Result; }
  34. set { SetProperty(ref _Result, value); }
  35. }
  36. private CalibrationTestResult _TestResult;
  37. public CalibrationTestResult TestResult
  38. {
  39. get { return _TestResult; }
  40. set { SetProperty(ref _TestResult, value); }
  41. }
  42. #endregion
  43. #region 命令
  44. private DelegateCommand _LoadedCommand;
  45. public DelegateCommand LoadedCommand =>
  46. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  47. private DelegateCommand _NextCommand;
  48. public DelegateCommand NextCommand =>
  49. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  50. private DelegateCommand _BackCommand;
  51. public DelegateCommand BackCommand =>
  52. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  53. #endregion
  54. #region 事件
  55. #endregion
  56. public CalibrationResultViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService)
  57. {
  58. _regionManager = regionManager;
  59. _regionNavigationService = regionNavigationService;
  60. _container = container;
  61. _dialogService = dialogService;
  62. _eventAggregator = ea;
  63. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  64. _container.Resolve<CalibrationHomeViewModel>().PropertyChanged += CalibrationEditVisionViewModel_PropertyChanged;
  65. }
  66. #region 方法
  67. void ExecuteLoadedCommand()
  68. {
  69. if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
  70. {
  71. IsAllowEdit = false;
  72. }
  73. else
  74. {
  75. IsAllowEdit = true;
  76. }
  77. try
  78. {
  79. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  80. Result = SelectCalibration.CalibrationResult;
  81. TestResult = SelectCalibration.CalibrationTestResult;
  82. }
  83. catch (Exception ex)
  84. {
  85. LogHelper.WriteLogError("相机校准-校准结果界面加载时出错!", ex);
  86. MessageBox.Show(ex.Message);
  87. }
  88. }
  89. /// <summary>
  90. /// 下一步
  91. /// </summary>
  92. void ExecuteNextCommand()
  93. {
  94. _container.Resolve<Management>().SaveCalibration(SelectCalibration);
  95. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationHome");
  96. }
  97. /// <summary>
  98. /// 上一步
  99. /// </summary>
  100. void ExecuteBackCommand()
  101. {
  102. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationVerification");
  103. }
  104. private void CalibrationEditVisionViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  105. {
  106. //if (e.PropertyName == "SelectCalibration")
  107. //{
  108. // SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  109. //}
  110. }
  111. #endregion
  112. private bool _IsAllowEdit = false;
  113. public bool IsAllowEdit
  114. {
  115. get { return _IsAllowEdit; }
  116. set { SetProperty(ref _IsAllowEdit, value); }
  117. }
  118. private void LoginChange(Models.User user)
  119. {
  120. if (user.userPart == Enums.UserPart.Operator)
  121. {
  122. IsAllowEdit = false;
  123. }
  124. else
  125. {
  126. IsAllowEdit = true;
  127. }
  128. }
  129. }
  130. }