终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
2 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. 
  2. using BPASmartClient.Helper;
  3. using FryPot_DosingSystem.Control;
  4. using FryPot_DosingSystem.Model;
  5. using FryPot_DosingSystem.View;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Forms;
  17. namespace FryPot_DosingSystem.ViewModel
  18. {
  19. internal class MainViewModel : ObservableObject
  20. {
  21. public ObservableCollection<ActionMenu> menus { get; set; } = new ObservableCollection<ActionMenu>();
  22. public RelayCommand Login { get; set; }
  23. public RelayCommand PasswordChange { get; set; }
  24. public RelayCommand ExitLogin { get; set; }
  25. public RelayCommand<object> TogglePag { get; set; }
  26. public bool UserManagement { get { return _mUserManagement; } set { _mUserManagement = value; OnPropertyChanged(); } }
  27. private bool _mUserManagement;
  28. /// <summary>
  29. /// 当前登陆信息
  30. /// </summary>
  31. private UserInfo _currentLoginAccount;
  32. public UserInfo CurrentLoginAccount { get { return _currentLoginAccount; } set { _currentLoginAccount = value; OnPropertyChanged(); } }
  33. /// <summary>
  34. /// 不同权限显示不同菜单
  35. /// </summary>
  36. public ObservableCollection<ActionMenu> DisplayMenus { get; set; } = new ObservableCollection<ActionMenu>();
  37. public FrameworkElement MyWindow { get { return _mMyWindow; } set { _mMyWindow = value; OnPropertyChanged(); } }
  38. private FrameworkElement _mMyWindow;
  39. public string WindowTitleName { get { return _mWindowTitleName; } set { _mWindowTitleName = value; OnPropertyChanged(); } }
  40. private string _mWindowTitleName;
  41. /// <summary>
  42. /// 开机自启
  43. /// </summary>
  44. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  45. private bool _status;
  46. /// <summary>
  47. /// 设备初始化状态
  48. /// </summary>
  49. public bool Status
  50. {
  51. get { return _status; }
  52. set
  53. {
  54. if (value)
  55. {
  56. ActionManage.GetInstance.Send("StartPlcInite");
  57. }
  58. else
  59. {
  60. ActionManage.GetInstance.Send("EndPlcInite");
  61. }
  62. _status = value;
  63. OnPropertyChanged();
  64. }
  65. }
  66. private Authority authority;
  67. public Authority Authority
  68. {
  69. get { return authority; }
  70. set
  71. {
  72. var res = menus.Where(p => Array.FindIndex(p.Authority, au => au == value) >= 0).ToList();
  73. if (res != null && res.Count > 0)
  74. {
  75. DisplayMenus.Clear();
  76. res.ForEach(p => DisplayMenus.Add(p));
  77. DoNavChanged(res[0].CommandParameter);
  78. }
  79. authority = value;
  80. }
  81. }
  82. public MainViewModel()
  83. {
  84. LogViewModel model = LogViewModel.GetInstance;
  85. DeviceOperate deviceOperate = DeviceOperate.GetInstance;//开启实时PLC数据读取
  86. DosingLogicControl logigControl = DosingLogicControl.GetInstance;//开启逻辑控制任务程序
  87. TogglePag = new RelayCommand<object>(DoNavChanged);
  88. Login = new RelayCommand(() =>
  89. {
  90. ActionManage.GetInstance.CancelRegister("ContentUpdate");
  91. ActionManage.GetInstance.Register(new Func<object>(() => { return "注册"; }), "ContentUpdate");
  92. DoNavChanged("AdministratorLoginView.用户登陆");
  93. UserManagement = false;
  94. });
  95. PasswordChange = new RelayCommand(() =>
  96. {
  97. ActionManage.GetInstance.CancelRegister("ContentUpdate");
  98. ActionManage.GetInstance.Register(new Func<object>(() => { return "修改"; }), "ContentUpdate");
  99. ActionManage.GetInstance.CancelRegister("LoginInfo");
  100. ActionManage.GetInstance.Register(new Func<object>(() => { return CurrentLoginAccount; }), "LoginInfo");
  101. DoNavChanged("AdministratorLoginView.密码修改");
  102. UserManagement = false;
  103. });
  104. ExitLogin = new RelayCommand(() =>
  105. {
  106. //DoNavChanged("LoginView.退出登录");
  107. CurrentLoginAccount = null;
  108. Authority = Authority.观察员;
  109. UserManagement = false;
  110. });
  111. LoginInfoConfig.GetInstance.Init();//用户数据初始化
  112. LoginRegister();
  113. MenusDefaultInit();
  114. Authority = Authority.管理员;
  115. }
  116. private void MenusDefaultInit()
  117. {
  118. menus.Add(new ActionMenu() { MenuName = "配方设置", CommandParameter = "RecipeSetView.配方设置", Authority = new Authority[] { Authority.管理员, Authority.技术员 } });
  119. menus.Add(new ActionMenu() { MenuName = "配方下发", CommandParameter = "RecipeSendDownView.配方下发", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员 } });
  120. menus.Add(new ActionMenu() { MenuName = "设备列表", CommandParameter = "DeviceListVIew.设备列表", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
  121. menus.Add(new ActionMenu() { MenuName = "状态监测", CommandParameter = "HardWareStatusView.状态监测", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
  122. menus.Add(new ActionMenu() { MenuName = "日志信息", CommandParameter = "LogView.日志信息", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
  123. menus.Add(new ActionMenu() { MenuName = "报警记录", CommandParameter = "", Authority = new Authority[] { Authority.管理员, Authority.技术员, Authority.操作员, Authority.观察员 } });
  124. }
  125. public void DoNavChanged(object obj)
  126. {
  127. if (obj != null && obj is string stobj)
  128. {
  129. var strs = stobj.Split('.');
  130. if (strs != null && strs.Length == 2)
  131. {
  132. Type type = Type.GetType($"FryPot_DosingSystem.View.{strs[0]}");
  133. var res = type?.GetConstructor(System.Type.EmptyTypes)?.Invoke(null);
  134. if (res != null && res is FrameworkElement fe) MyWindow = fe;
  135. WindowTitleName = strs[1];
  136. }
  137. }
  138. }
  139. /// <summary>
  140. /// 登陆验证
  141. /// </summary>
  142. private void LoginRegister()
  143. {
  144. ActionManage.GetInstance.Register(new Func<object, object>((o) =>
  145. {
  146. if (o != null && o is string str)
  147. {
  148. var strs = str.Split("-=");
  149. if (strs != null && strs.Length == 3)
  150. {
  151. var us = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == strs[0] && p.Password == strs[1] && strs[2] == p.Authority.ToString());
  152. if (us != null)
  153. {
  154. Authority = us.Authority;
  155. CurrentLoginAccount = us;//记录当前登陆信息
  156. return string.Empty;
  157. }
  158. }
  159. }
  160. return "用户名或密码错误";
  161. }), "LoginDosingSystem");
  162. }
  163. }
  164. }