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

144 lines
4.5 KiB

  1. using BPASmartClient.CustomResource.Pages.Enums;
  2. using BPASmartClient.CustomResource.Pages.Model;
  3. using BPASmartClient.CustomResource.Pages.View;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using BPASmart.Model;
  13. using BPA.Helper;
  14. using System.IO;
  15. namespace BPASmart.VariableManager
  16. {
  17. /// <summary>
  18. /// Interaction logic for App.xaml
  19. /// </summary>
  20. public partial class App : Application
  21. {
  22. //public static string ConstPath = string.Empty;
  23. public static Window MainWindow;
  24. protected override void OnStartup(StartupEventArgs e)
  25. {
  26. base.OnStartup(e);
  27. Json<LocalPar>.Read();
  28. FileConfigModel.ConstPath = Json<LocalPar>.Data.ProjectPath;
  29. DataRead();
  30. AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
  31. MenuInit();
  32. MainView mv = new MainView();
  33. mv.WindowState = WindowState.Normal;
  34. MainWindow = mv;
  35. mv.Show();
  36. }
  37. private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  38. {
  39. DataSave();
  40. }
  41. protected override void OnExit(ExitEventArgs e)
  42. {
  43. base.OnExit(e);
  44. DataSave();
  45. }
  46. private void MenuInit()
  47. {
  48. #region 设备管理
  49. ObservableCollection<SubMenumodel> DeviceMonitor = new ObservableCollection<SubMenumodel>();
  50. DeviceMonitor.Add(new SubMenumodel()
  51. {
  52. SubMenuName = "设备管理",
  53. AssemblyName = "BPASmart.VariableManager",
  54. ToggleWindowPath = "Views.CommunicationSetView",
  55. SubMenuVisibility = Visibility.Visible,
  56. });
  57. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  58. {
  59. MainMenuIcon = "&#xe603;",
  60. MainMenuName = "设备管理",
  61. Alias = "Device Management",
  62. subMenumodels = DeviceMonitor,
  63. });
  64. #endregion
  65. #region 变量管理,根据创建的通讯设备自动生成子菜单
  66. ObservableCollection<SubMenumodel> RecipeManage = new ObservableCollection<SubMenumodel>();
  67. ActionManage.GetInstance.Register(new Action<object>((o) =>
  68. {
  69. RecipeManage.Add(AddSubMenuModel(o.ToString()));
  70. }), "AddCommunicationDevice");
  71. ActionManage.GetInstance.Register(new Action<object>((o) =>
  72. {
  73. if (o != null && o is CommunicationModel menumodel)
  74. {
  75. var res = RecipeManage.FirstOrDefault(p => p.SubMenuName == menumodel.DeviceName);
  76. if (res != null) RecipeManage.Remove(res);
  77. }
  78. }), "RemoveCommunicationDevice");
  79. Json<CommunicationPar>.Data.CommunicationDevices?.ToList()?.ForEach(item =>
  80. {
  81. RecipeManage.Add(AddSubMenuModel(item.DeviceName));
  82. });
  83. MenuManage.GetInstance.menuModels.Add(new MenuModel()
  84. {
  85. MainMenuIcon = "&#xe62d;",
  86. MainMenuName = "变量管理",
  87. Alias = "Recipe Management",
  88. subMenumodels = RecipeManage,
  89. });
  90. #endregion
  91. }
  92. private SubMenumodel AddSubMenuModel(string s)
  93. {
  94. return new SubMenumodel()
  95. {
  96. SubMenuName = s,
  97. AssemblyName = "BPASmart.VariableManager",
  98. ToggleWindowPath = "Views.VariableConfig",
  99. SubMenuVisibility = Visibility.Visible,
  100. };
  101. }
  102. //static string path
  103. //{
  104. // get
  105. // {
  106. // string ReturnValue = null;
  107. // if (Directory.Exists(ConstPath))
  108. // {
  109. // string path = $"{ConstPath}\\AccessFile\\JSON";
  110. // Directory.CreateDirectory(path);
  111. // ReturnValue = $"{ConstPath}\\AccessFile\\JSON\\CommunicationPar.json";
  112. // }
  113. // return ReturnValue;
  114. // }
  115. //}
  116. private void DataSave()
  117. {
  118. Json<CommunicationPar>.Save(FileConfigModel.GetPath);
  119. }
  120. private void DataRead()
  121. {
  122. Json<CommunicationPar>.Read(FileConfigModel.GetPath);
  123. }
  124. }
  125. }