终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

331 lignes
12 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.Pages.View;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.Model;
  5. using Microsoft.Toolkit.Mvvm.ComponentModel;
  6. using Microsoft.Toolkit.Mvvm.Input;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. namespace BPASmartClient.CustomResource.Pages.ViewModel
  15. {
  16. public class UserConfigViewModel:ObservableObject
  17. {
  18. /// <summary>
  19. /// 页面列表集合
  20. /// </summary>
  21. public ObservableCollection<UserTreeViewModel> pageTreeViewModels { get; set; } = new ObservableCollection<UserTreeViewModel>();
  22. /// <summary>
  23. /// 已选择页面
  24. /// </summary>
  25. public ObservableCollection<UserTreeViewModel> SelectePage { get; set; } = new ObservableCollection<UserTreeViewModel>();
  26. /// <summary>
  27. /// 本地原料集合
  28. /// </summary>
  29. public ObservableCollection<RawMaterialModel> LoaclMaterails { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;
  30. /// <summary>
  31. /// 设备原料集合
  32. /// </summary>
  33. public ObservableCollection<RawMaterialModel> DeviceMaterails { get; set; } = Global.DeviceRawMaterials;
  34. /// <summary>
  35. /// 用户本地原料权限
  36. /// </summary>
  37. public ObservableCollection<RawMaterialModel> UserLoaclMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
  38. /// <summary>
  39. /// 用户设备原料权限
  40. /// </summary>
  41. public ObservableCollection<RawMaterialModel> UserDeviceMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
  42. /// <summary>
  43. /// 切换本地和设备原料权限
  44. /// </summary>
  45. public bool IsChecked { get { return _isChecked; } set { _isChecked = value;OnPropertyChanged(); } }
  46. private bool _isChecked = true;
  47. /// <summary>
  48. /// 用户名
  49. /// </summary>
  50. public string UserName { get { return _username; } set { _username = value; OnPropertyChanged(); } }
  51. private string _username;
  52. /// <summary>
  53. /// 本地原料权限显示
  54. /// </summary>
  55. public Visibility VisibilityLocal { get { return _visibilityLocal; } set { _visibilityLocal = value; OnPropertyChanged(); } }
  56. private Visibility _visibilityLocal = Visibility.Visible;
  57. /// <summary>
  58. /// 设备原料权限显示
  59. /// </summary>
  60. public Visibility VisibilityDevice { get { return _visibilityDevice; } set { _visibilityDevice = value; OnPropertyChanged(); } }
  61. private Visibility _visibilityDevice = Visibility.Collapsed;
  62. public RelayCommand<object> AddUserPageCommand { get; set; }
  63. public RelayCommand<object> DeleteUserPageCommand { get; set; }
  64. public RelayCommand<object> DeleteAllCommand { get; set; }
  65. public RelayCommand<object> AddAllCommand { get; set; }
  66. public RelayCommand<object> ChangeMaterailPageCommand { get; set; }
  67. public RelayCommand SaveCommand { get; set; }
  68. public RelayCommand CancelCommand { get; set; }
  69. public RelayCommand<object> AddLoaclMaterialCommand { get; set; }
  70. public RelayCommand<object> DeleteLoaclMaterialCommand { get; set; }
  71. public RelayCommand<object> AddDeviceMaterialCommand { get; set; }
  72. public RelayCommand<object> DeleteDeviceMaterialCommand { get; set; }
  73. private void AddUserPage(object o)
  74. {
  75. if (o == null) return;
  76. if(o is string name)
  77. {
  78. var s = SelectePage.FirstOrDefault(x => x.Name == name);
  79. if (!SelectePage.Contains(s))
  80. {
  81. foreach (UserTreeViewModel item in pageTreeViewModels)
  82. {
  83. var res = item.TreeViewItems.FirstOrDefault(P => P.Name == name);
  84. if(res != null)
  85. {
  86. SelectePage.Add(res);
  87. return;
  88. }
  89. }
  90. }
  91. }
  92. }
  93. private void DeleteUserPage(object o)
  94. {
  95. if (o == null) return;
  96. if (o is string name)
  97. {
  98. var res = SelectePage.FirstOrDefault(p=>p.Name == name);
  99. SelectePage.Remove(res);
  100. }
  101. }
  102. private void ChangeMaterailPage(object o)
  103. {
  104. if (o == null) return;
  105. if (o is string type)
  106. {
  107. if(type == "Local") {IsChecked = true;VisibilityLocal = Visibility.Visible; VisibilityDevice = Visibility.Collapsed; }
  108. else {IsChecked = false; VisibilityDevice = Visibility.Visible;VisibilityLocal = Visibility.Collapsed; }
  109. }
  110. }
  111. private void AddLoaclMaterial(object o)
  112. {
  113. if (o == null) return;
  114. if (o is string materail)
  115. {
  116. var res = LoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail);
  117. if(UserLoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail)==null) UserLoaclMaterails.Add(res);
  118. }
  119. }
  120. private void DeleteLoaclMaterial(object o)
  121. {
  122. if (o == null) return;
  123. if (o is string materail)
  124. {
  125. var res = UserLoaclMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
  126. UserLoaclMaterails.Remove(res);
  127. }
  128. }
  129. private void AddDeviceMaterial(object o)
  130. {
  131. if (o == null) return;
  132. if (o is string materail)
  133. {
  134. var res = DeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
  135. if(UserDeviceMaterails.FirstOrDefault(p=>p.DeviceIp == res.DeviceIp) == null)
  136. {
  137. UserDeviceMaterails.Add(res);
  138. }
  139. }
  140. }
  141. private void DeleteDeviceMaterial(object o)
  142. {
  143. if (o == null) return;
  144. if (o is string materail)
  145. {
  146. var res = UserDeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
  147. UserDeviceMaterails.Remove(res);
  148. }
  149. }
  150. private void AddAll(object o)
  151. {
  152. if (o == null) return;
  153. if (o.ToString() == "page")
  154. {
  155. SelectePage.Clear();
  156. foreach (UserTreeViewModel item in pageTreeViewModels)
  157. {
  158. foreach (var res in item.TreeViewItems)
  159. {
  160. SelectePage.Add(res);
  161. }
  162. }
  163. }
  164. else if (o.ToString() == "local")
  165. {
  166. UserLoaclMaterails.Clear();
  167. foreach (RawMaterialModel item in LoaclMaterails)
  168. {
  169. UserLoaclMaterails.Add(item);
  170. }
  171. }
  172. else if (o.ToString() == "device")
  173. {
  174. UserDeviceMaterails.Clear();
  175. foreach (RawMaterialModel item in DeviceMaterails)
  176. {
  177. UserDeviceMaterails.Add(item);
  178. }
  179. }
  180. }
  181. private void DeleteAll(object o)
  182. {
  183. if (o == null) return;
  184. if(o.ToString() == "page")
  185. {
  186. SelectePage.Clear();
  187. }
  188. else if(o.ToString() == "local")
  189. {
  190. UserLoaclMaterails.Clear();
  191. }
  192. else if(o.ToString() == "device")
  193. {
  194. UserDeviceMaterails.Clear();
  195. }
  196. }
  197. public UserConfigViewModel()
  198. {
  199. AddUserPageCommand = new RelayCommand<object>(AddUserPage);
  200. DeleteUserPageCommand = new RelayCommand<object>(DeleteUserPage);
  201. DeleteAllCommand = new RelayCommand<object>(DeleteAll);
  202. AddAllCommand = new RelayCommand<object>(AddAll);
  203. ChangeMaterailPageCommand = new RelayCommand<object>(ChangeMaterailPage);
  204. SaveCommand = new RelayCommand(() =>
  205. {
  206. var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == Global.changeUserInfo.UserName && p.Password == Global.changeUserInfo.Password);
  207. if(res != null)
  208. {
  209. res.userTreeViewModels = new List<UserTreeViewModel>();
  210. res.userTreeViewModels.AddRange(SelectePage);
  211. res.locaRawMaterials = new List<RawMaterialModel>();
  212. res.locaRawMaterials.AddRange(UserLoaclMaterails);
  213. res.devRawMaterials = new List<RawMaterialModel>();
  214. res.devRawMaterials.AddRange(UserDeviceMaterails);
  215. Config.GetInstance.SaveUser();
  216. }
  217. Global.changeUserInfo = null;
  218. ActionManage.GetInstance.Send("UserConfigViewConfirm");
  219. });
  220. CancelCommand = new RelayCommand(() =>
  221. {
  222. Global.changeUserInfo = null;
  223. ActionManage.GetInstance.Send("UserConfigViewCancel");
  224. });
  225. AddLoaclMaterialCommand = new RelayCommand<object>(AddLoaclMaterial);
  226. DeleteLoaclMaterialCommand = new RelayCommand<object>(DeleteLoaclMaterial);
  227. AddDeviceMaterialCommand = new RelayCommand<object>(AddDeviceMaterial);
  228. DeleteDeviceMaterialCommand = new RelayCommand<object>(DeleteDeviceMaterial);
  229. foreach (var item in MenuManage.GetInstance.menuModels)
  230. {
  231. List<UserTreeViewModel> list = new List<UserTreeViewModel>();
  232. foreach(var res in item.subMenumodels)
  233. {
  234. list.Add(new UserTreeViewModel { Name = res.SubMenuName});
  235. }
  236. pageTreeViewModels.Add(new UserTreeViewModel
  237. {
  238. Name = item.MainMenuName,
  239. TreeViewItems = list
  240. });
  241. }
  242. //用户已拥有权限
  243. if(Global.changeUserInfo != null)
  244. {
  245. UserName = Global.changeUserInfo.UserName;
  246. if (Global.changeUserInfo.userTreeViewModels != null)
  247. {
  248. if(Global.changeUserInfo.userTreeViewModels.Count > 0)
  249. {
  250. foreach(UserTreeViewModel item in Global.changeUserInfo.userTreeViewModels)
  251. {
  252. SelectePage.Add(item);
  253. }
  254. }
  255. if(Global.changeUserInfo.locaRawMaterials.Count>0)
  256. {
  257. foreach(RawMaterialModel model in Global.changeUserInfo.locaRawMaterials)
  258. {
  259. UserLoaclMaterails.Add(model);
  260. }
  261. }
  262. if (Global.changeUserInfo.devRawMaterials.Count > 0)
  263. {
  264. foreach (RawMaterialModel model in Global.changeUserInfo.devRawMaterials)
  265. {
  266. UserDeviceMaterails.Add(model);
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }