using Aitex.Core.UI.MVVM; using MECF.Framework.Common.CommonData.Vpw; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.Persistent.VpwCell; using MECF.Framework.Common.Persistent.VpwMain; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using System.Windows.Threading; namespace PunkHPX8_MainPages.ViewModels { public class VPWCellViewModel:BindableBase { #region 常量 private const string COMMONDATA = "CommonData"; private const string VPW = "vpw"; private const string PERSISTENT_VALUE = "PersistentValue"; #endregion #region 内部变量 #region Common /// /// 模块名称 /// private string _module; /// /// StateMachine /// private string _stateMachine; /// /// Status /// private string _status; /// /// 数据 /// private VpwCellCommonData _vpwCellCommonData; /// /// VPW Main数据 /// private VpwMainCommonData _vpwMainCommonData; /// /// Threshold /// private VpwCellPersistentValue _vpwCellPersistent; /// /// 是否是Manual模式 /// private bool _isManualOperationMode; #endregion #region VPW recipe /// /// RecipeModuleName /// private string _recipeModuleName; /// /// RecipeType /// private string _recipeType; /// /// AchievedRunRecipeCycle /// private int _achievedRunRecipeCycle; /// /// 当前Recipe /// private string _currentRecipe; /// /// RecipeContent /// private string _recipeContent; /// /// TimeRemaining /// private int _timeRemaining; /// /// OfTotalTime /// private int _totalTime; /// /// OperatingMode /// private string _operatingMode; /// /// State Machine /// private string _state; /// /// RecipeMode /// private string _recipeMode; #endregion #region UI /// /// IsErrorState 用于腔体变红 /// private bool _isErrorState; /// /// 页面功能启用 /// private bool _isEnabled; /// /// AutoMode页面功能启用 /// private bool _isAutoEnabled; #endregion #endregion #region 系统数据 /// /// 定时器 /// DispatcherTimer _timer; /// /// 查询后台数据集合 /// private List _rtDataKeys = new List(); /// /// rt查询key数值字典 /// private Dictionary _rtDataValueDic = new Dictionary(); #endregion #region 属性 #region Common /// /// 模块名称 /// public string Module { get { return _module; } set { SetProperty(ref _module, value); } } /// /// StateMachine /// public string StateMachine { get { return _stateMachine; } set { SetProperty(ref _stateMachine, value); } } /// /// Status /// public string Status { get { return _status; } set { SetProperty(ref _status, value); } } /// /// Commondata /// public VpwMainCommonData VpwMainCommonData { get { return _vpwMainCommonData; } set { SetProperty(ref _vpwMainCommonData, value); } } /// /// Commondata /// public VpwCellCommonData VpwCellCommonData { get { return _vpwCellCommonData; } set { SetProperty(ref _vpwCellCommonData, value); } } /// /// Persistent /// public VpwCellPersistentValue VpwCellPersistent { get { return _vpwCellPersistent; } set { SetProperty(ref _vpwCellPersistent, value); } } /// /// 是否是Manual模式 /// public bool IsManualOperationMode { get { return _isManualOperationMode; } set { SetProperty(ref _isManualOperationMode, value); } } #endregion #region VPW recipe /// /// RecipeModuleName /// public string RecipeModuleName { get { return _recipeModuleName; } set { SetProperty(ref _recipeModuleName, value); } } /// /// RecipeType /// public string RecipeType { get { return _recipeType; } set { SetProperty(ref _recipeType, value); } } public int AchievedRunRecipeCycle { get { return _achievedRunRecipeCycle; } set { SetProperty(ref _achievedRunRecipeCycle, value); } } /// /// 当前运行的Recipe /// public string CurrentRecipe { get { return _currentRecipe; } set { SetProperty(ref _currentRecipe, value); } } /// /// RecipeContent /// public string RecipeContent { get { return _recipeContent; } set { SetProperty(ref _recipeContent, value); } } /// /// TimeRemaining /// public int TimeRemaining { get { return _timeRemaining; } set { SetProperty(ref _timeRemaining, value); } } /// /// TotalTime /// public int TotalTime { get { return _totalTime; } set { SetProperty(ref _totalTime, value); } } /// /// OperatingMode /// public string OperatingMode { get { return _operatingMode; } set { SetProperty(ref _operatingMode, value); } } /// /// State /// public string State { get { return _state; } set { SetProperty(ref _state, value); } } /// /// RecipeMode /// public string RecipeMode { get { return _recipeMode; } set { SetProperty(ref _recipeMode, value); } } #endregion #region UI /// /// IsErrorState /// public bool IsErrorState { get { return _isErrorState; } set { SetProperty(ref _isErrorState, value); } } /// /// 页面功能启用 /// public bool IsEnabled { get { return _isEnabled; } set { SetProperty(ref _isEnabled, value); } } /// /// AutoMode页面功能启用 /// public bool IsAutoEnabled { get { return _isAutoEnabled; } set { SetProperty(ref _isAutoEnabled, value); } } #endregion #endregion #region Command指令 public ICommand InitializeCommand { get; set; } public ICommand HomeCommand { get; set; } #endregion public VPWCellViewModel() { InitializeCommand = new DelegateCommand(InitializeAction); HomeCommand = new DelegateCommand(HomeAction); } /// /// 加载数据 /// public void LoadData(string systemName) { Module = systemName; _rtDataKeys.Clear(); List lst = new List(); _rtDataValueDic = QueryDataClient.Instance.Service.PollData(lst); _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}"); _rtDataKeys.Add($"{Module}.{COMMONDATA}"); _rtDataKeys.Add($"{Module}.MachineState"); _rtDataKeys.Add($"VPWMain1.{COMMONDATA}"); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(200); _timer.Tick += Timer_Tick; } _timer.Start(); } /// /// 定时器执行 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { VpwCellCommonData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{COMMONDATA}"); VpwMainCommonData = CommonFunction.GetValue(_rtDataValueDic, $"VPWMain1.{COMMONDATA}"); VpwCellPersistent = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}"); } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } #region 指令Action /// /// Initialize Action /// /// private void InitializeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll"); } /// /// Home Action /// /// private void HomeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.Home"); } #endregion } }