终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

131 linhas
3.5 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. /// <summary>
  41. /// 是否告警
  42. /// </summary>
  43. public AlarmModel IsAlarm { get; set; }
  44. public System.Windows.Window window;
  45. public DispatcherTimer dispatcherTimer;
  46. #region 单一
  47. private volatile static MainViewModel _Instance;
  48. public static MainViewModel GetInstance() => _Instance ?? (_Instance = new MainViewModel());
  49. #endregion
  50. public MainViewModel()
  51. {
  52. IsAlarm = new AlarmModel();
  53. OrderStatusViewModel.Init();
  54. //设备告警日志
  55. MessageLog.GetInstance.AlarmLogNotify = new Action(() =>
  56. {
  57. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  58. {
  59. IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0;
  60. IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count;
  61. }));
  62. });
  63. dispatcherTimer = new DispatcherTimer();
  64. dispatcherTimer.Tick += delegate
  65. {
  66. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  67. {
  68. NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState();
  69. }));
  70. };
  71. dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
  72. dispatcherTimer.Start();
  73. }
  74. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  75. }
  76. public class AlarmModel : ObservableObject
  77. {
  78. /// <summary>
  79. /// 是否告警
  80. /// </summary>
  81. private bool _IsCheck = false;
  82. public bool IsCheck
  83. {
  84. get
  85. {
  86. return _IsCheck;
  87. }
  88. set
  89. {
  90. if (_IsCheck == value)
  91. return;
  92. _IsCheck = value;
  93. OnPropertyChanged("IsCheck");
  94. }
  95. }
  96. /// <summary>
  97. /// 告警数量
  98. /// </summary>
  99. private int _ListNum = 0;
  100. public int ListNum
  101. {
  102. get
  103. {
  104. return _ListNum;
  105. }
  106. set
  107. {
  108. if (_ListNum == value)
  109. return;
  110. _ListNum = value;
  111. OnPropertyChanged("ListNum");
  112. }
  113. }
  114. public AlarmModel()
  115. {
  116. }
  117. }
  118. }