终端一体化运控平台
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.

App.xaml.cs 11 KiB

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