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

138 regels
3.9 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. CurrentOrderCount = Json<KeepDataBase>.Data.orderLists.Count;
  71. }));
  72. };
  73. dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
  74. dispatcherTimer.Start();
  75. }
  76. public int CurrentOrderCount { get { return _mCurrentOrderCount; } set { _mCurrentOrderCount = value; OnPropertyChanged(); } }
  77. private int _mCurrentOrderCount;
  78. public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
  79. public bool IsVerty { get { return Json<KeepDataBase>.Data.IsVerify; } set { Json<KeepDataBase>.Data.IsVerify = value; OnPropertyChanged(); } }
  80. }
  81. public class AlarmModel : ObservableObject
  82. {
  83. /// <summary>
  84. /// 是否告警
  85. /// </summary>
  86. private bool _IsCheck = false;
  87. public bool IsCheck
  88. {
  89. get
  90. {
  91. return _IsCheck;
  92. }
  93. set
  94. {
  95. if (_IsCheck == value)
  96. return;
  97. _IsCheck = value;
  98. OnPropertyChanged("IsCheck");
  99. }
  100. }
  101. /// <summary>
  102. /// 告警数量
  103. /// </summary>
  104. private int _ListNum = 0;
  105. public int ListNum
  106. {
  107. get
  108. {
  109. return _ListNum;
  110. }
  111. set
  112. {
  113. if (_ListNum == value)
  114. return;
  115. _ListNum = value;
  116. OnPropertyChanged("ListNum");
  117. }
  118. }
  119. public AlarmModel()
  120. {
  121. }
  122. }
  123. }