ProductDescriptionViewModel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.Collections.ObjectModel;
  10. using System.Linq;
  11. using TeamAAS_VP.Core;
  12. using TeamAAS_VP.Events;
  13. using TeamAAS_VP.Interfaces;
  14. using TeamAAS_VP.Models;
  15. namespace TeamAAS_VP.ViewModels.Product
  16. {
  17. public class ProductDescriptionViewModel : BindableBase, IConfirmNavigationRequest
  18. {
  19. IRegionManager _regionManager;
  20. IEventAggregator _eventAggregator;
  21. IContainerProvider _container;
  22. IDialogService _dialogService;
  23. ISystemDatabaseService _systemDatabaseService;
  24. #region 属性
  25. private ProductModel _SelectProduct;
  26. /// <summary>
  27. /// 选中的产品
  28. /// </summary>
  29. public ProductModel SelectProduct
  30. {
  31. get { return _SelectProduct; }
  32. set { SetProperty(ref _SelectProduct, value); }
  33. }
  34. #endregion
  35. #region 命令
  36. private DelegateCommand _NextCommand;
  37. public DelegateCommand NextCommand =>
  38. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  39. private DelegateCommand _BackCommand;
  40. public DelegateCommand BackCommand =>
  41. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  42. private DelegateCommand _LoadedCommand;
  43. public DelegateCommand LoadedCommand =>
  44. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  45. #endregion
  46. #region 事件
  47. #endregion
  48. public ProductDescriptionViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService, ISystemDatabaseService systemDatabaseService)
  49. {
  50. _regionManager = regionManager;
  51. _eventAggregator = ea;
  52. _container = container;
  53. _dialogService = dialogService;
  54. _systemDatabaseService = systemDatabaseService;
  55. //订阅权限登录事件
  56. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  57. }
  58. #region 方法
  59. /// <summary>
  60. /// 下一步
  61. /// </summary>
  62. void ExecuteNextCommand()
  63. {
  64. NavigationParameters param = new NavigationParameters();
  65. param.Add("SelectProduct", SelectProduct);
  66. _regionManager.RequestNavigate("ProductRegionContext", "ProductProcessManage", param);
  67. }
  68. void ExecuteBackCommand()
  69. {
  70. NavigationParameters param = new NavigationParameters();
  71. param.Add("SelectProduct", SelectProduct);
  72. _regionManager.RequestNavigate("ProductRegionContext", "ProductHome", param);
  73. }
  74. void ExecuteLoadedCommand()
  75. {
  76. if (_systemDatabaseService.GetCurrentUser().userPart == Enums.UserPart.Operator)
  77. {
  78. IsAllowEdit = false;
  79. }
  80. else
  81. {
  82. IsAllowEdit = true;
  83. }
  84. }
  85. #endregion
  86. #region 继承
  87. /// <summary>
  88. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  89. /// </summary>
  90. /// <param name="navigationContext"></param>
  91. /// <param name="continuationCallback"></param>
  92. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  93. {
  94. continuationCallback(true);
  95. }
  96. /// <summary>
  97. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  98. /// </summary>
  99. /// <param name="navigationContext"></param>
  100. /// <exception cref="NotImplementedException"></exception>
  101. public async void OnNavigatedTo(NavigationContext navigationContext)
  102. {
  103. SelectProduct = navigationContext.Parameters.GetValue<ProductModel>("SelectProduct");
  104. }
  105. /// <summary>
  106. /// 是否允许导航到此视图模型。
  107. /// </summary>
  108. /// <param name="navigationContext"></param>
  109. /// <returns></returns>
  110. public bool IsNavigationTarget(NavigationContext navigationContext)
  111. {
  112. return true;
  113. }
  114. /// <summary>
  115. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  116. /// </summary>
  117. /// <param name="navigationContext"></param>
  118. public void OnNavigatedFrom(NavigationContext navigationContext)
  119. {
  120. }
  121. #endregion
  122. private bool _IsAllowEdit = false;
  123. public bool IsAllowEdit
  124. {
  125. get { return _IsAllowEdit; }
  126. set { SetProperty(ref _IsAllowEdit, value); }
  127. }
  128. private void LoginChange(Models.User user)
  129. {
  130. if (user.userPart == Enums.UserPart.Operator)
  131. {
  132. IsAllowEdit = false;
  133. }
  134. else
  135. {
  136. IsAllowEdit = true;
  137. }
  138. }
  139. }
  140. }