|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using System.Collections.ObjectModel;
- using BPASmartClient.CustomResource.Pages.Model;
- using System.Windows;
- using Microsoft.Toolkit.Mvvm.Input;
- using BPASmartClient.Helper;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class UserLogViewModel : ObservableObject
- {
- public UserLogViewModel()
- {
- Sqlite<UserLog>.GetInstance.Save();
- UserLogs = MessageNotify.GetInstance.userLogs;
- SwitchCommand = new RelayCommand(() =>
- {
- if (ButContent == "历史日志")
- {
- GetHistoryUserLog();
- CurrentDataVis = Visibility.Hidden;
- HistoryDataVis = Visibility.Visible;
- IsVisibility = Visibility.Visible;
- ControlButText = "开始查询";
- ButContent = "实时日志";
- return;
- }
-
- if (ButContent == "实时日志")
- {
- HistoryDataVis = Visibility.Hidden;
- CurrentDataVis = Visibility.Visible;
- IsVisibility = Visibility.Hidden;
- ButContent = "历史日志";
- return;
- }
-
- });
-
- ControlCommand = new RelayCommand(() =>
- {
- if (ControlButText == "报警复位") return;
- if (ControlButText == "开始查询")
- {
- var lists = Sqlite<UserLog>.GetInstance.GetData();
- var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
- var result = res.Where(p => p.UserName == SearchUser && SearchUser != null && SearchUser.Length > 0).ToList();
- var logs = result != null && SearchUser?.Length > 0 ? result : res;
- if (logs != null)
- {
- HistoryUserLog.Clear();
- foreach (var item in logs)
- {
- HistoryUserLog.Add(item);
- }
- }
- }
- });
- }
-
- private void GetHistoryUserLog()
- {
- var data = Sqlite<UserLog>.GetInstance.GetData();
- var res = data.Where(p => p.UserName == Global.userInfo.UserName).ToList();
- if (res != null)
- {
- HistoryUserLog.Clear();
- foreach (var item in res)
- {
- int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
- if (day == 0)
- {
- HistoryUserLog.Add(item);
- }
- }
- }
- }
-
- public RelayCommand SwitchCommand { get; set; }
-
- public RelayCommand ControlCommand { get; set; }
-
- public Visibility CurrentDataVis { get { return _mCurrentDataVis; } set { _mCurrentDataVis = value; OnPropertyChanged(); } }
- private Visibility _mCurrentDataVis = Visibility.Visible;
-
- public Visibility HistoryDataVis { get { return _mHistoryDataVis; } set { _mHistoryDataVis = value; OnPropertyChanged(); } }
- private Visibility _mHistoryDataVis = Visibility.Hidden;
-
- /// <summary>
- /// 是否显示
- /// </summary>
- public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } }
- private Visibility _mIsVisibility = Visibility.Hidden;
-
- /// <summary>
- /// 文字显示
- /// </summary>
- public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } }
- private string _mButContent = "历史日志";
-
- /// <summary>
- /// 控制按钮文本显示
- /// </summary>
- public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } }
- private string _mControlButText = "报警复位";
-
- /// <summary>
- /// 开始时间
- /// </summary>
- public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } }
- private DateTime _mStartDateTime = DateTime.Now;
-
- /// <summary>
- /// 结束时间
- /// </summary>
- public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } }
- private DateTime _mEndDateTime = DateTime.Now;
-
-
- public string SearchUser { get { return _mSearchUser; } set { _mSearchUser = value; OnPropertyChanged(); } }
- private string _mSearchUser;
-
-
- public ObservableCollection<UserLog> HistoryUserLog { get; set; } = new ObservableCollection<UserLog>();
-
- public ObservableCollection<UserLog> UserLogs { get; set; }
-
- }
- }
|