using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.Helper; using FryPot_DosingSystem.Model; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; 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 : ObservableObject { public ObservableCollection DeviceName { get; set; } = new ObservableCollection(); public ObservableCollection devices { get; set; } = new ObservableCollection(); public RelayCommand AddDeviceCommand { get; set; } public RelayCommand SaveDeviceConfig { get; set; } public RelayCommand 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 RelayCommand(() => { 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 RelayCommand((str) => { DeviceInfo device = devices.FirstOrDefault(p => p.DeviceNum == str); if (device != null) { devices.Remove(device); } }); SaveDeviceConfig = new RelayCommand(() => { Json.Data.Devices = devices; Json.Save(); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"IP设置成功!"); }); } } }