终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

331 rader
12 KiB

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