|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BPA.Helper;
- using System.Collections.Concurrent;
- using System.Collections.ObjectModel;
- using System.Windows;
-
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Model;
- using System.Threading;
- using Microsoft.EntityFrameworkCore.Migrations;
-
- namespace BPASmartClient.CustomResource.Pages.ViewModel
- {
- public class AlarmViewModel : NotifyBase
- {
- public AlarmViewModel()
- {
- ControlCommand = new BPARelayCommand(async () =>
- {
- if (ControlButText == "报警复位") return;
- if (ControlButText == "开始查询")
- {
- var startTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} {StartTS.Hours}:{StartTS.Minutes}:{StartTS.Seconds}");
- var endTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} {EndTS.Hours}:{EndTS.Minutes}:{EndTS.Seconds}");
- var res = await LogHelper.GetInstance.QueryableAsync<BPA.Helper.Log.DB.Alarm>(startTime, endTime);
- if (res != null) HistoryAlarm.Clear();
- int count = 0;
- res?.ForEach(item =>
- {
- count++;
- HistoryAlarm.Add(new Alarm()
- {
- Date = item.Date,
- Grade = item.Grade,
- NumId = count,
- Info = item.MsgInfo,
- Time = item.Time,
- Value = item.Value
- });
- });
-
-
- //var lists = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.GetData();
- //var res = lists.Where(p => Convert.ToDateTime(p.Date) >= StartDateTime && Convert.ToDateTime(p.Date) <= EndDateTime).ToList();
- //if (res != null)
- //{
- // HistoryAlarm.Clear();
- // foreach (var item in res)
- // {
- // HistoryAlarm.Add(item);
- // }
- //}
- }
-
- });
-
- SwitchCommand = new BPARelayCommand(() =>
- {
- if (ButContent == "历史报警")
- {
- GetHistoryAlarm();
- CurrentDataVis = Visibility.Hidden;
- HistoryDataVis = Visibility.Visible;
- IsVisibility = Visibility.Visible;
- ControlButText = "开始查询";
- ButContent = "实时报警";
- return;
- }
-
- if (ButContent == "实时报警")
- {
- HistoryDataVis = Visibility.Hidden;
- CurrentDataVis = Visibility.Visible;
- IsVisibility = Visibility.Hidden;
- ControlButText = "报警复位";
- ButContent = "历史报警";
- return;
- }
- });
-
- //AlarmInfos = AlarmHelper<AlarmInfo>.Alarms;
-
- }
-
- private async void GetHistoryAlarm()
- {
- var startTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} 00:00:00");
- var endTime = Convert.ToDateTime($"{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day} 23:59:59");
- var res = await LogHelper.GetInstance.QueryableAsync<BPA.Helper.Log.DB.Alarm>(startTime, endTime);
- if (res != null) HistoryAlarm.Clear();
- int count = 0;
- res?.ForEach(item =>
- {
- count++;
- HistoryAlarm.Add(new Alarm()
- {
- Date = item.Date,
- Grade = item.Grade,
- NumId = count,
- Info = item.MsgInfo,
- Time = item.Time,
- Value = item.Value
- });
- });
-
-
-
-
- //var data = Sqlite<BPASmartClient.Model.Alarm>.GetInstance.GetData();
- //if (data != null)
- //{
- // HistoryAlarm.Clear();
- // foreach (var item in data)
- // {
- // int day = DateTime.Now.Subtract(Convert.ToDateTime(item.Date)).Days;
- // if (day == 0)
- // {
- // HistoryAlarm.Add(item);
- // }
- // }
- //}
- }
-
- public BPARelayCommand SwitchCommand { get; set; }
-
- public BPARelayCommand 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;
-
- /// <summary>
- /// 开始时间
- /// </summary>
- public TimeSpan StartTS { get { return _mStartTS; } set { _mStartTS = value; OnPropertyChanged(); } }
- private TimeSpan _mStartTS = new TimeSpan(0, 0, 0);
-
- /// <summary>
- /// 结束时间
- /// </summary>
-
- public TimeSpan EndTS { get { return _mEndTS; } set { _mEndTS = value; OnPropertyChanged(); } }
- private TimeSpan _mEndTS = new TimeSpan(23, 59, 59);
-
-
- public static ObservableCollection<BPASmartClient.Model.Alarm> AlarmInfos { get; set; } = new();
- public ObservableCollection<BPASmartClient.Model.Alarm> HistoryAlarm { get; set; } = new();
-
- }
- }
|