using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPA.Helper; using FryPot_DosingSystem.Model; using BPA.Helper; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FryPot_DosingSystem.ViewModel { internal class DeviceListViewModel : NotifyBase { public ObservableCollection DeviceName { get; set; } = new ObservableCollection(); public ObservableCollection devices { get; set; } = new ObservableCollection(); public BPARelayCommand AddDeviceCommand { get; set; } public BPARelayCommand SaveDeviceConfig { get; set; } public BPARelayCommand DeleteDevice { get; set; } public DeviceListViewModel() { Json.Read(); devices = Json.Data.Devices; DeviceName.Add("滚筒输送线"); DeviceName.Add("炒锅1"); DeviceName.Add("炒锅2"); DeviceName.Add("炒锅3"); DeviceName.Add("炒锅4"); DeviceName.Add("炒锅5"); AddDeviceCommand = new BPARelayCommand(() => { erp: string guid = Guid.NewGuid().ToString(); DeviceInfo info = devices.FirstOrDefault(p => p.DeviceNum == guid); if (info == null) { devices.Add(new DeviceInfo() { DeviceNum = guid }); } else { goto erp; } }); DeleteDevice = new BPARelayCommand((str) => { DeviceInfo device = devices.FirstOrDefault(p => p.DeviceNum == str); if (device != null) { devices.Remove(device); } }); SaveDeviceConfig = new BPARelayCommand(() => { Json.Data.Devices = devices; Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"IP设置成功!"); }); } } }