ProductParamsViewModel.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 System.Windows;
  12. using TeamAAS_VP.Events;
  13. using TeamAAS_VP.Core;
  14. using TeamAAS_VP.Models;
  15. using TeamAAS_VP.Resources.Languages;
  16. namespace TeamAAS_VP.ViewModels.Product
  17. {
  18. public class ProductParamsViewModel : BindableBase
  19. {
  20. IRegionManager _regionManager;
  21. IEventAggregator _eventAggregator;
  22. IContainerProvider _container;
  23. IDialogService _dialogService;
  24. ProductsViewModel productsViewModel;
  25. #region 属性
  26. private ProductModel _SelectProduct;
  27. /// <summary>
  28. /// 选中的产品
  29. /// </summary>
  30. public ProductModel SelectProduct
  31. {
  32. get { return _SelectProduct; }
  33. set { SetProperty(ref _SelectProduct, value); }
  34. }
  35. private Management _management;
  36. public Management management
  37. {
  38. get { return _management; }
  39. set { SetProperty(ref _management, value); }
  40. }
  41. #endregion
  42. #region 命令
  43. private DelegateCommand _NextCommand;
  44. public DelegateCommand NextCommand =>
  45. _NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
  46. private DelegateCommand _BackCommand;
  47. public DelegateCommand BackCommand =>
  48. _BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
  49. private DelegateCommand _LoadedCommand;
  50. public DelegateCommand LoadedCommand =>
  51. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  52. #endregion
  53. #region 事件
  54. #endregion
  55. public ProductParamsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService)
  56. {
  57. _regionManager = regionManager;
  58. _eventAggregator = ea;
  59. _container = container;
  60. _dialogService = dialogService;
  61. //订阅权限登录事件
  62. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  63. productsViewModel = _container.Resolve<ProductsViewModel>();
  64. SelectProduct = productsViewModel.SelectProduct;
  65. management = _container.Resolve<Management>();
  66. }
  67. #region 方法
  68. /// <summary>
  69. /// 完成
  70. /// </summary>
  71. void ExecuteNextCommand()
  72. {
  73. if (MessageBox.Show(Lang.是否保存产品.Replace("[{0}]", ""), Lang.保存产品, MessageBoxButton.YesNo,MessageBoxImage.Question)==MessageBoxResult.Yes)
  74. {
  75. management.SaveProducts(SelectProduct);
  76. }
  77. _regionManager.RequestNavigate("ProductRegionContext", "ProductHome");
  78. }
  79. /// <summary>
  80. /// 上一步
  81. /// </summary>
  82. void ExecuteBackCommand()
  83. {
  84. _regionManager.RequestNavigate("ProductRegionContext", "RobotPointParams");
  85. }
  86. void ExecuteLoadedCommand()
  87. {
  88. if (_container.Resolve<Management>().CurrentUser.userPart == Enums.UserPart.Operator)
  89. {
  90. IsAllowEdit = false;
  91. }
  92. else
  93. {
  94. IsAllowEdit = true;
  95. }
  96. productsViewModel = _container.Resolve<ProductsViewModel>();
  97. SelectProduct = productsViewModel.SelectProduct;
  98. management = _container.Resolve<Management>();
  99. }
  100. #endregion
  101. private bool _IsAllowEdit = false;
  102. public bool IsAllowEdit
  103. {
  104. get { return _IsAllowEdit; }
  105. set { SetProperty(ref _IsAllowEdit, value); }
  106. }
  107. private void LoginChange(Models.User user)
  108. {
  109. if (user.userPart == Enums.UserPart.Operator)
  110. {
  111. IsAllowEdit = false;
  112. }
  113. else
  114. {
  115. IsAllowEdit = true;
  116. }
  117. }
  118. }
  119. }