using BPA.Helper; using BPASmartClient.DosingSystem.View; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace BPASmartClient.DosingSystem.ViewModel { public class DeviceListViewModel : ViewModelBase { public DeviceListViewModel() { DetailsCommand = new BPARelayCommand((o) => { if (o != null && o is string str) { ChangeDeviceNameView cdn = new ChangeDeviceNameView(); ActionManage.GetInstance.Send("ChangeDeviceNameViewOpen", str); cdn.ShowDialog(); } }); //devices = DeviceInquire.GetInstance.devices; //2023/6/29新加 改为升序排列显示 devices = ConvertToObservableCollention(DeviceInquire.GetInstance.devices.OrderByDescending(p => p.IpAddress.Split(".")[3]).Reverse()); } public ObservableCollection devices { get; set; } public ObservableCollection ConvertToObservableCollention(IEnumerable array) { ObservableCollection collec = new ObservableCollection(); foreach (var item in array) { collec.Add(item); } return collec; } } public class Devices : NotifyBase { public string IpAddress { get { return _mIpAddress; } set { _mIpAddress = value; OnPropertyChanged(); } } private string _mIpAddress; /// /// 设备编号 /// public int DeviceNum { get { return _mDeviceNum; } set { _mDeviceNum = value; OnPropertyChanged(); } } private int _mDeviceNum; public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } } private string _mDeviceName; } }