终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

135 строки
5.0 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. namespace BPASmartClient.CustomResource.Pages.ViewModel
  12. {
  13. public class UserLogViewModel : NotifyBase
  14. {
  15. public UserLogViewModel()
  16. {
  17. Sqlite<UserLog>.GetInstance.Save();
  18. UserLogs = MessageNotify.GetInstance.userLogs;
  19. SwitchCommand = new BPARelayCommand(() =>
  20. {
  21. if (ButContent == "历史日志")
  22. {
  23. GetHistoryUserLog();
  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<UserLog>.GetInstance.GetData();
  46. var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
  47. var result = res.Where(p => p.UserName == SearchUser && SearchUser != null && SearchUser.Length > 0).ToList();
  48. var logs = result != null && SearchUser?.Length > 0 ? result : res;
  49. if (logs != null)
  50. {
  51. HistoryUserLog.Clear();
  52. foreach (var item in logs)
  53. {
  54. HistoryUserLog.Add(item);
  55. }
  56. }
  57. }
  58. });
  59. }
  60. private void GetHistoryUserLog()
  61. {
  62. var data = Sqlite<UserLog>.GetInstance.GetData();
  63. var res = data.Where(p => p.UserName == Global.userInfo.UserName).ToList();
  64. if (res != null)
  65. {
  66. HistoryUserLog.Clear();
  67. foreach (var item in res)
  68. {
  69. int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
  70. if (day == 0)
  71. {
  72. HistoryUserLog.Add(item);
  73. }
  74. }
  75. }
  76. }
  77. public BPARelayCommand SwitchCommand { get; set; }
  78. public BPARelayCommand ControlCommand { get; set; }
  79. public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
  80. private Visibility _mCurrentDataVis = Visibility.Visible;
  81. public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
  82. private Visibility _mHistoryDataVis = Visibility.Hidden;
  83. /// <summary>
  84. /// 是否显示
  85. /// </summary>
  86. public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
  87. private Visibility _mIsVisibility = Visibility.Hidden;
  88. /// <summary>
  89. /// 文字显示
  90. /// </summary>
  91. public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
  92. private string _mButContent = "历史日志";
  93. /// <summary>
  94. /// 控制按钮文本显示
  95. /// </summary>
  96. public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
  97. private string _mControlButText = "报警复位";
  98. /// <summary>
  99. /// 开始时间
  100. /// </summary>
  101. public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
  102. private DateTime _mStartDateTime = DateTime.Now;
  103. /// <summary>
  104. /// 结束时间
  105. /// </summary>
  106. public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
  107. private DateTime _mEndDateTime = DateTime.Now;
  108. public string SearchUser { get { return _mSearchUser; } set { _mSearchUser = value; OnPropertyChanged(); } }
  109. private string _mSearchUser;
  110. public ObservableCollection<UserLog> HistoryUserLog { get; set; } = new ObservableCollection<UserLog>();
  111. public ObservableCollection<UserLog> UserLogs { get; set; }
  112. }
  113. }