终端一体化运控平台
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 lines
4.9 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 Microsoft.Toolkit.Mvvm.Input;
  8. using System.Collections.ObjectModel;
  9. using BPASmartClient.CustomResource.Pages.Model;
  10. using System.Windows;
  11. using BPASmartClient.Helper;
  12. using System.Diagnostics;
  13. namespace BPASmartClient.CustomResource.Pages.ViewModel
  14. {
  15. public class RunLogViewModel : ObservableObject
  16. {
  17. public RunLogViewModel()
  18. {
  19. Sqlite<RunLog>.GetInstance.Save();
  20. SwitchCommand = new RelayCommand(() =>
  21. {
  22. if (ButContent == "历史日志")
  23. {
  24. GetHistoryRunLog();
  25. CurrentDataVis = Visibility.Hidden;
  26. HistoryDataVis = Visibility.Visible;
  27. IsVisibility = Visibility.Visible;
  28. ControlButText = "开始查询";
  29. ButContent = "实时日志";
  30. return;
  31. }
  32. if (ButContent == "实时日志")
  33. {
  34. HistoryDataVis = Visibility.Hidden;
  35. CurrentDataVis = Visibility.Visible;
  36. IsVisibility = Visibility.Hidden;
  37. ButContent = "历史日志";
  38. return;
  39. }
  40. });
  41. ControlCommand = new RelayCommand(() =>
  42. {
  43. if (ControlButText == "报警复位") return;
  44. if (ControlButText == "开始查询")
  45. {
  46. var lists = Sqlite<RunLog>.GetInstance.GetData();
  47. var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
  48. if (res != null)
  49. {
  50. HistoryRunLog.Clear();
  51. foreach (var item in res)
  52. {
  53. HistoryRunLog.Add(item);
  54. }
  55. }
  56. }
  57. });
  58. }
  59. private void GetHistoryRunLog()
  60. {
  61. var data = Sqlite<RunLog>.GetInstance.GetData();
  62. if (data != null)
  63. {
  64. var res = data.Where(p => p.Date == DateTime.Now.ToString("yyyy-MM-dd")).ToList();
  65. if (res != null)
  66. {
  67. HistoryRunLog.Clear();
  68. res.ForEach(item =>
  69. {
  70. HistoryRunLog.Add(item);
  71. });
  72. }
  73. //foreach (var item in data)
  74. //{
  75. // int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  76. // if (day == 0)
  77. // {
  78. // HistoryRunLog.Add(item);
  79. // }
  80. //}
  81. }
  82. }
  83. public RelayCommand SwitchCommand { get; set; }
  84. public RelayCommand ControlCommand { get; set; }
  85. public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
  86. private Visibility _mCurrentDataVis = Visibility.Visible;
  87. public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
  88. private Visibility _mHistoryDataVis = Visibility.Hidden;
  89. /// <summary>
  90. /// 是否显示
  91. /// </summary>
  92. public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
  93. private Visibility _mIsVisibility = Visibility.Hidden;
  94. /// <summary>
  95. /// 文字显示
  96. /// </summary>
  97. public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
  98. private string _mButContent = "历史日志";
  99. /// <summary>
  100. /// 控制按钮文本显示
  101. /// </summary>
  102. public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
  103. private string _mControlButText = "报警复位";
  104. /// <summary>
  105. /// 开始时间
  106. /// </summary>
  107. public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
  108. private DateTime _mStartDateTime = DateTime.Now;
  109. /// <summary>
  110. /// 结束时间
  111. /// </summary>
  112. public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
  113. private DateTime _mEndDateTime = DateTime.Now;
  114. public ObservableCollection<RunLog> HistoryRunLog { get; set; } = new ObservableCollection<RunLog>();
  115. public ObservableCollection<RunLog> Log { get; set; } = MessageNotify.GetInstance.runLogs;
  116. }
  117. }