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

191 lines
7.1 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPA.Helper;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.CustomResource.Pages.Model;
  11. using BPASmartClient.Model;
  12. using System.Threading;
  13. using Microsoft.EntityFrameworkCore.Migrations;
  14. namespace BPASmartClient.CustomResource.Pages.ViewModel
  15. {
  16. public class AlarmViewModel : NotifyBase
  17. {
  18. public AlarmViewModel()
  19. {
  20. ControlCommand = new BPARelayCommand(async () =>
  21. {
  22. if (ControlButText == "报警复位") return;
  23. if (ControlButText == "开始查询")
  24. {
  25. var startTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} {StartTS.Hours}:{StartTS.Minutes}:{StartTS.Seconds}");
  26. var endTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} {EndTS.Hours}:{EndTS.Minutes}:{EndTS.Seconds}");
  27. var res = await LogHelper.GetInstance.QueryableAsync<BPA.Helper.Log.DB.Alarm>(startTime, endTime);
  28. if (res != null) HistoryAlarm.Clear();
  29. int count = 0;
  30. res?.ForEach(item =>
  31. {
  32. count++;
  33. HistoryAlarm.Add(new Alarm()
  34. {
  35. Date = item.Date,
  36. Grade = item.Grade,
  37. NumId = count,
  38. Info = item.MsgInfo,
  39. Time = item.Time,
  40. Value = item.Value
  41. });
  42. });
  43. //var lists = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.GetData();
  44. //var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
  45. //if (res != null)
  46. //{
  47. // HistoryAlarm.Clear();
  48. // foreach (var item in res)
  49. // {
  50. // HistoryAlarm.Add(item);
  51. // }
  52. //}
  53. }
  54. });
  55. SwitchCommand = new BPARelayCommand(() =>
  56. {
  57. if (ButContent == "历史报警")
  58. {
  59. GetHistoryAlarm();
  60. CurrentDataVis = Visibility.Hidden;
  61. HistoryDataVis = Visibility.Visible;
  62. IsVisibility = Visibility.Visible;
  63. ControlButText = "开始查询";
  64. ButContent = "实时报警";
  65. return;
  66. }
  67. if (ButContent == "实时报警")
  68. {
  69. HistoryDataVis = Visibility.Hidden;
  70. CurrentDataVis = Visibility.Visible;
  71. IsVisibility = Visibility.Hidden;
  72. ControlButText = "报警复位";
  73. ButContent = "历史报警";
  74. return;
  75. }
  76. });
  77. //AlarmInfos = AlarmHelper<AlarmInfo>.Alarms;
  78. }
  79. private async void GetHistoryAlarm()
  80. {
  81. var startTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} 00:00:00");
  82. var endTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} 23:59:59");
  83. var res = await LogHelper.GetInstance.QueryableAsync<BPA.Helper.Log.DB.Alarm>(startTime, endTime);
  84. if (res != null) HistoryAlarm.Clear();
  85. int count = 0;
  86. res?.ForEach(item =>
  87. {
  88. count++;
  89. HistoryAlarm.Add(new Alarm()
  90. {
  91. Date = item.Date,
  92. Grade = item.Grade,
  93. NumId = count,
  94. Info = item.MsgInfo,
  95. Time = item.Time,
  96. Value = item.Value
  97. });
  98. });
  99. //var data = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.GetData();
  100. //if (data != null)
  101. //{
  102. // HistoryAlarm.Clear();
  103. // foreach (var item in data)
  104. // {
  105. // int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  106. // if (day == 0)
  107. // {
  108. // HistoryAlarm.Add(item);
  109. // }
  110. // }
  111. //}
  112. }
  113. public BPARelayCommand SwitchCommand { get; set; }
  114. public BPARelayCommand ControlCommand { get; set; }
  115. public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
  116. private Visibility _mCurrentDataVis = Visibility.Visible;
  117. public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
  118. private Visibility _mHistoryDataVis = Visibility.Hidden;
  119. /// <summary>
  120. /// 是否显示
  121. /// </summary>
  122. public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
  123. private Visibility _mIsVisibility = Visibility.Hidden;
  124. /// <summary>
  125. /// 文字显示
  126. /// </summary>
  127. public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
  128. private string _mButContent = "历史报警";
  129. /// <summary>
  130. /// 控制按钮文本显示
  131. /// </summary>
  132. public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
  133. private string _mControlButText = "报警复位";
  134. /// <summary>
  135. /// 开始时间
  136. /// </summary>
  137. public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
  138. private DateTime _mStartDateTime = DateTime.Now;
  139. /// <summary>
  140. /// 结束时间
  141. /// </summary>
  142. public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
  143. private DateTime _mEndDateTime = DateTime.Now;
  144. /// <summary>
  145. /// 开始时间
  146. /// </summary>
  147. public TimeSpan StartTS { get { return _mStartTS; } set { _mStartTS = value; OnPropertyChanged(); } }
  148. private TimeSpan _mStartTS = new TimeSpan(0, 0, 0);
  149. /// <summary>
  150. /// 结束时间
  151. /// </summary>
  152. public TimeSpan EndTS { get { return _mEndTS; } set { _mEndTS = value; OnPropertyChanged(); } }
  153. private TimeSpan _mEndTS = new TimeSpan(23, 59, 59);
  154. public static ObservableCollection<BPASmartClient.Model.Alarm> AlarmInfos { get; set; } = new();
  155. public ObservableCollection<BPASmartClient.Model.Alarm> HistoryAlarm { get; set; } = new();
  156. }
  157. }