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

379 lines
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?.MqttDisConnect();
  99. Json<LocalRecipe>.Save();
  100. Json<DevicePar>.Save();
  101. Json<LocaMaterial>.Save();
  102. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
  103. TaskManage.GetInstance.Dispose();
  104. //Process.GetCurrentProcess().Kill();
  105. }
  106. private void MenuInit()
  107. {
  108. NfcServer.GetInstance.Init();
  109. #region 配方管理菜单
  110. ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  111. RecipeManage.Add(new SubMenumodel()
  112. {
  113. SubMenuName = "配方管理",
  114. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  115. AssemblyName = "BPASmartClient.DosingSystem",
  116. ToggleWindowPath = "View.RecipeSettingsView"
  117. });
  118. RecipeManage.Add(new SubMenumodel()
  119. {
  120. SubMenuName = "配方下发",
  121. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  122. AssemblyName = "BPASmartClient.DosingSystem",
  123. ToggleWindowPath = "View.RecipeControlView"
  124. });
  125. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  126. {
  127. MainMenuIcon = "&#xe683;",
  128. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  129. MainMenuName = "配方管理",
  130. Alias = "Recipe Management",
  131. subMenumodels = RecipeManage,
  132. });
  133. #endregion
  134. #region 参数设置
  135. ObservableCollection<SubMenumodel> ParSet = new ObservableCollection<SubMenumodel>();
  136. ParSet.Add(new SubMenumodel()
  137. {
  138. SubMenuName = "原料参数设置",
  139. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  140. AssemblyName = "BPASmartClient.DosingSystem",
  141. ToggleWindowPath = "View.DeviceMaterialParView"
  142. });
  143. ParSet.Add(new SubMenumodel()
  144. {
  145. SubMenuName = "设备参数设置",
  146. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  147. AssemblyName = "BPASmartClient.DosingSystem",
  148. ToggleWindowPath = "View.CommParSetView"
  149. });
  150. ParSet.Add(new SubMenumodel()
  151. {
  152. SubMenuName = "测试",
  153. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  154. AssemblyName = "BPASmartClient.DosingSystem",
  155. ToggleWindowPath = "View.SendCtrlView"
  156. });
  157. //ParSet.Add(new SubMenumodel()
  158. //{
  159. // SubMenuName = "出料口管理设置",
  160. // SubMenuPermission = new Permission[] { Permission.管理员 },
  161. // AssemblyName = "BPASmartClient.DosingSystem",
  162. // ToggleWindowPath = "View.OutletManagementView"
  163. //});
  164. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  165. {
  166. MainMenuIcon = "&#xe62d;",
  167. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  168. MainMenuName = "参数设置",
  169. Alias = "Parameter Set",
  170. subMenumodels = ParSet,
  171. });
  172. #endregion
  173. #region 手动控制
  174. ObservableCollection<SubMenumodel> ManualControl = new ObservableCollection<SubMenumodel>();
  175. ManualControl.Add(new SubMenumodel()
  176. {
  177. SubMenuName = "气缸手动控制",
  178. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  179. AssemblyName = "BPASmartClient.DosingSystem",
  180. ToggleWindowPath = "View.ManualControlView"
  181. });
  182. ManualControl.Add(new SubMenumodel()
  183. {
  184. SubMenuName = "输送带手动控制",
  185. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  186. AssemblyName = "BPASmartClient.DosingSystem",
  187. ToggleWindowPath = "View.ConveyerBeltManualView"
  188. });
  189. //ManualControl.Add(new SubMenumodel()
  190. //{
  191. // SubMenuName = "配料输送带控制",
  192. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  193. // AssemblyName = "BPASmartClient.DosingSystem",
  194. // ToggleWindowPath = "View.TempManageControlView"
  195. //});
  196. //ManualControl.Add(new SubMenumodel()
  197. //{
  198. // SubMenuName = "料仓控制",
  199. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 },
  200. // AssemblyName = "BPASmartClient.DosingSystem",
  201. // ToggleWindowPath = "View.StockControlView"
  202. //});
  203. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  204. {
  205. MainMenuIcon = "&#xe622;",
  206. MainMenuName = "手动控制",
  207. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  208. Alias = "Parameter Set",
  209. subMenumodels = ManualControl,
  210. });
  211. #endregion
  212. #region 消息日志
  213. ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>();
  214. InfoLog.Add(new SubMenumodel()
  215. {
  216. SubMenuName = "操作日志",
  217. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  218. AssemblyName = "BPASmartClient.CustomResource",
  219. ToggleWindowPath = "Pages.View.UserLogView"
  220. });
  221. InfoLog.Add(new SubMenumodel()
  222. {
  223. SubMenuName = "运行日志",
  224. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  225. AssemblyName = "BPASmartClient.CustomResource",
  226. ToggleWindowPath = "Pages.View.RunLogView"
  227. });
  228. InfoLog.Add(new SubMenumodel()
  229. {
  230. SubMenuName = "报警记录",
  231. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  232. AssemblyName = "BPASmartClient.CustomResource",
  233. ToggleWindowPath = "Pages.View.AlarmView"
  234. });
  235. InfoLog.Add(new SubMenumodel()
  236. {
  237. SubMenuName = "调试日志",
  238. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  239. AssemblyName = "BPASmartClient.CustomResource",
  240. ToggleWindowPath = "Pages.View.DebugLogView"
  241. });
  242. //InfoLog.Add(new SubMenumodel()
  243. //{
  244. // SubMenuName = "报表数据",
  245. // SubMenuPermission = new Permission[] { Permission.操作员, Permission.管理员, Permission.技术员, Permission.技术员 },
  246. // AssemblyName = "BPASmartClient.CustomResource",
  247. // ToggleWindowPath = "Pages.View.ReportView"
  248. //});
  249. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  250. {
  251. MainMenuIcon = "&#xe668;",
  252. MainMenuName = "消息日志",
  253. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  254. Alias = "Message Log",
  255. subMenumodels = InfoLog,
  256. });
  257. #endregion
  258. #region 硬件设备监控
  259. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  260. DeviceMonitor.Add(new SubMenumodel()
  261. {
  262. SubMenuName = "原料设备列表",
  263. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  264. AssemblyName = "BPASmartClient.DosingSystem",
  265. ToggleWindowPath = "View.DeviceListView"
  266. });
  267. //2023/6/29修改
  268. if (!String.IsNullOrWhiteSpace(Json<DevicePar>.Data.BaseParModel.ConveryType) && (ConveryType)Enum.Parse(typeof(ConveryType), Json<DevicePar>.Data.BaseParModel.ConveryType) == ConveryType.U型)
  269. {
  270. DeviceMonitor.Add(new SubMenumodel()
  271. {
  272. SubMenuName = "设备状态",
  273. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  274. AssemblyName = "BPASmartClient.DosingSystem",
  275. ToggleWindowPath = "View.UHardwareStatusView"
  276. });
  277. }
  278. else
  279. {
  280. DeviceMonitor.Add(new SubMenumodel()
  281. {
  282. SubMenuName = "设备状态",
  283. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  284. AssemblyName = "BPASmartClient.DosingSystem",
  285. ToggleWindowPath = "View.HardwareStatusView"
  286. });
  287. }
  288. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  289. {
  290. MainMenuIcon = "&#xe603;",
  291. MainMenuName = "设备监控",
  292. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  293. Alias = "Device Monitor",
  294. subMenumodels = DeviceMonitor,
  295. });
  296. #endregion
  297. #region 用户管理
  298. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  299. UserManager.Add(new SubMenumodel()
  300. {
  301. SubMenuName = "用户登录",
  302. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  303. AssemblyName = "BPASmartClient.CustomResource",
  304. ToggleWindowPath = "Pages.View.SubPagLoginView"
  305. });
  306. UserManager.Add(new SubMenumodel()
  307. {
  308. SubMenuName = "密码修改",
  309. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  310. AssemblyName = "BPASmartClient.CustomResource",
  311. ToggleWindowPath = "Pages.View.PasswordChangeView"
  312. });
  313. UserManager.Add(new SubMenumodel()
  314. {
  315. SubMenuName = "用户管理",
  316. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  317. AssemblyName = "BPASmartClient.CustomResource",
  318. ToggleWindowPath = "Pages.View.UserManagerView"
  319. });
  320. //UserManager.Add(new SubMenumodel()
  321. //{
  322. // SubMenuName = "NFC登录管理",
  323. // SubMenuPermission = new Permission[] { Permission.管理员 },
  324. // AssemblyName = "BPASmartClient.CustomResource",
  325. // ToggleWindowPath = "Pages.View.NfcSetView"
  326. //});
  327. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  328. {
  329. MainMenuIcon = "&#xe66d;",
  330. MainMenuName = "用户管理",
  331. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  332. Alias = "User Management",
  333. subMenumodels = UserManager,
  334. });
  335. #endregion
  336. }
  337. private void DataInit()
  338. {
  339. //Config.GetInstance.Init();
  340. Json<LocalRecipe>.Read();
  341. Json<DevicePar>.Read();
  342. Json<LocaMaterial>.Read();
  343. }
  344. }
  345. }