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

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