终端一体化运控平台
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

230 řádky
9.8 KiB

  1. using System.Configuration;
  2. using System.Data;
  3. using System.Windows;
  4. namespace BPASmartClient.Academy
  5. {
  6. /// <summary>
  7. /// Interaction logic for App.xaml
  8. /// </summary>
  9. public partial class App : Application
  10. {
  11. public static Window MainWindow;
  12. public EventWaitHandle ProgramStarted { get; set; }
  13. protected override async void OnStartup(StartupEventArgs e)
  14. {
  15. bool createNew;
  16. MessageLog.GetInstance.NotifyShow = new Action<string>(o =>
  17. {
  18. DebugLogViewModel.MessageModels.Add(new MessageModel()
  19. {
  20. LogInfo = o,
  21. Forground = System.Windows.Media.Brushes.DeepSkyBlue
  22. });
  23. });
  24. MessageLog.GetInstance.NotifyShowEx = new Action<string>(o =>
  25. {
  26. DebugLogViewModel.MessageModels.Add(new MessageModel()
  27. {
  28. LogInfo = o,
  29. Forground = System.Windows.Media.Brushes.Red
  30. });
  31. });
  32. ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "Academy", out createNew);
  33. if (!createNew)
  34. {
  35. MessageBox.Show("程序已启动");
  36. App.Current.Shutdown();
  37. Environment.Exit(0);
  38. }
  39. base.OnStartup(e);
  40. SystemHelper.GetInstance.CreateDesktopShortcut();
  41. DataInit();
  42. MenuInit();
  43. MainView mv = new MainView();
  44. mv.TitleName = $"反应釜焖制系统 V1.0.1";
  45. LoginView lv = new LoginView();
  46. var res = lv.ShowDialog();
  47. if (res != null && res == true)
  48. {
  49. #region 更新测试
  50. //string directory = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\UpdateModel.json";
  51. //if (File.Exists(directory))
  52. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] {Json<UpdateModel>.Data.UpgradeVersion}";
  53. //else
  54. //{
  55. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  56. // Task.Run(() =>
  57. // {
  58. // Thread.Sleep(3000);
  59. // var tt = MessageNotify.GetInstance.ShowDialog("检测到新版本,请问是否现在更新?", DialogType.Information);
  60. // if (tt)
  61. // {
  62. // string directory = AppDomain.CurrentDomain.BaseDirectory;
  63. // Process.Start($"{directory}BPASmartClient.Update.exe");
  64. // App.Current.Dispatcher.Invoke(() => { mv.Close(); });
  65. // }
  66. // });
  67. //}
  68. #endregion
  69. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog("用户登录");
  70. mv.Show();
  71. }
  72. else
  73. mv.Close();
  74. MainWindow = mv;
  75. }
  76. protected override void OnExit(ExitEventArgs e)
  77. {
  78. base.OnExit(e);
  79. Json<LocalRecipe>.Save();
  80. Json<DevicePar>.Save();
  81. Json<LocaMaterial>.Save();
  82. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
  83. TaskManage.GetInstance.Dispose();
  84. //Process.GetCurrentProcess().Kill();
  85. }
  86. private void MenuInit()
  87. {
  88. #region 配方管理菜单
  89. ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  90. RecipeManage.Add(new SubMenumodel()
  91. {
  92. SubMenuName = "配方管理",
  93. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  94. AssemblyName = "BPASmartClient.Academy",
  95. ToggleWindowPath = "View.RecipeSettingsView"
  96. });
  97. RecipeManage.Add(new SubMenumodel()
  98. {
  99. SubMenuName = "配方下发",
  100. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  101. AssemblyName = "BPASmartClient.Academy",
  102. ToggleWindowPath = "View.RecipeControlView"
  103. });
  104. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  105. {
  106. MainMenuIcon = "&#xe683;",
  107. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  108. MainMenuName = "配方管理",
  109. Alias = "Recipe Management",
  110. subMenumodels = RecipeManage,
  111. });
  112. #endregion
  113. #region 消息日志
  114. ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>();
  115. InfoLog.Add(new SubMenumodel()
  116. {
  117. SubMenuName = "操作日志",
  118. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  119. AssemblyName = "BPASmartClient.CustomResource",
  120. ToggleWindowPath = "Pages.View.UserLogView"
  121. });
  122. InfoLog.Add(new SubMenumodel()
  123. {
  124. SubMenuName = "运行日志",
  125. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  126. AssemblyName = "BPASmartClient.CustomResource",
  127. ToggleWindowPath = "Pages.View.RunLogView"
  128. });
  129. InfoLog.Add(new SubMenumodel()
  130. {
  131. SubMenuName = "报警记录",
  132. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  133. AssemblyName = "BPASmartClient.CustomResource",
  134. ToggleWindowPath = "Pages.View.AlarmView"
  135. });
  136. InfoLog.Add(new SubMenumodel()
  137. {
  138. SubMenuName = "调试日志",
  139. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  140. AssemblyName = "BPASmartClient.CustomResource",
  141. ToggleWindowPath = "Pages.View.DebugLogView"
  142. });
  143. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  144. {
  145. MainMenuIcon = "&#xe668;",
  146. MainMenuName = "消息日志",
  147. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  148. Alias = "Message Log",
  149. subMenumodels = InfoLog,
  150. });
  151. #endregion
  152. #region 硬件设备监控
  153. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  154. DeviceMonitor.Add(new SubMenumodel()
  155. {
  156. SubMenuName = "设备控制",
  157. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  158. AssemblyName = "BPASmartClient.Academy",
  159. ToggleWindowPath = "View.DeviceMotionView"
  160. });
  161. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  162. {
  163. MainMenuIcon = "&#xe603;",
  164. MainMenuName = "设备监控",
  165. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  166. Alias = "Device Monitor",
  167. subMenumodels = DeviceMonitor,
  168. });
  169. #endregion
  170. #region 用户管理
  171. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  172. UserManager.Add(new SubMenumodel()
  173. {
  174. SubMenuName = "用户登录",
  175. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  176. AssemblyName = "BPASmartClient.CustomResource",
  177. ToggleWindowPath = "Pages.View.SubPagLoginView"
  178. });
  179. UserManager.Add(new SubMenumodel()
  180. {
  181. SubMenuName = "密码修改",
  182. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  183. AssemblyName = "BPASmartClient.CustomResource",
  184. ToggleWindowPath = "Pages.View.PasswordChangeView"
  185. });
  186. UserManager.Add(new SubMenumodel()
  187. {
  188. SubMenuName = "用户管理",
  189. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  190. AssemblyName = "BPASmartClient.CustomResource",
  191. ToggleWindowPath = "Pages.View.UserManagerView"
  192. });
  193. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  194. {
  195. MainMenuIcon = "&#xe66d;",
  196. MainMenuName = "用户管理",
  197. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  198. Alias = "User Management",
  199. subMenumodels = UserManager,
  200. });
  201. #endregion
  202. }
  203. private void DataInit()
  204. {
  205. Json<LocalRecipe>.Read();
  206. Json<DevicePar>.Read();
  207. Json<LocaMaterial>.Read();
  208. }
  209. }
  210. }