终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

138 linhas
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 BPA.Helper;
  7. using System.Collections.ObjectModel;
  8. using BPASmartClient.CustomResource.Pages.Model;
  9. using System.Windows;
  10. using BPA.Helper;
  11. using System.Diagnostics;
  12. namespace BPASmartClient.CustomResource.Pages.ViewModel
  13. {
  14. public class RunLogViewModel : NotifyBase
  15. {
  16. public RunLogViewModel()
  17. {
  18. Sqlite<RunLog>.GetInstance.Save();
  19. SwitchCommand = new BPARelayCommand(() =>
  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 BPARelayCommand(() =>
  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. var res = data.Where(p => p.Date == DateTime.Now.ToString("yyyy-MM-dd")).ToList();
  64. if (res != null)
  65. {
  66. HistoryRunLog.Clear();
  67. res.ForEach(item =>
  68. {
  69. HistoryRunLog.Add(item);
  70. });
  71. }
  72. //foreach (var item in data)
  73. //{
  74. // int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  75. // if (day == 0)
  76. // {
  77. // HistoryRunLog.Add(item);
  78. // }
  79. //}
  80. }
  81. }
  82. public BPARelayCommand SwitchCommand { get; set; }
  83. public BPARelayCommand 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 ObservableCollection<RunLog> HistoryRunLog { get; set; } = new ObservableCollection<RunLog>();
  114. public ObservableCollection<RunLog> Log { get; set; } = MessageNotify.GetInstance.runLogs;
  115. }
  116. }