CalibrationResultViewModel.cs 6.8 KB

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