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

147 lines
4.0 KiB

  1. using BPASmartClient.Business;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.Message;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Input;
  14. using System.Windows.Threading;
  15. namespace BPASmartClient.ViewModel
  16. {
  17. /// <summary>
  18. /// 主界面
  19. /// </summary>
  20. public class MainViewModel : ObservableObject
  21. {
  22. /// <summary>
  23. /// 网络连接状态
  24. /// </summary>
  25. private bool _NetworkConnectState = true;
  26. public bool NetworkConnectState
  27. {
  28. get
  29. {
  30. return _NetworkConnectState;
  31. }
  32. set
  33. {
  34. if (_NetworkConnectState == value)
  35. return;
  36. _NetworkConnectState = value;
  37. OnPropertyChanged("NetworkConnectState");
  38. }
  39. }
  40. //状态隐藏
  41. public Visibility VsMenuItem { get { return _vsMenuItem; } set { _vsMenuItem = value; OnPropertyChanged(); } }
  42. private Visibility _vsMenuItem;
  43. public RelayCommand LogoutCommand { get; set; }
  44. /// <summary>
  45. /// 是否告警
  46. /// </summary>
  47. public AlarmModel IsAlarm { get; set; }
  48. public System.Windows.Window window;
  49. public DispatcherTimer dispatcherTimer;
  50. #region 单一
  51. private volatile static MainViewModel _Instance;
  52. public static MainViewModel GetInstance() => _Instance ?? (_Instance = new MainViewModel());
  53. #endregion
  54. public MainViewModel()
  55. {
  56. IsAlarm = new AlarmModel();
  57. OrderStatusViewModel.Init();
  58. //设备告警日志
  59. MessageLog.GetInstance.AlarmLogNotify = new Action(() =>
  60. {
  61. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  62. {
  63. IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0;
  64. IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count;
  65. }));
  66. });
  67. dispatcherTimer = new DispatcherTimer();
  68. dispatcherTimer.Tick += delegate
  69. {
  70. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  71. {
  72. NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState();
  73. }));
  74. };
  75. dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
  76. dispatcherTimer.Start();
  77. ActionManage.GetInstance.Register(new Action(() =>
  78. {
  79. VsMenuItem = Visibility.Hidden;
  80. }),"Lonin");
  81. LogoutCommand = new RelayCommand(() =>
  82. {
  83. VsMenuItem = Visibility.Visible;
  84. });
  85. }
  86. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  87. }
  88. public class AlarmModel : ObservableObject
  89. {
  90. /// <summary>
  91. /// 是否告警
  92. /// </summary>
  93. private bool _IsCheck = false;
  94. public bool IsCheck
  95. {
  96. get
  97. {
  98. return _IsCheck;
  99. }
  100. set
  101. {
  102. if (_IsCheck == value)
  103. return;
  104. _IsCheck = value;
  105. OnPropertyChanged("IsCheck");
  106. }
  107. }
  108. /// <summary>
  109. /// 告警数量
  110. /// </summary>
  111. private int _ListNum = 0;
  112. public int ListNum
  113. {
  114. get
  115. {
  116. return _ListNum;
  117. }
  118. set
  119. {
  120. if (_ListNum == value)
  121. return;
  122. _ListNum = value;
  123. OnPropertyChanged("ListNum");
  124. }
  125. }
  126. public AlarmModel()
  127. {
  128. }
  129. }
  130. }