CalibrationResultViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Interfaces;
  14. using TeamAAS_VP.Models;
  15. using TeamAAS_VP.Models.Calibration;
  16. using TeamAAS_VP.Resources.Languages;
  17. using TeamAAS_VP.Services;
  18. namespace TeamAAS_VP.ViewModels.Calibration
  19. {
  20. public class CalibrationResultViewModel : BindableBase, IConfirmNavigationRequest
  21. {
  22. IRegionManager _regionManager;
  23. IRegionNavigationService _regionNavigationService;
  24. IContainerProvider _container;
  25. IDialogService _dialogService;
  26. IEventAggregator _eventAggregator;
  27. IConfigService _configService;
  28. ICalibrationService _calibrationService;
  29. ISystemDatabaseService _systemDatabaseService;
  30. #region 属性
  31. private CalibrationInfo _SelectCalibration;
  32. public CalibrationInfo SelectCalibration
  33. {
  34. get { return _SelectCalibration; }
  35. set { SetProperty(ref _SelectCalibration, value); }
  36. }
  37. private CalibrationResult _Result;
  38. public CalibrationResult Result
  39. {
  40. get { return _Result; }
  41. set { SetProperty(ref _Result, value); }
  42. }
  43. private CalibrationTestResult _TestResult;
  44. public CalibrationTestResult TestResult
  45. {
  46. get { return _TestResult; }
  47. set { SetProperty(ref _TestResult, value); }
  48. }
  49. #endregion
  50. #region 命令
  51. private DelegateCommand _LoadedCommand;
  52. public DelegateCommand LoadedCommand =>
  53. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  54. private DelegateCommand _NextCommand;
  55. public DelegateCommand NextCommand =>
  56. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  57. private DelegateCommand _BackCommand;
  58. public DelegateCommand BackCommand =>
  59. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  60. #endregion
  61. #region 事件
  62. #endregion
  63. public CalibrationResultViewModel(IRegionManager regionManager, IEventAggregator ea, IRegionNavigationService regionNavigationService, IContainerProvider container, IDialogService dialogService,
  64. IConfigService configService, ICalibrationService calibrationService, ISystemDatabaseService systemDatabaseService)
  65. {
  66. _regionManager = regionManager;
  67. _regionNavigationService = regionNavigationService;
  68. _container = container;
  69. _dialogService = dialogService;
  70. _eventAggregator = ea;
  71. _configService = configService;
  72. _calibrationService = calibrationService;
  73. _systemDatabaseService = systemDatabaseService;
  74. }
  75. #region 方法
  76. void ExecuteLoadedCommand()
  77. {
  78. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  79. {
  80. IsAllowEdit = false;
  81. }
  82. else
  83. {
  84. IsAllowEdit = true;
  85. }
  86. }
  87. /// <summary>
  88. /// 下一步
  89. /// </summary>
  90. void ExecuteNextCommand()
  91. {
  92. NavigationParameters param = new NavigationParameters();
  93. param.Add("SelectCalibration", SelectCalibration);
  94. _calibrationService.AddOrUpdateCalibration(SelectCalibration);
  95. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationHome", param);
  96. }
  97. /// <summary>
  98. /// 上一步
  99. /// </summary>
  100. void ExecuteBackCommand()
  101. {
  102. NavigationParameters param = new NavigationParameters();
  103. param.Add("SelectCalibration", SelectCalibration);
  104. _regionManager.RequestNavigate("CalibrationRegionContext", "CalibrationVerification", param);
  105. }
  106. private void CalibrationEditVisionViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  107. {
  108. //if (e.PropertyName == "SelectCalibration")
  109. //{
  110. // SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  111. //}
  112. }
  113. #endregion
  114. #region 继承
  115. /// <summary>
  116. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  117. /// </summary>
  118. /// <param name="navigationContext"></param>
  119. /// <param name="continuationCallback"></param>
  120. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  121. {
  122. continuationCallback(true);
  123. }
  124. /// <summary>
  125. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  126. /// </summary>
  127. /// <param name="navigationContext"></param>
  128. /// <exception cref="NotImplementedException"></exception>
  129. public async void OnNavigatedTo(NavigationContext navigationContext)
  130. {
  131. SelectCalibration = navigationContext.Parameters.GetValue<CalibrationInfo>("SelectCalibration");
  132. try
  133. {
  134. SelectCalibration = _container.Resolve<CalibrationHomeViewModel>().SelectCalibration;
  135. Result = SelectCalibration.CalibrationResult;
  136. TestResult = SelectCalibration.CalibrationTestResult;
  137. }
  138. catch (Exception ex)
  139. {
  140. LogHelper.WriteLogError(Lang.相机校准校准结果界面加载时出错, ex);
  141. MessageBox.Show(ex.Message);
  142. }
  143. }
  144. /// <summary>
  145. /// 是否允许导航到此视图模型。
  146. /// </summary>
  147. /// <param name="navigationContext"></param>
  148. /// <returns></returns>
  149. public bool IsNavigationTarget(NavigationContext navigationContext)
  150. {
  151. return true;
  152. }
  153. /// <summary>
  154. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  155. /// </summary>
  156. /// <param name="navigationContext"></param>
  157. public void OnNavigatedFrom(NavigationContext navigationContext)
  158. {
  159. }
  160. #endregion
  161. private bool _IsAllowEdit = false;
  162. public bool IsAllowEdit
  163. {
  164. get { return _IsAllowEdit; }
  165. set { SetProperty(ref _IsAllowEdit, value); }
  166. }
  167. private void LoginChange(Models.User user)
  168. {
  169. if (user.userPart == Enums.UserPart.Operator)
  170. {
  171. IsAllowEdit = false;
  172. }
  173. else
  174. {
  175. IsAllowEdit = true;
  176. }
  177. }
  178. }
  179. }