using BPASmartClient.FoodStationTest.Model; using BPASmartClient.FoodStationTest.View; using BPA.Helper; using BPA.Helper; using System.Collections.ObjectModel; namespace BPASmartClient.FoodStationTest.ViewModel { public class DeviceListViewModel : NotifyBase { public DeviceListViewModel() { ChangeNameCommand = new BPARelayCommand((o) => { if (o != null && o is string str) { ChangeDeviceNameView cdn = new ChangeDeviceNameView(); ActionManage.GetInstance.Send("ChangeDeviceNameViewOpen", str); cdn.ShowDialog(); } }); Open = new BPARelayCommand((o) => { if (o != null && o is string str) { DeviceInquire.GetInstance.GetDevice(str).OpenLid();//设置PLC名称 } }); Close = new BPARelayCommand((o) => { if (o != null && o is string str) { DeviceInquire.GetInstance.GetDevice(str).CloseLid();//设置PLC名称 } }); devices = DeviceInquire.GetInstance.devices; /*foreach (var device in devices) { device.Serial = Convert.ToInt32(device.DeviceName.Substring(1, device.DeviceName.Length - 1)) / 10; } devices = new ObservableCollection(devices.OrderBy(item => item.Serial));*/ } public BPARelayCommand ChangeNameCommand { get; set; } public BPARelayCommand Open { get; set; } public BPARelayCommand Close { get; set; } //public static ObservableCollection devices { get; set; } = new ObservableCollection(); public ObservableCollection devices { get; set; } } public class Devices : NotifyBase { public int Serial { get { return _mSerial; } set { _mSerial = value; OnPropertyChanged(); } } private int _mSerial; public string IpAddress { get { return _mIpAddress; } set { _mIpAddress = value; OnPropertyChanged(); } } private string _mIpAddress; public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } private string _mDeviceName; } }