终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

196 lines
7.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Security.Cryptography.Xml;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Media;
  11. using BPASmartClient.CustomResource.Pages.Model;
  12. using BPA.Helper;
  13. using BPASmartClient.Model;
  14. using BPA.Helper;
  15. namespace BPASmartClient.CustomResource.Pages.ViewModel
  16. {
  17. public class MainViewModel : NotifyBase
  18. {
  19. public MainViewModel()
  20. {
  21. NavChangedCommand = new BPARelayCommand<object>(DoNavChanged);
  22. MessageLog.GetInstance.InfoNotify = new Action<string>((o) =>
  23. {
  24. Application.Current?.Dispatcher?.Invoke(() =>
  25. {
  26. //ff20aefe
  27. var temp = new MessageModel()
  28. {
  29. LogInfo = o,
  30. Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
  31. };
  32. if (DebugLogViewModel.MessageModels.Count > 0)
  33. DebugLogViewModel.MessageModels.Insert(0, temp);
  34. else
  35. DebugLogViewModel.MessageModels.Add(temp);
  36. });
  37. });
  38. MessageLog.GetInstance.ExInfoNotify = new Action<string>((o) =>
  39. {
  40. Application.Current?.Dispatcher?.Invoke(() =>
  41. {
  42. //FFF53F62
  43. var temp = new MessageModel()
  44. {
  45. LogInfo = o,
  46. Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
  47. };
  48. if (DebugLogViewModel.MessageModels.Count > 0)
  49. DebugLogViewModel.MessageModels.Insert(0, temp);
  50. else
  51. DebugLogViewModel.MessageModels.Add(temp);
  52. });
  53. });
  54. BPA.Helper.MessageLog.GetInstance.NotifyShow = new Action<string>((o) =>
  55. {
  56. try
  57. {
  58. Application.Current?.Dispatcher?.Invoke(() =>
  59. {
  60. //ff20aefe
  61. var temp = new MessageModel()
  62. {
  63. LogInfo = o,
  64. Forground = new SolidColorBrush(Color.FromArgb(255, 32, 174, 254))
  65. };
  66. if (DebugLogViewModel.MessageModels.Count > 0)
  67. DebugLogViewModel.MessageModels.Insert(0, temp);
  68. else
  69. DebugLogViewModel.MessageModels.Add(temp);
  70. });
  71. }
  72. catch (Exception)
  73. {
  74. //throw;
  75. }
  76. });
  77. BPA.Helper.MessageLog.GetInstance.NotifyShowEx = new Action<string>((o) =>
  78. {
  79. Application.Current?.Dispatcher?.Invoke(() =>
  80. {
  81. //FFF53F62
  82. var temp = new MessageModel()
  83. {
  84. LogInfo = o,
  85. Forground = new SolidColorBrush(Color.FromArgb(255, 245, 63, 98))
  86. };
  87. if (DebugLogViewModel.MessageModels.Count > 0)
  88. DebugLogViewModel.MessageModels.Insert(0, temp);
  89. else
  90. DebugLogViewModel.MessageModels.Add(temp);
  91. });
  92. });
  93. menuModels = MenuManage.GetInstance.menuModels;
  94. PermissionChange();
  95. ActionManage.GetInstance.Register(new Action(() =>
  96. {
  97. PermissionChange();
  98. }), "PermissionChange");
  99. ActionManage.GetInstance.Register(new Action<object>((c) =>
  100. {
  101. if (c != null)
  102. IsAlarm = Convert.ToBoolean(c);
  103. }), "HeartBeatCheck");
  104. }
  105. private void PermissionChange()
  106. {
  107. int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
  108. if (MainIndex >= 0 && MainIndex < menuModels.Count)
  109. {
  110. int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
  111. if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
  112. {
  113. //DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
  114. DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex));
  115. }
  116. }
  117. }
  118. public ObservableCollection<MenuModel> menuModels { get; set; }
  119. private void DoNavChanged(object obj)
  120. {
  121. if (obj != null && obj is SubMenumodel menumodel)
  122. {
  123. DisplayName = menumodel.SubMenuName;
  124. var end = menumodel.AssemblyName.Substring(menumodel.AssemblyName.Length - 1);
  125. var start = menumodel.ToggleWindowPath.Substring(0, 1);
  126. bool isAddPoint = end != "." && start != ".";
  127. string point = isAddPoint ? "." : "";
  128. Type type = Assembly.Load(menumodel.AssemblyName)?.GetType($"{menumodel.AssemblyName}{point}{menumodel.ToggleWindowPath}");
  129. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  130. if (type?.BaseType.Name == "Window") ((Window)cti?.Invoke(null)).ShowDialog();
  131. else if (type?.BaseType.Name == "UserControl")
  132. {
  133. MainContent = null;
  134. MainContent = (FrameworkElement)cti?.Invoke(null);
  135. MainContent?.GetType()?.GetProperty("Name").SetValue(MainContent, menumodel.SubMenuName);
  136. }
  137. }
  138. }
  139. private bool _status;
  140. /// <summary>
  141. /// 设备初始化状态
  142. /// </summary>
  143. public bool Status
  144. {
  145. get { return _status; }
  146. set
  147. {
  148. if (value)
  149. {
  150. ActionManage.GetInstance.Send("StartPlcInite");
  151. }
  152. else
  153. {
  154. ActionManage.GetInstance.Send("EndPlcInite");
  155. }
  156. _status = value;
  157. OnPropertyChanged();
  158. }
  159. }
  160. private bool _isAlarm = true;
  161. /// <summary>
  162. /// 心跳检测报警
  163. /// </summary>
  164. public bool IsAlarm
  165. {
  166. get { return _isAlarm; }
  167. set { _isAlarm = value; OnPropertyChanged(); }
  168. }
  169. /// <summary>
  170. /// 开机自启
  171. /// </summary>
  172. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  173. public BPARelayCommand<object> NavChangedCommand { get; set; }
  174. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  175. private FrameworkElement _mMainContent;
  176. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  177. private string _mDisplayName;
  178. }
  179. }