终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

110 wiersze
4.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using BPASmartClient.CustomResource.Pages.Model;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.ComponentModel;
  12. using Microsoft.Toolkit.Mvvm.Input;
  13. namespace BPASmartClient.CustomResource.Pages.ViewModel
  14. {
  15. public class MainViewModel : ObservableObject
  16. {
  17. public MainViewModel()
  18. {
  19. NavChangedCommand = new RelayCommand<object>(DoNavChanged);
  20. menuModels = MenuManage.GetInstance.menuModels;
  21. PermissionChange();
  22. ActionManage.GetInstance.Register(new Action(() =>
  23. {
  24. PermissionChange();
  25. }), "PermissionChange");
  26. }
  27. private void PermissionChange()
  28. {
  29. int MainIndex = Array.FindIndex(menuModels.ToArray(), P => P.MainMenuVisibility == Visibility.Visible);
  30. if (MainIndex >= 0 && MainIndex < menuModels.Count)
  31. {
  32. int SubIndex; SubIndex = Array.FindIndex(menuModels.ElementAt(MainIndex).subMenumodels.ToArray(), p => p.SubMenuVisibility == Visibility.Visible);
  33. if (SubIndex >= 0 && SubIndex < menuModels.ElementAt(MainIndex).subMenumodels.Count)
  34. {
  35. DoNavChanged(menuModels.ElementAt(MainIndex).subMenumodels.ElementAt(SubIndex).ToggleWindowPath);
  36. }
  37. }
  38. }
  39. public ObservableCollection<MenuModel> menuModels { get; set; }
  40. private void DoNavChanged(object obj)
  41. {
  42. for (int i = 0; i < menuModels.Count; i++)
  43. {
  44. var res = menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.ToggleWindowPath == obj.ToString());
  45. if (res != null)
  46. {
  47. DisplayName = res.SubMenuName;
  48. var end = res.AssemblyName.Substring(res.AssemblyName.Length - 1);
  49. var start = res.ToggleWindowPath.Substring(0, 1);
  50. bool isAddPoint = end != "." && start != ".";
  51. string point = isAddPoint ? "." : "";
  52. Type type = Assembly.Load(res.AssemblyName)?.GetType($"{res.AssemblyName }{point}{ res.ToggleWindowPath}");
  53. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  54. if (type?.BaseType.Name == "Window")
  55. {
  56. ((Window)cti?.Invoke(null)).ShowDialog();
  57. break;
  58. }
  59. else if (type?.BaseType.Name == "UserControl")
  60. {
  61. //ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  62. MainContent = (FrameworkElement)cti?.Invoke(null);
  63. break;
  64. }
  65. }
  66. }
  67. }
  68. private bool _status;
  69. /// <summary>
  70. /// 设备初始化状态
  71. /// </summary>
  72. public bool Status
  73. {
  74. get { return _status; }
  75. set
  76. {
  77. if (value)
  78. {
  79. ActionManage.GetInstance.Send("StartPlcInite");
  80. }
  81. else
  82. {
  83. ActionManage.GetInstance.Send("EndPlcInite");
  84. }
  85. _status = value;
  86. OnPropertyChanged();
  87. }
  88. }
  89. /// <summary>
  90. /// 开机自启
  91. /// </summary>
  92. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  93. public RelayCommand<object> NavChangedCommand { get; set; }
  94. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  95. private FrameworkElement _mMainContent;
  96. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  97. private string _mDisplayName;
  98. }
  99. }