using MECF.Framework.Common.DataCenter; using MECF.Framework.Common.Equipment; using MECF.Framework.Common.OperationCenter; using Prism.Commands; using Prism.Mvvm; using System.Collections.ObjectModel; using System.Drawing; using System.Runtime.Serialization; using System.Threading.Tasks; using Venus_Core; using Venus_Unity; using WPF.Themes.UserControls; namespace Venus_MainPages.ViewModels { public class AutoRatioViewModel : BindableBase { private ObservableCollection m_RatioValues = new ObservableCollection(); public ObservableCollection RatioValues { get { return m_RatioValues; } set { SetProperty(ref m_RatioValues, value); } } private DelegateCommand _SetCommand; public DelegateCommand SetCommand => _SetCommand ?? (_SetCommand = new DelegateCommand(OnSet)); private DelegateCommand _LoadCommand; public DelegateCommand LoadCommand => _LoadCommand ?? (_LoadCommand = new DelegateCommand(OnLoad)); public string ModuleName; public AutoRatioViewModel() { } private void OnLoad() { string value = QueryDataClient.Instance.Service.GetConfig($"{ModuleName}.HighTemperatureHeater.AutoRatioValue").ToString(); if (string.IsNullOrEmpty(value)) { RatioValues.Add(new RatioValue(0, 300, 135F)); RatioValues.Add(new RatioValue(301, 600, 165F)); RatioValues.Add(new RatioValue(601, 630, 180F)); RatioValues.Add(new RatioValue(631, 830, 210F)); } try { var ratioValue = SerializeHelper.Instance.JsonStringToObject>(value); RatioValues = ratioValue; } catch { RatioValues.Clear(); RatioValues.Add(new RatioValue(0, 300, 135F)); RatioValues.Add(new RatioValue(301, 600, 165F)); RatioValues.Add(new RatioValue(601, 630, 180F)); RatioValues.Add(new RatioValue(631, 830, 210F)); } } private int maxValue; private async void OnSet() { maxValue = int.MinValue; foreach (var item in RatioValues) { if (item.MinValue <= maxValue) { int index = RatioValues.IndexOf(item); WPFMessageBox.ShowError($"Range{index} MaxValue {maxValue} > = Range{index + 1} MinValue {item.MinValue}"); return; } if (item.MinValue>item.MaxValue) { int index=RatioValues.IndexOf(item); WPFMessageBox.ShowError($"Range{index+1} MinValue {item.MinValue} > MaxValue {item.MaxValue}"); return; } maxValue = item.MaxValue; } var value = SerializeHelper.Instance.ObjectToJsonString(RatioValues); InvokeClient.Instance.Service.DoOperation("System.SetConfig", $"{ModuleName}.HighTemperatureHeater.AutoRatioValue", value); await Task.Delay(500); InvokeClient.Instance.Service.DoOperation($"{ModuleName}.HighTemperatureHeater.SetAutoRatio"); } } }