using BPA.Helper; using BPASmartClient.Model; using BPASmartClient.MorkM.Model; using BPA.Helper; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.MorkM.ViewModel { internal class SimOrderConfitViewModel: NotifyBase { bool IsEdit = false; SimOrderVisibleData simOrderVisibleData; string DeviceType = string.Empty; public SimOrderConfitViewModel() { // DeviceType = GeneralConfig.StartDevice; ActionManage.GetInstance.Register(new Action((o) => { if (o != null) { if (o is SimOrderVisibleData sim) { Name = sim.Text; Max = sim.MaxValue; Min = sim.MinValue; IsEdit = true; simOrderVisibleData = sim; } } }), "SendSimData"); ConfirmCommand = new BPARelayCommand(() => { //if (!Json.Data.simOrderConfig.ContainsKey(DeviceType)) //{ // Json.Data.simOrderConfig.TryAdd(DeviceType, new ObservableCollection()); //} if (!IsEdit) { Json.Data.simOrderConfig.Add(new SimOrderVisibleData() { IsEnable = true, IsSelected = true, Text = Name, Loc = Min, MaxValue = Max, MinValue = Min, }); } else { int index = Array.FindIndex(Json.Data.simOrderConfig.ToArray(), p => p.Text == simOrderVisibleData.Text); if (index >= 0 && index < Json.Data.simOrderConfig.Count()) { Json.Data.simOrderConfig.ElementAt(index).Text = Name; Json.Data.simOrderConfig.ElementAt(index).MinValue = Min; Json.Data.simOrderConfig.ElementAt(index).MaxValue = Max; Json.Data.simOrderConfig.ElementAt(index).IsEnable = simOrderVisibleData.IsEnable; Json.Data.simOrderConfig.ElementAt(index).IsSelected = simOrderVisibleData.IsSelected; } } ActionManage.GetInstance.Send("SimOrderConfitViewModelExit"); }); CancelCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("SimOrderConfitViewModelExit"); }); } public BPARelayCommand ConfirmCommand { get; set; } public BPARelayCommand CancelCommand { get; set; } public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged();; } } private string _mName; public ushort Min { get { return _mMin; } set { _mMin = value; OnPropertyChanged(); } } private ushort _mMin; public ushort Max { get { return _mMax; } set { _mMax = value; OnPropertyChanged(); } } private ushort _mMax; } }