using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Utilities; using System.Windows.Threading; using Prism.Commands; using Prism.Mvvm; using MECF.Framework.Common.RecipeCenter; using CyberX8_Core; using CyberX8_MainPages.PMs; using MECF.Framework.Common.OperationCenter; using System.Windows.Input; using MECF.Framework.Common.Persistent.Reservoirs; using MECF.Framework.Common.CommonData.Reservoir; using CyberX8_MainPages.Model; using System.Collections.ObjectModel; using OpenSEMI.ClientBase.Command; namespace CyberX8_MainPages.ViewModels { internal class DosingSystemViewModel : BindableBase { #region 常量 private const int MAX_REPLEN_NUM = 4; #endregion #region 内部变量 #region system /// /// rt查询key /// private List _rtDataKeys = new List(); /// /// 时钟 /// DispatcherTimer _timer; /// /// rt查询数据 /// private Dictionary _rtDataValueDic = new Dictionary(); #endregion #region Common /// /// Module /// private string _module; /// /// Operation Mode /// private string _operatingMode; /// /// 状态 /// private string _state; /// /// Reservoirs Persistent数据 /// private ReservoirsPersistentValue _reservoirsPersistent; /// /// Replens Persistent数据 /// private Dictionary _replensPersistent = new Dictionary(); /// /// 页面功能启用 /// private bool _isEnabled; /// /// AutoMode页面功能启用 /// private bool _isAutoEnabled; /// /// IsManualorAuto /// private bool _isManualorAuto; /// /// Reservoir数据 /// private StandardHotReservoirData _reservoirData; #endregion #region recipe /// /// 当前的recipe /// private ResRecipe _currentRecipe; /// /// Recipe Mode /// private string _recipeMode; /// /// Selected Recipe Node /// private RecipeNode _selectedRecipeNode; /// /// Recipe Type /// private string _recipeType; /// /// Recipe Manager /// private UiRecipeManager _uiRecipeManager = new UiRecipeManager(); #endregion #region DosingSystem /// /// Replen Datas /// private ReplenData[] _replenDatas; /// /// Replen Data Collection /// private ObservableCollection _replenDataCollection; /// /// Replen Items /// private ObservableCollection _replenEnable = new ObservableCollection(new bool[MAX_REPLEN_NUM]); /// /// Replen数量 /// private int _replenNum; /// /// Replen Persistent数据集合 /// private ObservableCollection _replensPersistentCollection; #endregion #endregion #region 属性 #region Common /// /// Module /// public string Module { get { return _module; } set { SetProperty(ref _module, value); } } /// /// Operation Mode /// public string OperatingMode { get { return _operatingMode; } set { SetProperty(ref _operatingMode, value); } } /// /// 状态 /// public string State { get { return _state; } set { SetProperty(ref _state, value); } } /// /// Reservoirs Persistent数据 /// public ReservoirsPersistentValue ReservoirsPersistent { get { return _reservoirsPersistent; } set { SetProperty(ref _reservoirsPersistent, value); } } /// /// Replen Persistent数据集合 /// public ObservableCollection ReplensPersistentCollection { get { return _replensPersistentCollection; } set { SetProperty(ref _replensPersistentCollection, value); } } /// /// 页面功能启用 /// public bool IsEnabled { get { return _isEnabled; } set { SetProperty(ref _isEnabled, value); } } /// /// AutoMode页面功能启用 /// public bool IsAutoEnabled { get { return _isAutoEnabled; } set { SetProperty(ref _isAutoEnabled, value); } } /// /// IsManualorAuto /// public bool IsManualorAuto { get { return _isManualorAuto; } set { SetProperty(ref _isManualorAuto, value); } } /// /// Reservoir数据 /// public StandardHotReservoirData ReservoirData { get { return _reservoirData; } set { SetProperty(ref _reservoirData, value); } } #endregion #region recipe /// /// Recipe内容 /// public ResRecipe CurrentRecipe { get { return _currentRecipe; } set { SetProperty(ref _currentRecipe, value); } } /// /// Selected Recipe Node /// public RecipeNode SelectedRecipeNode { get { return _selectedRecipeNode; } set { SetProperty(ref _selectedRecipeNode, value); } } /// /// Recipe Mode /// public string RecipeMode { get { return _recipeMode; } set { SetProperty(ref _recipeMode, value); } } /// /// Recipe Type /// public string RecipeType { get { return _recipeType; } set { SetProperty(ref _recipeType, value); } } #endregion #region DosingSystem /// /// Replen 数据 /// public ReplenData[] ReplenDatas { get { return _replenDatas; } set { SetProperty(ref _replenDatas, value); } } /// /// Replen Data集合 /// public ObservableCollection ReplenDataCollection { get { return _replenDataCollection; } set { SetProperty(ref _replenDataCollection, value); } } /// /// Replen Enable列表 /// public ObservableCollection ReplenEnable { get { return _replenEnable; } set { SetProperty(ref _replenEnable, value); } } /// /// Replen 数量 /// public int ReplenNum { get { return _replenNum; } set { SetProperty(ref _replenNum, value); } } #endregion #endregion #region 命令 public ICommand InitializeCommand { get; set; } public ICommand BackCommand { get; set; } #endregion /// /// 构造函数 /// public DosingSystemViewModel() { InitializeCommand = new DelegateCommand(InitializeAction); BackCommand = new DelegateCommand(BackAction); } /// /// 加载数据 /// public void LoadData(string systemName) { RecipeType = "rds"; Module = systemName; _rtDataKeys.Clear(); _rtDataKeys.Add($"{Module}.ReservoirData"); _rtDataKeys.Add($"{Module}.PersistentValue"); _rtDataKeys.Add($"{Module}.ReplenPersistentValue"); _rtDataKeys.Add($"{Module}.ReplenNum"); _rtDataKeys.Add($"{Module}.ReplenDatas"); _rtDataKeys.Add($"{Module}.DosingSystemState"); if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { ReplenNum = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReplenNum"); for (int i = 0; i < ReplenNum; i++) { ReplenEnable[i] = true; } } } if (ReplenDataCollection == null) ReplenDataCollection = new ObservableCollection(new ReplenData[ReplenNum]); if (ReplensPersistentCollection == null) ReplensPersistentCollection = new ObservableCollection(new ReplenPersistentValue[ReplenNum]); if (_timer == null) { _timer = new DispatcherTimer(); _timer.Interval = TimeSpan.FromMilliseconds(200); _timer.Tick += Timer_Tick; } _timer.Start(); } #region 命令方法 /// /// 初始化 /// /// private void InitializeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.DosingInitialize"); } /// /// 回到Reservoir主页面 /// /// private void BackAction(object param) { GlobalEvents.OnSwitchFixedChildSubItem(Module, Module); } #endregion /// /// 时钟 /// /// /// private void Timer_Tick(object sender, EventArgs e) { if (_rtDataKeys.Count != 0) { _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys); if (_rtDataValueDic != null) { State = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.DosingSystemState"); ReservoirsPersistent = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.PersistentValue"); _replensPersistent = CommonFunction.GetValue>(_rtDataValueDic, $"{Module}.ReplenPersistentValue"); _replenDatas = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReplenDatas"); if(_replenDatas != null) { for(int i = 0; i < _replenNum;i++) { ReplensPersistentCollection[i] = _replensPersistent[_replenDatas[i].ReplenName]; if (_replenDatas[i].IsAutoDosingError) { State = "Error"; } } } ReservoirData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReservoirData"); if ("Manual".Equals(ReplensPersistentCollection[0].OperatingMode)) { IsEnabled = true; IsAutoEnabled = true; IsManualorAuto = false; } else if ("Auto".Equals(ReplensPersistentCollection[0].OperatingMode)) { IsAutoEnabled = true; IsEnabled = false; IsManualorAuto = true; } else { State = "Stopped"; IsEnabled = false; IsAutoEnabled = false; IsManualorAuto = false; } if(ReplenDataCollection != null) { ReplenDataCollection.Clear(); for (int i = 0; i < ReplenNum; i++) { ReplenDataCollection.Add(_replenDatas[i]); } } } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } } }