终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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