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

111 rivejä
4.2 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. ActionManage.GetInstance.Send("RecipeIsChange");
  43. for (int i = 0; i < menuModels.Count; i++)
  44. {
  45. var res = menuModels.ElementAt(i).subMenumodels.FirstOrDefault(p => p.ToggleWindowPath == obj.ToString());
  46. if (res != null)
  47. {
  48. DisplayName = res.SubMenuName;
  49. var end = res.AssemblyName.Substring(res.AssemblyName.Length - 1);
  50. var start = res.ToggleWindowPath.Substring(0, 1);
  51. bool isAddPoint = end != "." && start != ".";
  52. string point = isAddPoint ? "." : "";
  53. Type type = Assembly.Load(res.AssemblyName)?.GetType($"{res.AssemblyName }{point}{ res.ToggleWindowPath}");
  54. ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  55. if (type?.BaseType.Name == "Window")
  56. {
  57. ((Window)cti?.Invoke(null)).ShowDialog();
  58. break;
  59. }
  60. else if (type?.BaseType.Name == "UserControl")
  61. {
  62. //ConstructorInfo cti = type?.GetConstructor(System.Type.EmptyTypes);
  63. MainContent = (FrameworkElement)cti?.Invoke(null);
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. private bool _status;
  70. /// <summary>
  71. /// 设备初始化状态
  72. /// </summary>
  73. public bool Status
  74. {
  75. get { return _status; }
  76. set
  77. {
  78. if (value)
  79. {
  80. ActionManage.GetInstance.Send("StartPlcInite");
  81. }
  82. else
  83. {
  84. ActionManage.GetInstance.Send("EndPlcInite");
  85. }
  86. _status = value;
  87. OnPropertyChanged();
  88. }
  89. }
  90. /// <summary>
  91. /// 开机自启
  92. /// </summary>
  93. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  94. public RelayCommand<object> NavChangedCommand { get; set; }
  95. public FrameworkElement MainContent { get { return _mMainContent; } set { _mMainContent = value; OnPropertyChanged(); } }
  96. private FrameworkElement _mMainContent;
  97. public string DisplayName { get { return _mDisplayName; } set { _mDisplayName = value; OnPropertyChanged(); } }
  98. private string _mDisplayName;
  99. }
  100. }