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

137 lines
4.6 KiB

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