using BPASmartClient.Business;
using BPA.Helper;
using BPASmartClient.Model;
using BPA.Helper;
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
{
///
/// 主界面
///
public class MainViewModel : NotifyBase
{
///
/// 网络连接状态
///
private bool _NetworkConnectState = true;
public bool NetworkConnectState
{
get
{
return _NetworkConnectState;
}
set
{
if (_NetworkConnectState == value)
return;
_NetworkConnectState = value;
OnPropertyChanged("NetworkConnectState");
}
}
///
/// 是否告警
///
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();
CurrentOrderCount = Json.Data.orderLists.Count;
}));
};
dispatcherTimer.Interval = TimeSpan.FromSeconds(1);
dispatcherTimer.Start();
}
public int CurrentOrderCount { get { return _mCurrentOrderCount; } set { _mCurrentOrderCount = value; OnPropertyChanged(); } }
private int _mCurrentOrderCount;
public bool AutoStart { get { return SystemHelper.GetInstance.IsAutoStart(); } set { SystemHelper.GetInstance.AutoStart(value); OnPropertyChanged(); } }
public bool IsVerty { get { return Json.Data.IsVerify; } set { Json.Data.IsVerify = value; OnPropertyChanged(); } }
}
public class AlarmModel : NotifyBase
{
///
/// 是否告警
///
private bool _IsCheck = false;
public bool IsCheck
{
get
{
return _IsCheck;
}
set
{
if (_IsCheck == value)
return;
_IsCheck = value;
OnPropertyChanged("IsCheck");
}
}
///
/// 告警数量
///
private int _ListNum = 0;
public int ListNum
{
get
{
return _ListNum;
}
set
{
if (_ListNum == value)
return;
_ListNum = value;
OnPropertyChanged("ListNum");
}
}
public AlarmModel()
{
}
}
}