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

372 rivejä
16 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.管理员 },
  154. // AssemblyName = "BPASmartClient.DosingSystem",
  155. // ToggleWindowPath = "View.OutletManagementView"
  156. //});
  157. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  158. {
  159. MainMenuIcon = "&#xe62d;",
  160. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  161. MainMenuName = "参数设置",
  162. Alias = "Parameter Set",
  163. subMenumodels = ParSet,
  164. });
  165. #endregion
  166. #region 手动控制
  167. ObservableCollection<SubMenumodel> ManualControl = new ObservableCollection<SubMenumodel>();
  168. ManualControl.Add(new SubMenumodel()
  169. {
  170. SubMenuName = "气缸手动控制",
  171. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  172. AssemblyName = "BPASmartClient.DosingSystem",
  173. ToggleWindowPath = "View.ManualControlView"
  174. });
  175. ManualControl.Add(new SubMenumodel()
  176. {
  177. SubMenuName = "输送带手动控制",
  178. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  179. AssemblyName = "BPASmartClient.DosingSystem",
  180. ToggleWindowPath = "View.ConveyerBeltManualView"
  181. });
  182. //ManualControl.Add(new SubMenumodel()
  183. //{
  184. // SubMenuName = "配料输送带控制",
  185. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  186. // AssemblyName = "BPASmartClient.DosingSystem",
  187. // ToggleWindowPath = "View.TempManageControlView"
  188. //});
  189. //ManualControl.Add(new SubMenumodel()
  190. //{
  191. // SubMenuName = "料仓控制",
  192. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.技术员 },
  193. // AssemblyName = "BPASmartClient.DosingSystem",
  194. // ToggleWindowPath = "View.StockControlView"
  195. //});
  196. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  197. {
  198. MainMenuIcon = "&#xe622;",
  199. MainMenuName = "手动控制",
  200. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  201. Alias = "Parameter Set",
  202. subMenumodels = ManualControl,
  203. });
  204. #endregion
  205. #region 消息日志
  206. ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>();
  207. InfoLog.Add(new SubMenumodel()
  208. {
  209. SubMenuName = "操作日志",
  210. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  211. AssemblyName = "BPASmartClient.CustomResource",
  212. ToggleWindowPath = "Pages.View.UserLogView"
  213. });
  214. InfoLog.Add(new SubMenumodel()
  215. {
  216. SubMenuName = "运行日志",
  217. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  218. AssemblyName = "BPASmartClient.CustomResource",
  219. ToggleWindowPath = "Pages.View.RunLogView"
  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.AlarmView"
  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.DebugLogView"
  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.ReportView"
  241. //});
  242. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  243. {
  244. MainMenuIcon = "&#xe668;",
  245. MainMenuName = "消息日志",
  246. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  247. Alias = "Message Log",
  248. subMenumodels = InfoLog,
  249. });
  250. #endregion
  251. #region 硬件设备监控
  252. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  253. DeviceMonitor.Add(new SubMenumodel()
  254. {
  255. SubMenuName = "原料设备列表",
  256. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  257. AssemblyName = "BPASmartClient.DosingSystem",
  258. ToggleWindowPath = "View.DeviceListView"
  259. });
  260. //2023/6/29修改
  261. if (!String.IsNullOrWhiteSpace(Json<DevicePar>.Data.BaseParModel.ConveryType) && (ConveryType)Enum.Parse(typeof(ConveryType), Json<DevicePar>.Data.BaseParModel.ConveryType) == ConveryType.U型)
  262. {
  263. DeviceMonitor.Add(new SubMenumodel()
  264. {
  265. SubMenuName = "设备状态",
  266. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  267. AssemblyName = "BPASmartClient.DosingSystem",
  268. ToggleWindowPath = "View.UHardwareStatusView"
  269. });
  270. }
  271. else
  272. {
  273. DeviceMonitor.Add(new SubMenumodel()
  274. {
  275. SubMenuName = "设备状态",
  276. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  277. AssemblyName = "BPASmartClient.DosingSystem",
  278. ToggleWindowPath = "View.HardwareStatusView"
  279. });
  280. }
  281. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  282. {
  283. MainMenuIcon = "&#xe603;",
  284. MainMenuName = "设备监控",
  285. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  286. Alias = "Device Monitor",
  287. subMenumodels = DeviceMonitor,
  288. });
  289. #endregion
  290. #region 用户管理
  291. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  292. UserManager.Add(new SubMenumodel()
  293. {
  294. SubMenuName = "用户登录",
  295. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  296. AssemblyName = "BPASmartClient.CustomResource",
  297. ToggleWindowPath = "Pages.View.SubPagLoginView"
  298. });
  299. UserManager.Add(new SubMenumodel()
  300. {
  301. SubMenuName = "密码修改",
  302. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  303. AssemblyName = "BPASmartClient.CustomResource",
  304. ToggleWindowPath = "Pages.View.PasswordChangeView"
  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.UserManagerView"
  312. });
  313. //UserManager.Add(new SubMenumodel()
  314. //{
  315. // SubMenuName = "NFC登录管理",
  316. // SubMenuPermission = new Permission[] { Permission.管理员 },
  317. // AssemblyName = "BPASmartClient.CustomResource",
  318. // ToggleWindowPath = "Pages.View.NfcSetView"
  319. //});
  320. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  321. {
  322. MainMenuIcon = "&#xe66d;",
  323. MainMenuName = "用户管理",
  324. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  325. Alias = "User Management",
  326. subMenumodels = UserManager,
  327. });
  328. #endregion
  329. }
  330. private void DataInit()
  331. {
  332. //Config.GetInstance.Init();
  333. Json<LocalRecipe>.Read();
  334. Json<DevicePar>.Read();
  335. Json<LocaMaterial>.Read();
  336. }
  337. }
  338. }