ProductParamsViewModel.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using MaterialDesignThemes.Wpf;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Ioc;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using Prism.Services.Dialogs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using Team.FFFeederService.Interfaces;
  15. using TeamAAS_VP.Controls;
  16. using TeamAAS_VP.Core;
  17. using TeamAAS_VP.Events;
  18. using TeamAAS_VP.Interfaces;
  19. using TeamAAS_VP.Models;
  20. using TeamAAS_VP.Resources.Languages;
  21. using TeamAAS_VP.Services;
  22. namespace TeamAAS_VP.ViewModels.Product
  23. {
  24. public class ProductParamsViewModel : BindableBase, IConfirmNavigationRequest
  25. {
  26. IRegionManager _regionManager;
  27. IEventAggregator _eventAggregator;
  28. IContainerProvider _container;
  29. IDialogService _dialogService;
  30. IConfigService _configService;
  31. IRobotService _robotService;
  32. ICameraService _cameraService;
  33. IFeederService _feederService;
  34. IPlcService _plcService;
  35. IProductService _productService;
  36. ISystemDatabaseService _systemDatabaseService;
  37. #region 属性
  38. private ProductModel _SelectProduct;
  39. /// <summary>
  40. /// 选中的产品
  41. /// </summary>
  42. public ProductModel SelectProduct
  43. {
  44. get { return _SelectProduct; }
  45. set { SetProperty(ref _SelectProduct, value); }
  46. }
  47. private Management _management;
  48. public Management management
  49. {
  50. get { return _management; }
  51. set { SetProperty(ref _management, value); }
  52. }
  53. #endregion
  54. #region 命令
  55. private DelegateCommand _NextCommand;
  56. public DelegateCommand NextCommand =>
  57. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  58. private DelegateCommand _BackCommand;
  59. public DelegateCommand BackCommand =>
  60. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  61. private DelegateCommand _LoadedCommand;
  62. public DelegateCommand LoadedCommand =>
  63. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  64. #endregion
  65. #region 事件
  66. #endregion
  67. public ProductParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  68. IConfigService configService, IRobotService robotService, ICameraService cameraService, IFeederService feederService, IPlcService plcService, IProductService productService,
  69. ISystemDatabaseService systemDatabaseService)
  70. {
  71. _regionManager = regionManager;
  72. _eventAggregator = ea;
  73. _container = container;
  74. _dialogService = dialogService;
  75. _configService = configService;
  76. _robotService = robotService;
  77. _cameraService = cameraService;
  78. _feederService = feederService;
  79. _plcService = plcService;
  80. _productService = productService;
  81. _systemDatabaseService = systemDatabaseService;
  82. //订阅权限登录事件
  83. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  84. management = _container.Resolve<Management>();
  85. }
  86. #region 方法
  87. /// <summary>
  88. /// 完成
  89. /// </summary>
  90. async void ExecuteNextCommand()
  91. {
  92. if (MessageBox.Show(Lang.是否保存产品.Replace("[{0}]", ""), Lang.保存产品, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  93. {
  94. var waiting = new WaitingControl();
  95. //show the dialog
  96. var task = DialogHost.Show(waiting, "RootDialog", null, null, null);
  97. await _productService.UpdateProductAsync(SelectProduct);
  98. if (DialogHost.IsDialogOpen("RootDialog"))
  99. {
  100. DialogHost.Close("RootDialog");
  101. }
  102. await task;
  103. }
  104. NavigationParameters param = new NavigationParameters();
  105. param.Add("SelectProduct", SelectProduct);
  106. _regionManager.RequestNavigate("ProductRegionContext", "ProductHome", param);
  107. }
  108. /// <summary>
  109. /// 上一步
  110. /// </summary>
  111. void ExecuteBackCommand()
  112. {
  113. NavigationParameters param = new NavigationParameters();
  114. param.Add("SelectProduct", SelectProduct);
  115. _regionManager.RequestNavigate("ProductRegionContext", "RobotPointParams", param);
  116. }
  117. void ExecuteLoadedCommand()
  118. {
  119. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  120. {
  121. IsAllowEdit = false;
  122. }
  123. else
  124. {
  125. IsAllowEdit = true;
  126. }
  127. }
  128. #endregion
  129. #region 继承
  130. /// <summary>
  131. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  132. /// </summary>
  133. /// <param name="navigationContext"></param>
  134. /// <param name="continuationCallback"></param>
  135. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  136. {
  137. continuationCallback(true);
  138. }
  139. /// <summary>
  140. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  141. /// </summary>
  142. /// <param name="navigationContext"></param>
  143. /// <exception cref="NotImplementedException"></exception>
  144. public async void OnNavigatedTo(NavigationContext navigationContext)
  145. {
  146. try
  147. {
  148. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  149. }
  150. catch (Exception ex)
  151. {
  152. LogHelper.WriteLogError("机器人点位界面进入时出错!", ex);
  153. }
  154. }
  155. /// <summary>
  156. /// 是否允许导航到此视图模型。
  157. /// </summary>
  158. /// <param name="navigationContext"></param>
  159. /// <returns></returns>
  160. public bool IsNavigationTarget(NavigationContext navigationContext)
  161. {
  162. return true;
  163. }
  164. /// <summary>
  165. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  166. /// </summary>
  167. /// <param name="navigationContext"></param>
  168. public void OnNavigatedFrom(NavigationContext navigationContext)
  169. {
  170. }
  171. #endregion
  172. private bool _IsAllowEdit = false;
  173. public bool IsAllowEdit
  174. {
  175. get { return _IsAllowEdit; }
  176. set { SetProperty(ref _IsAllowEdit, value); }
  177. }
  178. private void LoginChange(Models.User user)
  179. {
  180. if (user.userPart == Enums.UserPart.Operator)
  181. {
  182. IsAllowEdit = false;
  183. }
  184. else
  185. {
  186. IsAllowEdit = true;
  187. }
  188. }
  189. }
  190. }