终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

337 lines
15 KiB

  1. using BPASmartClient.Academy._50L;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using LiveCharts;
  4. using System.Collections.Specialized;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.Linq.Expressions;
  8. using System.Windows;
  9. namespace BPASmartClient.Academy
  10. {
  11. /// <summary>
  12. /// Interaction logic for App.xaml
  13. /// </summary>
  14. public partial class App : Application
  15. {
  16. public static Window MainWindow;
  17. public EventWaitHandle ProgramStarted { get; set; }
  18. protected override void OnStartup(StartupEventArgs e)
  19. {
  20. bool createNew;
  21. MessageLog.GetInstance.NotifyShow = new Action<string>(o =>
  22. {
  23. DebugLogViewModel.MessageModels.Add(new MessageModel()
  24. {
  25. LogInfo = o,
  26. Forground = System.Windows.Media.Brushes.DeepSkyBlue
  27. });
  28. });
  29. MessageLog.GetInstance.NotifyShowEx = new Action<string>(o =>
  30. {
  31. DebugLogViewModel.MessageModels.Add(new MessageModel()
  32. {
  33. LogInfo = o,
  34. Forground = System.Windows.Media.Brushes.Red
  35. });
  36. });
  37. //AlarmViewModel.AlarmInfos = MessageNotify.GetInstance.alarmLogs;
  38. ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "Academy", out createNew);
  39. if (!createNew)
  40. {
  41. MessageBox.Show("程序已启动");
  42. App.Current.Shutdown();
  43. Environment.Exit(0);
  44. }
  45. base.OnStartup(e);
  46. SystemHelper.GetInstance.CreateDesktopShortcut();
  47. DataInit();
  48. MenuInit();
  49. MainView mv = new MainView();
  50. string typeName = Json<DevicePar>.Data.ProjectTypeName == ProjectType.HKYF20240714.ToString() ? "10L" : "50L";
  51. mv.TitleName = $"{typeName} 反应釜焖制系统 V1.0.1";
  52. //#if !DEBUG
  53. // LoginView lv = new LoginView();
  54. // var res = lv.ShowDialog();
  55. // if (res != null && res == true)
  56. // {
  57. // #region 更新测试
  58. // //string directory = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\UpdateModel.json";
  59. // //if (File.Exists(directory))
  60. // // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] {Json<UpdateModel>.Data.UpgradeVersion}";
  61. // //else
  62. // //{
  63. // // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1";
  64. // // Task.Run(() =>
  65. // // {
  66. // // Thread.Sleep(3000);
  67. // // var tt = MessageNotify.GetInstance.ShowDialog("检测到新版本,请问是否现在更新?", DialogType.Information);
  68. // // if (tt)
  69. // // {
  70. // // string directory = AppDomain.CurrentDomain.BaseDirectory;
  71. // // Process.Start($"{directory}BPASmartClient.Update.exe");
  72. // // App.Current.Dispatcher.Invoke(() => { mv.Close(); });
  73. // // }
  74. // // });
  75. // //}
  76. // #endregion
  77. // BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog("用户登录");
  78. // mv.Show();
  79. // }
  80. // else
  81. // mv.Close();
  82. //#else
  83. mv.Show();
  84. //#endif
  85. MainWindow = mv;
  86. }
  87. protected override void OnExit(ExitEventArgs e)
  88. {
  89. base.OnExit(e);
  90. Json<LocalRecipe>.Save();
  91. Json<DevicePar>.Save();
  92. Json<LocaMaterial>.Save();
  93. BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave();
  94. TaskManage.GetInstance.Dispose();
  95. switch (Json<DevicePar>.Data.ProjectTypeName)
  96. {
  97. case "HKYF20240916":
  98. if (PlcControl.GetInstance.IsConnect)
  99. {
  100. PlcControl.GetInstance.Write(BoolAddEnum.系统启动, false);
  101. }
  102. break;
  103. default:
  104. if (Simens_PLC.GetInstance.IsConnected)
  105. {
  106. Simens_PLC.GetInstance.id = "";
  107. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1002.0", false);
  108. Simens_PLC.GetInstance.siemens.Write<bool>("DB1.DBX1002.1", false);
  109. }
  110. break;
  111. }
  112. App.Current.Shutdown();
  113. Environment.Exit(0);
  114. //Process.GetCurrentProcess().Kill();
  115. }
  116. private void MenuInit()
  117. {
  118. #region 配方管理菜单
  119. //ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  120. //RecipeManage.Add(new SubMenumodel()
  121. //{
  122. // SubMenuName = "配方管理",
  123. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  124. // AssemblyName = "BPASmartClient.Academy",
  125. // ToggleWindowPath = "View.RecipeSettingsView"
  126. //});
  127. //RecipeManage.Add(new SubMenumodel()
  128. //{
  129. // SubMenuName = "配方下发",
  130. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  131. // AssemblyName = "BPASmartClient.Academy",
  132. // ToggleWindowPath = "View.RecipeControlView"
  133. //});
  134. //MenuManage.GetInstance.menuModels.Add(new MenuModel()
  135. //{
  136. // MainMenuIcon = "&#xe683;",
  137. // MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  138. // MainMenuName = "配方管理",
  139. // Alias = "Recipe Management",
  140. // subMenumodels = RecipeManage,
  141. //});
  142. #endregion
  143. #region 硬件设备监控
  144. bool Is10L = Json<DevicePar>.Data.ProjectTypeName == ProjectType.HKYF20240714.ToString();
  145. int num = 0;
  146. if (Enum.TryParse(typeof(ProjectType), Json<DevicePar>.Data.ProjectTypeName,out var enmuvalue))
  147. {
  148. num = (int) enmuvalue;
  149. }
  150. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  151. DeviceMonitor.Add(new SubMenumodel()
  152. {
  153. SubMenuName = "设备控制",
  154. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  155. AssemblyName = "BPASmartClient.Academy",
  156. ToggleWindowPath = num==0 ? "View.DeviceMotionView" :num==1? "View.ReactionKettle50LView": "View.DeviceMotion_2View"
  157. });
  158. //DeviceMonitor.Add(new SubMenumodel()
  159. //{
  160. // SubMenuName = "设备控制模板1",
  161. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  162. // AssemblyName = "BPASmartClient.Academy",
  163. // ToggleWindowPath = "View.DeviceMotionView"
  164. //});
  165. //DeviceMonitor.Add(new SubMenumodel()
  166. //{
  167. // SubMenuName = "设备控制模板2",
  168. // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  169. // AssemblyName = "BPASmartClient.Academy",
  170. // ToggleWindowPath = "View.DeviceMotion_2View"
  171. //});
  172. DeviceMonitor.Add(new SubMenumodel()
  173. {
  174. SubMenuName = "数据曲线",
  175. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  176. AssemblyName = "BPASmartClient.Academy",
  177. ToggleWindowPath = num==0 ? "View.DeviceChartView" :num==1? "View.DeviceChart50LView": "View.DeviceChartView"
  178. }); ;
  179. DeviceMonitor.Add(new SubMenumodel()
  180. {
  181. SubMenuName = "历史曲线",
  182. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  183. AssemblyName = "BPASmartClient.Academy",
  184. ToggleWindowPath = num==0 ? "View.HistoryChartView" : num==1?"View.HistoryChart50LView": "View.HistoryChartView"
  185. });
  186. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  187. {
  188. MainMenuIcon = "&#xe603;",
  189. MainMenuName = "设备监控",
  190. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  191. Alias = "Device Monitor",
  192. subMenumodels = DeviceMonitor,
  193. });
  194. #endregion
  195. #region 用户管理
  196. ObservableCollection<SubMenumodel> UserManager = new ObservableCollection<SubMenumodel>();
  197. UserManager.Add(new SubMenumodel()
  198. {
  199. SubMenuName = "用户登录",
  200. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  201. AssemblyName = "BPASmartClient.CustomResource",
  202. ToggleWindowPath = "Pages.View.SubPagLoginView"
  203. });
  204. UserManager.Add(new SubMenumodel()
  205. {
  206. SubMenuName = "密码修改",
  207. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  208. AssemblyName = "BPASmartClient.CustomResource",
  209. ToggleWindowPath = "Pages.View.PasswordChangeView"
  210. });
  211. UserManager.Add(new SubMenumodel()
  212. {
  213. SubMenuName = "用户管理",
  214. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  215. AssemblyName = "BPASmartClient.CustomResource",
  216. ToggleWindowPath = "Pages.View.UserManagerView"
  217. });
  218. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  219. {
  220. MainMenuIcon = "&#xe66d;",
  221. MainMenuName = "用户管理",
  222. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  223. Alias = "User Management",
  224. subMenumodels = UserManager,
  225. });
  226. #endregion
  227. #region 消息日志
  228. ObservableCollection<SubMenumodel> InfoLog = new ObservableCollection<SubMenumodel>();
  229. InfoLog.Add(new SubMenumodel()
  230. {
  231. SubMenuName = "操作日志",
  232. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  233. AssemblyName = "BPASmartClient.CustomResource",
  234. ToggleWindowPath = "Pages.View.UserLogView"
  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.RunLogView"
  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.AlarmView"
  249. });
  250. InfoLog.Add(new SubMenumodel()
  251. {
  252. SubMenuName = "调试日志",
  253. SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  254. AssemblyName = "BPASmartClient.CustomResource",
  255. ToggleWindowPath = "Pages.View.DebugLogView"
  256. });
  257. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  258. {
  259. MainMenuIcon = "&#xe668;",
  260. MainMenuName = "消息日志",
  261. MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 },
  262. Alias = "Message Log",
  263. subMenumodels = InfoLog,
  264. });
  265. #endregion
  266. #region 系统设置
  267. ObservableCollection<SubMenumodel> SystemSet = new ObservableCollection<SubMenumodel>();
  268. SystemSet.Add(new SubMenumodel()
  269. {
  270. SubMenuName = "系统设置",
  271. SubMenuPermission = new Permission[] { Permission.管理员, Permission.技术员 },
  272. AssemblyName = "BPASmartClient.Academy",
  273. ToggleWindowPath = "View.ParameterSetView"
  274. });
  275. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  276. {
  277. MainMenuIcon = "&#xe668;",
  278. MainMenuName = "系统设置",
  279. MainMenuPermission = new Permission[] { Permission.管理员, Permission.技术员 },
  280. Alias = "System Set",
  281. subMenumodels = SystemSet,
  282. });
  283. #endregion
  284. }
  285. private void DataInit()
  286. {
  287. Json<DevicePar>.Read();
  288. //Json<LocalRecipe>.Read();
  289. //Json<LocaMaterial>.Read();
  290. if (Json<DevicePar>.Data.ProjectTypeName.TryToEnum(out ProjectType pt))
  291. {
  292. switch (pt)
  293. {
  294. case ProjectType.HKYF20240714:
  295. Sqlite.GetInstance.Init();
  296. Simens_PLC.GetInstance.Init();
  297. Simens_PLC.GetInstance.Connect();
  298. break;
  299. case ProjectType.HKYF20240714_2:
  300. Sqlite.GetInstance.Init();
  301. Simens_PLC.GetInstance.Init();
  302. Simens_PLC.GetInstance.Connect();
  303. break;
  304. case ProjectType.HKYF20240916:
  305. SqliteOperate.GetInstance.Init();
  306. PlcControl.GetInstance.Init();
  307. break;
  308. default:
  309. break;
  310. }
  311. }
  312. }
  313. }
  314. }