using Aitex.Core.UI.MVVM; using MECF.Framework.Common.CommonData.Metal; using MECF.Framework.Common.CommonData.Reservoir; using MECF.Framework.Common.CommonData.TemperatureControl; using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Device.Safety; using MECF.Framework.Common.OperationCenter; using MECF.Framework.Common.Persistent.Reservoirs; using MECF.Framework.Common.RecipeCenter; using MECF.Framework.Common.Utilities; using Prism.Mvvm; using PunkHPX8_MainPages.Model; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Threading; namespace PunkHPX8_MainPages.ViewModels { public class DMReservoirViewModel : BindableBase { #region 常量 private const string RESERVOIRS_DATA = "ReservoirsData"; private const string RESERVOIRS = "reservoirs"; private const string PERSISTENT_VALUE = "PersistentValue"; #endregion #region 内部变量 private List _rtDataKeys = new List(); private Dictionary _rtDataValueDic = new Dictionary(); DispatcherTimer _timer; private bool _isEnabled; private bool _isError; private bool _isAutoEnabled; private SafetyData _commonSafetyData; private string _module; private string _state; private ResRecipe _currentRecipe; private ReservoirsPersistentValue _reservoirsPersistent; private string _recipeType; private int _inputCAPumpSpeed; private int _inputANPumpSpeed; private int _inputReturnFlowOpenPercent; private TemperatureControllerData _temperatureControlData; private string _tcEnableStatus; private string _tcName; private ReservoirData _reservoirData; private bool _isCAHighLevel; private bool _isCALowLevel; private double _avgCaLevel; private ObservableCollection _recipeNodes; private string _currentRecipeFileName; /// /// 是否配置Exhaust /// private bool _isEvaporatorConfig; /// /// 是否正在手动注水 /// private bool _isManualReplen; /// /// 手动注水时长(秒) /// private int _manualFillSeconds; /// /// DIValveMaxOnTime /// private double _diValveMaxOnTime; /// /// 是否补水异常 /// private bool _isDIReplenFault; /// /// CellModuleName集合 /// private ObservableCollection _cellModuleNameCollection = new ObservableCollection(); /// /// Cell A面Flow集合 /// private ObservableCollection _cellModuleNameFlowCollection = new ObservableCollection(); /// /// MetalData /// private ObservableCollection _metalDatas = new ObservableCollection(); /// /// MetalData的CellFlow集合 /// private ObservableCollection _metalCellFlowDatas = new ObservableCollection(); /// /// Meatl UI数据 /// private ObservableCollection _reservoirsUIDatas = new ObservableCollection(); #endregion #region 属性 public string Module { get { return _module; } set { SetProperty(ref _module, value); } } public bool IsEnabled { get { return _isEnabled; } set { SetProperty(ref _isEnabled, value); } } public bool IsError { get { return _isError; } set { SetProperty(ref _isError, value); } } public bool IsAutoEnabled { get { return _isAutoEnabled; } set { SetProperty(ref _isAutoEnabled, value); } } public SafetyData CommonSafetyData { get { return _commonSafetyData; } set { SetProperty(ref _commonSafetyData, value); } } public string State { get { return _state; } set { SetProperty(ref _state, value); } } public ResRecipe CurrentRecipe { get { return _currentRecipe; } set { SetProperty(ref _currentRecipe, value); } } public ReservoirsPersistentValue ReservoirsPersistent { get { return _reservoirsPersistent; } set { SetProperty(ref _reservoirsPersistent, value); } } public string RecipeType { get { return _recipeType; } set { SetProperty(ref _recipeType, value); } } public int InputCAPumpSpeed { get { return _inputCAPumpSpeed; } set { SetProperty(ref _inputCAPumpSpeed, value); } } public int InputANPumpSpeed { get { return _inputANPumpSpeed; } set { SetProperty(ref _inputANPumpSpeed, value); } } public int InputRetrunFlowOpenPercent { get { return _inputReturnFlowOpenPercent; } set { SetProperty(ref _inputReturnFlowOpenPercent, value); } } public TemperatureControllerData TemperatureControlData { get { return _temperatureControlData; } set { SetProperty(ref _temperatureControlData, value); } } public string TCEnableStatus { get { return _tcEnableStatus; } set { SetProperty(ref _tcEnableStatus, value); } } public ReservoirData ReservoirData { get { return _reservoirData; } set { SetProperty(ref _reservoirData, value); } } public bool IsCAHighLevel { get { return _isCAHighLevel; } set { SetProperty(ref _isCAHighLevel, value); } } public bool IsCALowLevel { get { return _isCALowLevel; } set { SetProperty(ref _isCALowLevel, value); } } /// /// Ca Level采样周期内平均值 /// public double AvgCALevel { get { return _avgCaLevel; } set { SetProperty(ref _avgCaLevel, value); } } /// /// 单次注水最大时长 /// public double DIValveMaxOnTime { get { return _diValveMaxOnTime; } set { SetProperty(ref _diValveMaxOnTime, value); } } /// /// 手动注水时长 /// public int ManualFillSeconds { get { return _manualFillSeconds; } set { SetProperty(ref _manualFillSeconds, value); } } /// /// 正在手动注水 /// public bool IsManualReplen { get { return _isManualReplen; } set { SetProperty(ref _isManualReplen, value); } } /// /// 是否补水异常 /// public bool IsDIReplenFault { get { return _isDIReplenFault; } set { SetProperty(ref _isDIReplenFault, value); } } #endregion #region 指令 public ICommand InitializeCommand { get; set; } public ICommand CAPumpSpeedSetCommand { get; set; } public ICommand ANPumpSpeedSetCommand { get; set; } public ICommand ReturnFlowOpenPercentSetCommand { get; set; } public ICommand ResetTotalCommand { get; set; } public ICommand ManualDireplenCommand { get; set; } #endregion public DMReservoirViewModel() { InitializeCommand = new DelegateCommand(InitializeAction); CAPumpSpeedSetCommand = new DelegateCommand(CAPumpSpeedSetAction); ANPumpSpeedSetCommand = new DelegateCommand(ANPumpSpeedSetAction); ReturnFlowOpenPercentSetCommand = new DelegateCommand(ReturnFlowOpenPercentSetAction); ResetTotalCommand = new DelegateCommand(ResetTotalAction); ManualDireplenCommand = new DelegateCommand(ManualDireplenAction); } #region 命令方法 /// /// 初始化 /// /// private void InitializeAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.InitializeAll"); } /// /// 设置CA pump泵速 /// /// private void CAPumpSpeedSetAction(object param) { if (InputCAPumpSpeed>100 || InputCAPumpSpeed < 0) { MessageBox.Show($"Input CAPumpSpeed value in 0~100", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } InvokeClient.Instance.Service.DoOperation($"{Module}.CAPumpSpeed",InputCAPumpSpeed); } /// /// 设置AN pump泵速 /// /// private void ANPumpSpeedSetAction(object param) { if (InputANPumpSpeed > 100 || InputANPumpSpeed < 0) { MessageBox.Show($"Input ANPumpSpeed value in 0~100", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } InvokeClient.Instance.Service.DoOperation($"{Module}.ANPumpSpeed", InputANPumpSpeed); } /// /// 设置return flow valve开闭的程度 /// /// private void ReturnFlowOpenPercentSetAction(object param) { if (InputRetrunFlowOpenPercent > 100 || InputRetrunFlowOpenPercent < 0) { MessageBox.Show($"Input RetrunFlowOpenPercent value in 0~100", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } InvokeClient.Instance.Service.DoOperation($"{Module}.ReturnValvePercent", InputRetrunFlowOpenPercent); } /// /// 重置TotalTime /// private void ResetTotalAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.ResetTotalTime"); } /// /// 手动注水 /// /// private void ManualDireplenAction(object param) { InvokeClient.Instance.Service.DoOperation($"{Module}.ManualCADiReplen", ManualFillSeconds); } #endregion public void LoadData(string systemName) { RecipeType = "res"; Module = systemName; _rtDataKeys.Clear(); _rtDataKeys.Add($"{Module}.{PERSISTENT_VALUE}"); _rtDataKeys.Add($"{Module}.CurrentRecipe"); _rtDataKeys.Add($"{Module}.FsmState"); _rtDataKeys.Add($"Safety.SafetyData"); _rtDataKeys.Add($"{Module}.ReservoirData"); _rtDataKeys.Add($"{Module}.IsCAHighLevel"); _rtDataKeys.Add($"{Module}.IsCALowLevel"); _rtDataKeys.Add($"{Module}.TemperatureControllerData"); _rtDataKeys.Add($"{Module}.DIValveMaxOnTime"); _rtDataKeys.Add($"{Module}.IsManualCAReplen"); _rtDataKeys.Add($"{Module}.IsDIReplenPerfillTimeOut"); _rtDataKeys.Add($"{Module}.IsDIReplenMaxTimeOut"); _rtDataKeys.Add($"{Module}.AvgCALevel"); 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) { State = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.FsmState"); ReservoirData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.ReservoirData"); CommonSafetyData = CommonFunction.GetValue(_rtDataValueDic, $"Safety.SafetyData"); ReservoirsPersistent = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.{PERSISTENT_VALUE}"); if (ReservoirsPersistent!= null && "Manual".Equals(ReservoirsPersistent.OperatingMode)) { IsEnabled = true; IsAutoEnabled = true; } else if (ReservoirsPersistent != null && "Auto".Equals(ReservoirsPersistent.OperatingMode)) { IsAutoEnabled = true; IsEnabled = false; } else { State = "Stopped"; IsEnabled = false; IsAutoEnabled = false; } CurrentRecipe = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.CurrentRecipe"); TemperatureControlData = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.TemperatureControllerData"); TCEnableStatus = TemperatureControlData.ControlOperationModel == 0 ? "Disable" : "Enable"; _tcName = TemperatureControlData.Name; IsCAHighLevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsCAHighLevel"); IsCALowLevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsCALowLevel"); AvgCALevel = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.AvgCALevel"); DIValveMaxOnTime = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.DIValveMaxOnTime"); IsManualReplen = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsManualCAReplen"); IsDIReplenFault = CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsDIReplenPerfillTimeOut") || CommonFunction.GetValue(_rtDataValueDic, $"{Module}.IsDIReplenMaxTimeOut"); } } } /// /// 隐藏 /// public void Hide() { if (_timer != null) { _timer.Stop(); } } } }