using BPASmartClient.Business; using BPASmartClient.Helper; using BPASmartClient.Message; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Threading; namespace BPASmartClient.ViewModel { /// <summary> /// 主界面 /// </summary> public class MainViewModel : ObservableObject { /// <summary> /// 网络连接状态 /// </summary> private bool _NetworkConnectState = true; public bool NetworkConnectState { get { return _NetworkConnectState; } set { if (_NetworkConnectState == value) return; _NetworkConnectState = value; OnPropertyChanged("NetworkConnectState"); } } /// <summary> /// 是否告警 /// </summary> public AlarmModel IsAlarm { get; set; } public System.Windows.Window window; public DispatcherTimer dispatcherTimer; #region 单一 private volatile static MainViewModel _Instance; public static MainViewModel GetInstance() => _Instance ?? (_Instance = new MainViewModel()); #endregion public MainViewModel() { IsAlarm =new AlarmModel(); OrderStatusViewModel.Init(); //设备告警日志 MessageLog.GetInstance.AlarmLogNotify = new Action(() => { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { IsAlarm.IsCheck = MessageLog.GetInstance.DPAlarmInfo.Count > 0; IsAlarm.ListNum = MessageLog.GetInstance.DPAlarmInfo.Count; })); }); dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += delegate { System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => { NetworkConnectState = UniversalHelper.GetInstance().GetNetworkState(); })); }; dispatcherTimer.Interval = TimeSpan.FromSeconds(1); dispatcherTimer.Start(); } } public class AlarmModel : ObservableObject { /// <summary> /// 是否告警 /// </summary> private bool _IsCheck = false; public bool IsCheck { get { return _IsCheck; } set { if (_IsCheck == value) return; _IsCheck = value; OnPropertyChanged("IsCheck"); } } /// <summary> /// 告警数量 /// </summary> private int _ListNum = 0; public int ListNum { get { return _ListNum; } set { if (_ListNum == value) return; _ListNum = value; OnPropertyChanged("ListNum"); } } public AlarmModel() { } } }