终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

356 行
16 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using BPASmartClient.CustomResource.Pages.Enums;
  11. using BPASmartClient.CustomResource.Pages.Model;
  12. using BPASmartClient.CustomResource.Pages.View;
  13. using BPASmartClient.CustomResource.Pages.ViewModel;
  14. using BPASmartClient.DosingSystem.View;
  15. using BPA.Helper;
  16. using BPASmartClient.DosingSystem.Model;
  17. using System.Diagnostics;
  18. using System.IO;
  19. using BPASmartClient.Update.Model;
  20. using BPASmartClient.DosingSystem.ViewModel;
  21. using System.Drawing;
  22. using System.Windows.Media;
  23. namespace BPASmartClient.DosingSystem
  24. {
  25. /// <summary>
  26. /// Interaction logic for App.xaml
  27. /// </summary>
  28. public partial class App : Application
  29. {
  30. public static Window MainWindow;
  31. public EventWaitHandle ProgramStarted { get; set; }
  32. protected override void OnStartup(StartupEventArgs e)
  33. {
  34. bool createNew;
  35. MessageLog.GetInstance.NotifyShow = new Action<string>(o =>
  36. {
  37. DebugLogViewModel.MessageModels.Add(new MessageModel()
  38. {
  39. LogInfo = o,
  40. Forground = System.Windows.Media.Brushes.DeepSkyBlue
  41. });
  42. });
  43. MessageLog.GetInstance.NotifyShowEx = new Action<string>(o =>
  44. {
  45. DebugLogViewModel.MessageModels.Add(new MessageModel()
  46. {
  47. LogInfo = o,
  48. Forground = System.Windows.Media.Brushes.Red
  49. });
  50. });
  51. ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "DosingSystem", out createNew);
  52. if (!createNew)
  53. {
  54. MessageBox.Show("程序已启动");
  55. App.Current.Shutdown();
  56. Environment.Exit(0);
  57. }
  58. base.OnStartup(e);
  59. BPASmartClient.Helper.SystemHelper.GetInstance.CreateDesktopShortcut();
  60. MenuInit();
  61. DataInit();
  62. //SiemensTest.GetInstance.Init();
  63. DeviceInquire.GetInstance.Init();//配料机设备上线监听,设备列表初始化
  64. MainView mv = new MainView();
  65. mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  66. LoginView lv = new LoginView();
  67. var res = lv.ShowDialog();
  68. if (res != null && res == true)
  69. {
  70. #region 更新测试
  71. //string directory = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\UpdateModel.json";
  72. //if (File.Exists(directory))
  73. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] {Json<UpdateModel>.Data.UpgradeVersion}";
  74. //else
  75. //{
  76. // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  77. // Task.Run(() =>
  78. // {
  79. // Thread.Sleep(3000);
  80. // var tt = MessageNotify.GetInstance.ShowDialog("检测到新版本,请问是否现在更新?", DialogType.Information);
  81. // if (tt)
  82. // {
  83. // string directory = AppDomain.CurrentDomain.BaseDirectory;
  84. // Process.Start($"{directory}BPASmartClient.Update.exe");
  85. // App.Current.Dispatcher.Invoke(() => { mv.Close(); });
  86. // }
  87. // });
  88. //}
  89. #endregion
  90. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog("用户登录");
  91. mv.Show();
  92. }
  93. else
  94. mv.Close();
  95. MainWindow = mv;
  96. }
  97. protected override void OnExit(ExitEventArgs e)
  98. {
  99. base.OnExit(e);
  100. Json<LocalRecipe>.Save();
  101. Json<DevicePar>.Save();
  102. Json<LocaMaterial>.Save();
  103. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
  104. ThreadManage.GetInstance().Dispose();
  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. DeviceMonitor.Add(new SubMenumodel()
  261. {
  262. SubMenuName = "设备状态",
  263. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  264. AssemblyName = "BPASmartClient.DosingSystem",
  265. ToggleWindowPath = "View.HardwareStatusView"
  266. });
  267. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  268. {
  269. MainMenuIcon = "&#xe603;",
  270. MainMenuName = "设备监控",
  271. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  272. Alias = "Device Monitor",
  273. subMenumodels = DeviceMonitor,
  274. });
  275. #endregion
  276. #region 用户管理
  277. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  278. UserManager.Add(new SubMenumodel()
  279. {
  280. SubMenuName = "用户登录",
  281. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  282. AssemblyName = "BPASmartClient.CustomResource",
  283. ToggleWindowPath = "Pages.View.SubPagLoginView"
  284. });
  285. UserManager.Add(new SubMenumodel()
  286. {
  287. SubMenuName = "密码修改",
  288. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  289. AssemblyName = "BPASmartClient.CustomResource",
  290. ToggleWindowPath = "Pages.View.PasswordChangeView"
  291. });
  292. UserManager.Add(new SubMenumodel()
  293. {
  294. SubMenuName = "用户管理",
  295. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  296. AssemblyName = "BPASmartClient.CustomResource",
  297. ToggleWindowPath = "Pages.View.UserManagerView"
  298. });
  299. //UserManager.Add(new SubMenumodel()
  300. //{
  301. // SubMenuName = "NFC登录管理",
  302. // SubMenuPermission = new Permission[] { Permission.管理员 },
  303. // AssemblyName = "BPASmartClient.CustomResource",
  304. // ToggleWindowPath = "Pages.View.NfcSetView"
  305. //});
  306. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  307. {
  308. MainMenuIcon = "&#xe66d;",
  309. MainMenuName = "用户管理",
  310. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  311. Alias = "User Management",
  312. subMenumodels = UserManager,
  313. });
  314. #endregion
  315. }
  316. private void DataInit()
  317. {
  318. //Config.GetInstance.Init();
  319. Json<LocalRecipe>.Read();
  320. Json<DevicePar>.Read();
  321. Json<LocaMaterial>.Read();
  322. }
  323. }
  324. }