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

135 lines
3.8 KiB

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