using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System.Collections.ObjectModel; using BPASmartClient.CustomResource.Pages.Model; using System.Windows; using BPASmartClient.Helper; namespace BPASmartClient.CustomResource.Pages.ViewModel { public class RunLogViewModel : ObservableObject { public RunLogViewModel() { Sqlite.GetInstance.Save(); SwitchCommand = new RelayCommand(() => { if (ButContent == "历史日志") { GetHistoryRunLog(); 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.GetInstance.GetData(); var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList(); if (res != null) { HistoryRunLog.Clear(); foreach (var item in res) { HistoryRunLog.Add(item); } } } }); } private void GetHistoryRunLog() { var data = Sqlite.GetInstance.GetData(); if (data != null) { HistoryRunLog.Clear(); foreach (var item in data) { int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days; if (day == 0) { HistoryRunLog.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; /// /// 是否显示 /// public Visibility IsVisibility { get { return _mIsVisibility; } set { _mIsVisibility = value; OnPropertyChanged(); } } private Visibility _mIsVisibility = Visibility.Hidden; /// /// 文字显示 /// public string ButContent { get { return _mButContent; } set { _mButContent = value; OnPropertyChanged(); } } private string _mButContent = "历史日志"; /// /// 控制按钮文本显示 /// public string ControlButText { get { return _mControlButText; } set { _mControlButText = value; OnPropertyChanged(); } } private string _mControlButText = "报警复位"; /// /// 开始时间 /// public DateTime StartDateTime { get { return _mStartDateTime; } set { _mStartDateTime = value; OnPropertyChanged(); } } private DateTime _mStartDateTime = DateTime.Now; /// /// 结束时间 /// public DateTime EndDateTime { get { return _mEndDateTime; } set { _mEndDateTime = value; OnPropertyChanged(); } } private DateTime _mEndDateTime = DateTime.Now; public ObservableCollection HistoryRunLog { get; set; } = new ObservableCollection(); public ObservableCollection Log { get; set; } = MessageNotify.GetInstance.runLogs; } }