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

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