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

244 lines
10 KiB

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