终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

380 lignes
17 KiB

  1. using BPA.Helper;
  2. using BPASmartClient.CustomResource.Pages.Enums;
  3. using BPASmartClient.CustomResource.Pages.Model;
  4. using BPASmartClient.CustomResource.Pages.View;
  5. using BPASmartClient.CustomResource.Pages.ViewModel;
  6. using BPASmartClient.DosingSystem.Model;
  7. using BPASmartClient.DosingSystem.Model.MQTT;
  8. using BPASmartClient.DosingSystem.Service;
  9. using System;
  10. using System.Collections.ObjectModel;
  11. using System.Collections.Specialized;
  12. using System.Configuration;
  13. using System.Diagnostics;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. namespace BPASmartClient.DosingSystem
  18. {
  19. /// <summary>
  20. /// Interaction logic for App.xaml
  21. /// </summary>
  22. public partial class App : Application
  23. {
  24. public static Window MainWindow;
  25. public ExcuteControl excute;
  26. public EventWaitHandle ProgramStarted { get; set; }
  27. protected override async void OnStartup(StartupEventArgs e)
  28. {
  29. bool createNew;
  30. MessageLog.GetInstance.NotifyShow = new Action<string>(o =>
  31. {
  32. DebugLogViewModel.MessageModels.Add(new MessageModel()
  33. {
  34. LogInfo = o,
  35. Forground = System.Windows.Media.Brushes.DeepSkyBlue
  36. });
  37. });
  38. MessageLog.GetInstance.NotifyShowEx = new Action<string>(o =>
  39. {
  40. DebugLogViewModel.MessageModels.Add(new MessageModel()
  41. {
  42. LogInfo = o,
  43. Forground = System.Windows.Media.Brushes.Red
  44. });
  45. });
  46. ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "DosingSystem", out createNew);
  47. if (!createNew)
  48. {
  49. MessageBox.Show("程序已启动");
  50. App.Current.Shutdown();
  51. Environment.Exit(0);
  52. }
  53. base.OnStartup(e);
  54. SystemHelper.GetInstance.CreateDesktopShortcut();
  55. DataInit();
  56. await Task.Run(() => { excute = ExcuteControl.GetInstance; });
  57. MenuInit();
  58. //SiemensTest.GetInstance.Init();
  59. DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
  60. MainView mv = new MainView();
  61. mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  62. LoginView lv = new LoginView();
  63. var res = lv.ShowDialog();
  64. if (res != null && res == true)
  65. {
  66. #region 更新测试
  67. //string directory = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\UpdateModel.json";
  68. //if (File.Exists(directory))
  69. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] {Json<UpdateModel>.Data.UpgradeVersion}";
  70. //else
  71. //{
  72. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  73. // Task.Run(() =>
  74. // {
  75. // Thread.Sleep(3000);
  76. // var tt = MessageNotify.GetInstance.ShowDialog("检测到新版本,请问是否现在更新?", DialogType.Information);
  77. // if (tt)
  78. // {
  79. // string directory = AppDomain.CurrentDomain.BaseDirectory;
  80. // Process.Start($"{directory}BPASmartClient.Update.exe");
  81. // App.Current.Dispatcher.Invoke(() => { mv.Close(); });
  82. // }
  83. // });
  84. //}
  85. #endregion
  86. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog("用户登录");
  87. mv.Show();
  88. }
  89. else
  90. mv.Close();
  91. //ServerFactory.GetInstance.Set(new APIServer());
  92. //MqttServer.GetInstance.Init();
  93. MainWindow = mv;
  94. }
  95. protected override void OnExit(ExitEventArgs e)
  96. {
  97. base.OnExit(e);
  98. excute?.ShutDown();
  99. //excute?.MqttDisConnect();
  100. Json<LocalRecipe>.Save();
  101. Json<DevicePar>.Save();
  102. Json<LocaMaterial>.Save();
  103. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
  104. TaskManage.GetInstance.Dispose();
  105. //Process.GetCurrentProcess().Kill();
  106. }
  107. private void MenuInit()
  108. {
  109. NfcServer.GetInstance.Init();
  110. #region 配方管理菜单
  111. ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  112. RecipeManage.Add(new SubMenumodel()
  113. {
  114. SubMenuName = "配方管理",
  115. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  116. AssemblyName = "BPASmartClient.DosingSystem",
  117. ToggleWindowPath = "View.RecipeSettingsView"
  118. });
  119. RecipeManage.Add(new SubMenumodel()
  120. {
  121. SubMenuName = "配方下发",
  122. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  123. AssemblyName = "BPASmartClient.DosingSystem",
  124. ToggleWindowPath = "View.RecipeControlView"
  125. });
  126. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  127. {
  128. MainMenuIcon = "&#xe683;",
  129. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  130. MainMenuName = "配方管理",
  131. Alias = "Recipe Management",
  132. subMenumodels = RecipeManage,
  133. });
  134. #endregion
  135. #region 参数设置
  136. ObservableCollection<SubMenumodel> ParSet = new ObservableCollection<SubMenumodel>();
  137. ParSet.Add(new SubMenumodel()
  138. {
  139. SubMenuName = "原料参数设置",
  140. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  141. AssemblyName = "BPASmartClient.DosingSystem",
  142. ToggleWindowPath = "View.DeviceMaterialParView"
  143. });
  144. ParSet.Add(new SubMenumodel()
  145. {
  146. SubMenuName = "设备参数设置",
  147. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  148. AssemblyName = "BPASmartClient.DosingSystem",
  149. ToggleWindowPath = "View.CommParSetView"
  150. });
  151. ParSet.Add(new SubMenumodel()
  152. {
  153. SubMenuName = "测试",
  154. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  155. AssemblyName = "BPASmartClient.DosingSystem",
  156. ToggleWindowPath = "View.SendCtrlView"
  157. });
  158. //ParSet.Add(new SubMenumodel()
  159. //{
  160. // SubMenuName = "出料口管理设置",
  161. // SubMenuPermission = new Permission[] { Permission.管理员 },
  162. // AssemblyName = "BPASmartClient.DosingSystem",
  163. // ToggleWindowPath = "View.OutletManagementView"
  164. //});
  165. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  166. {
  167. MainMenuIcon = "&#xe62d;",
  168. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  169. MainMenuName = "参数设置",
  170. Alias = "Parameter Set",
  171. subMenumodels = ParSet,
  172. });
  173. #endregion
  174. #region 手动控制
  175. ObservableCollection<SubMenumodel> ManualControl = new ObservableCollection<SubMenumodel>();
  176. ManualControl.Add(new SubMenumodel()
  177. {
  178. SubMenuName = "气缸手动控制",
  179. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  180. AssemblyName = "BPASmartClient.DosingSystem",
  181. ToggleWindowPath = "View.ManualControlView"
  182. });
  183. ManualControl.Add(new SubMenumodel()
  184. {
  185. SubMenuName = "输送带手动控制",
  186. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  187. AssemblyName = "BPASmartClient.DosingSystem",
  188. ToggleWindowPath = "View.ConveyerBeltManualView"
  189. });
  190. //ManualControl.Add(new SubMenumodel()
  191. //{
  192. // SubMenuName = "配料输送带控制",
  193. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  194. // AssemblyName = "BPASmartClient.DosingSystem",
  195. // ToggleWindowPath = "View.TempManageControlView"
  196. //});
  197. //ManualControl.Add(new SubMenumodel()
  198. //{
  199. // SubMenuName = "料仓控制",
  200. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 },
  201. // AssemblyName = "BPASmartClient.DosingSystem",
  202. // ToggleWindowPath = "View.StockControlView"
  203. //});
  204. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  205. {
  206. MainMenuIcon = "&#xe622;",
  207. MainMenuName = "手动控制",
  208. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  209. Alias = "Parameter Set",
  210. subMenumodels = ManualControl,
  211. });
  212. #endregion
  213. #region 消息日志
  214. ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>();
  215. InfoLog.Add(new SubMenumodel()
  216. {
  217. SubMenuName = "操作日志",
  218. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  219. AssemblyName = "BPASmartClient.CustomResource",
  220. ToggleWindowPath = "Pages.View.UserLogView"
  221. });
  222. InfoLog.Add(new SubMenumodel()
  223. {
  224. SubMenuName = "运行日志",
  225. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  226. AssemblyName = "BPASmartClient.CustomResource",
  227. ToggleWindowPath = "Pages.View.RunLogView"
  228. });
  229. InfoLog.Add(new SubMenumodel()
  230. {
  231. SubMenuName = "报警记录",
  232. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  233. AssemblyName = "BPASmartClient.CustomResource",
  234. ToggleWindowPath = "Pages.View.AlarmView"
  235. });
  236. InfoLog.Add(new SubMenumodel()
  237. {
  238. SubMenuName = "调试日志",
  239. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  240. AssemblyName = "BPASmartClient.CustomResource",
  241. ToggleWindowPath = "Pages.View.DebugLogView"
  242. });
  243. //InfoLog.Add(new SubMenumodel()
  244. //{
  245. // SubMenuName = "报表数据",
  246. // SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员, Permission.技术员 },
  247. // AssemblyName = "BPASmartClient.CustomResource",
  248. // ToggleWindowPath = "Pages.View.ReportView"
  249. //});
  250. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  251. {
  252. MainMenuIcon = "&#xe668;",
  253. MainMenuName = "消息日志",
  254. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  255. Alias = "Message Log",
  256. subMenumodels = InfoLog,
  257. });
  258. #endregion
  259. #region 硬件设备监控
  260. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  261. DeviceMonitor.Add(new SubMenumodel()
  262. {
  263. SubMenuName = "原料设备列表",
  264. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  265. AssemblyName = "BPASmartClient.DosingSystem",
  266. ToggleWindowPath = "View.DeviceListView"
  267. });
  268. //2023/6/29修改
  269. if (!String.IsNullOrWhiteSpace(Json<DevicePar>.Data.BaseParModel.ConveryType) && (ConveryType)Enum.Parse(typeof(ConveryType), Json<DevicePar>.Data.BaseParModel.ConveryType) == ConveryType.U型)
  270. {
  271. DeviceMonitor.Add(new SubMenumodel()
  272. {
  273. SubMenuName = "设备状态",
  274. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  275. AssemblyName = "BPASmartClient.DosingSystem",
  276. ToggleWindowPath = "View.UHardwareStatusView"
  277. });
  278. }
  279. else
  280. {
  281. DeviceMonitor.Add(new SubMenumodel()
  282. {
  283. SubMenuName = "设备状态",
  284. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  285. AssemblyName = "BPASmartClient.DosingSystem",
  286. ToggleWindowPath = "View.HardwareStatusView"
  287. });
  288. }
  289. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  290. {
  291. MainMenuIcon = "&#xe603;",
  292. MainMenuName = "设备监控",
  293. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  294. Alias = "Device Monitor",
  295. subMenumodels = DeviceMonitor,
  296. });
  297. #endregion
  298. #region 用户管理
  299. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  300. UserManager.Add(new SubMenumodel()
  301. {
  302. SubMenuName = "用户登录",
  303. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  304. AssemblyName = "BPASmartClient.CustomResource",
  305. ToggleWindowPath = "Pages.View.SubPagLoginView"
  306. });
  307. UserManager.Add(new SubMenumodel()
  308. {
  309. SubMenuName = "密码修改",
  310. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  311. AssemblyName = "BPASmartClient.CustomResource",
  312. ToggleWindowPath = "Pages.View.PasswordChangeView"
  313. });
  314. UserManager.Add(new SubMenumodel()
  315. {
  316. SubMenuName = "用户管理",
  317. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  318. AssemblyName = "BPASmartClient.CustomResource",
  319. ToggleWindowPath = "Pages.View.UserManagerView"
  320. });
  321. //UserManager.Add(new SubMenumodel()
  322. //{
  323. // SubMenuName = "NFC登录管理",
  324. // SubMenuPermission = new Permission[] { Permission.管理员 },
  325. // AssemblyName = "BPASmartClient.CustomResource",
  326. // ToggleWindowPath = "Pages.View.NfcSetView"
  327. //});
  328. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  329. {
  330. MainMenuIcon = "&#xe66d;",
  331. MainMenuName = "用户管理",
  332. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  333. Alias = "User Management",
  334. subMenumodels = UserManager,
  335. });
  336. #endregion
  337. }
  338. private void DataInit()
  339. {
  340. //Config.GetInstance.Init();
  341. Json<LocalRecipe>.Read();
  342. Json<DevicePar>.Read();
  343. Json<LocaMaterial>.Read();
  344. }
  345. }
  346. }