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

140 lines
4.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.CustomResource.Pages.Model;
  13. using BPASmartClient.Model;
  14. using Google.Protobuf.WellKnownTypes;
  15. using System.Threading;
  16. namespace BPASmartClient.CustomResource.Pages.ViewModel
  17. {
  18. public class AlarmViewModel : ObservableObject
  19. {
  20. public AlarmViewModel()
  21. {
  22. ControlCommand = new RelayCommand(() =>
  23. {
  24. if (ControlButText == "报警复位")
  25. {
  26. return;
  27. }
  28. if (ControlButText == "开始查询")
  29. {
  30. var lists = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.GetData();
  31. var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
  32. if (res != null)
  33. {
  34. HistoryAlarm.Clear();
  35. foreach (var item in res)
  36. {
  37. HistoryAlarm.Add(item);
  38. }
  39. }
  40. }
  41. });
  42. SwitchCommand = new RelayCommand(() =>
  43. {
  44. if (ButContent == "历史报警")
  45. {
  46. GetHistoryAlarm();
  47. CurrentDataVis = Visibility.Hidden;
  48. HistoryDataVis = Visibility.Visible;
  49. IsVisibility = Visibility.Visible;
  50. ControlButText = "开始查询";
  51. ButContent = "实时报警";
  52. return;
  53. }
  54. if (ButContent == "实时报警")
  55. {
  56. HistoryDataVis = Visibility.Hidden;
  57. CurrentDataVis = Visibility.Visible;
  58. IsVisibility = Visibility.Hidden;
  59. ControlButText = "报警复位";
  60. ButContent = "历史报警";
  61. return;
  62. }
  63. });
  64. //AlarmInfos = AlarmHelper<AlarmInfo>.Alarms;
  65. }
  66. private void GetHistoryAlarm()
  67. {
  68. var data = Sqlite<Alarm>.GetInstance.GetData();
  69. if (data != null)
  70. {
  71. HistoryAlarm.Clear();
  72. foreach (var item in data)
  73. {
  74. int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  75. if (day == 0)
  76. {
  77. HistoryAlarm.Add(item);
  78. }
  79. }
  80. }
  81. }
  82. public RelayCommand SwitchCommand { get; set; }
  83. public RelayCommand ControlCommand { get; set; }
  84. public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
  85. private Visibility _mCurrentDataVis = Visibility.Visible;
  86. public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
  87. private Visibility _mHistoryDataVis = Visibility.Hidden;
  88. /// <summary>
  89. /// 是否显示
  90. /// </summary>
  91. public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
  92. private Visibility _mIsVisibility = Visibility.Hidden;
  93. /// <summary>
  94. /// 文字显示
  95. /// </summary>
  96. public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
  97. private string _mButContent = "历史报警";
  98. /// <summary>
  99. /// 控制按钮文本显示
  100. /// </summary>
  101. public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
  102. private string _mControlButText = "报警复位";
  103. /// <summary>
  104. /// 开始时间
  105. /// </summary>
  106. public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
  107. private DateTime _mStartDateTime = DateTime.Now;
  108. /// <summary>
  109. /// 结束时间
  110. /// </summary>
  111. public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
  112. private DateTime _mEndDateTime = DateTime.Now;
  113. public static ObservableCollection<Alarm> AlarmInfos { get; set; }
  114. public ObservableCollection<Alarm> HistoryAlarm { get; set; } = new ObservableCollection<Alarm>();
  115. }
  116. }