using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; using BPASmartClient.Model; using BPASmartClient.MorkSUpgradedVer.Model; using BPA.Helper; namespace BPASmartClient.MorkSUpgradedVer.ViewModel { public class ParSetViewModel : NotifyBase { public ParSetViewModel() { SaveInfoCommand = new BPARelayCommand(SaveSettingData); ActionManage.GetInstance.Register(SaveSettingData, "初始化设定煮面时间"); if (Json.Data.DishLibraryParSets.Count < 5) { Json.Data.DishLibraryParSets.Clear(); for (int i = 0; i < 5; i++) { Json.Data.DishLibraryParSets.Add(new ParSet() { Minute = 2, Second = 0, TextBlockContext = $"{i + 1}" }); } } } public BPARelayCommand SaveInfoCommand { get; set; } public ObservableCollection parSets { get; set; } = Json.Data.parSets; public ObservableCollection DishLibraryParSets { get; set; } = Json.Data.DishLibraryParSets; private void SaveSettingData() { List values = new List(); values.Clear(); List bools = new List(); bools.Clear(); for (int i = 0; i < Json.Data.parSets.Count; i++) { values.Clear(); values.Add(Json.Data.parSets[i].Minute); values.Add(Json.Data.parSets[i].Second); bools.Add(Json.Data.parSets[i].IsShield); ActionManage.GetInstance.Send(new WritePar() { Address = $"VW{116 + (i * 6)}", Value = values.ToArray() }, "WriteVW"); } ActionManage.GetInstance.Send(new WritePar() { Address = "M260.0", Value = bools.ToArray() }, "WriteBools"); Json.Save(); } } }