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

AlarmViewModel.cs 4.7 KiB

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