2025-07-26 10:05:43 +08:00
|
|
|
|
// 文件: DMS.WPF/ViewModels/Items/DeviceItemViewModel.cs
|
2025-07-27 21:58:50 +08:00
|
|
|
|
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
using DMS.Application.DTOs;
|
|
|
|
|
|
using DMS.Core.Enums;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DMS.WPF.ViewModels.Items;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 代表设备列表中的单个设备项的ViewModel。
|
|
|
|
|
|
/// 实现了INotifyPropertyChanged,其任何属性变化都会自动通知UI。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class DeviceItemViewModel : ObservableObject
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Id { get; }
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string _name;
|
|
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string _description;
|
|
|
|
|
|
|
2025-07-26 10:05:43 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private ProtocolType _protocol;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string _ipAddress;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private int _port;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private int _rack;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private int _slot;
|
|
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
[ObservableProperty]
|
2025-07-27 21:58:50 +08:00
|
|
|
|
private CpuType _cpuType;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private DeviceType _deviceType;
|
|
|
|
|
|
|
2025-07-26 10:05:43 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string _opcUaServerUrl;
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private bool _isActive;
|
|
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private bool _isRunning;
|
|
|
|
|
|
|
2025-07-26 10:05:43 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string _status;
|
2025-07-27 21:58:50 +08:00
|
|
|
|
|
2025-07-27 22:35:07 +08:00
|
|
|
|
partial void OnProtocolChanged(ProtocolType oldValue, ProtocolType newValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-27 21:58:50 +08:00
|
|
|
|
public ObservableCollection<VariableTableItemViewModel> VariableTables { get; set; } = new();
|
2025-07-26 10:05:43 +08:00
|
|
|
|
|
|
|
|
|
|
public DeviceItemViewModel(DeviceDto dto)
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = dto.Id;
|
|
|
|
|
|
_name = dto.Name;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
_description = dto.Description;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
_protocol = dto.Protocol;
|
|
|
|
|
|
_ipAddress = dto.IpAddress;
|
|
|
|
|
|
_port = dto.Port;
|
|
|
|
|
|
_rack = dto.Rack;
|
|
|
|
|
|
_slot = dto.Slot;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
_cpuType = dto.CpuType;
|
|
|
|
|
|
_deviceType = dto.DeviceType;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
_opcUaServerUrl = dto.OpcUaServerUrl;
|
|
|
|
|
|
_isActive = dto.IsActive;
|
2025-07-27 21:08:58 +08:00
|
|
|
|
_isRunning = dto.IsRunning;
|
2025-07-26 10:05:43 +08:00
|
|
|
|
_status = dto.Status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-27 21:08:58 +08:00
|
|
|
|
public DeviceItemViewModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-26 10:05:43 +08:00
|
|
|
|
public DeviceDto ToDto()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new DeviceDto
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = this.Id,
|
|
|
|
|
|
Name = this.Name,
|
2025-07-27 21:08:58 +08:00
|
|
|
|
Description = this.Description,
|
2025-07-26 10:05:43 +08:00
|
|
|
|
Protocol = this.Protocol,
|
|
|
|
|
|
IpAddress = this.IpAddress,
|
|
|
|
|
|
Port = this.Port,
|
|
|
|
|
|
Rack = this.Rack,
|
|
|
|
|
|
Slot = this.Slot,
|
2025-07-27 21:08:58 +08:00
|
|
|
|
CpuType = this.CpuType,
|
|
|
|
|
|
DeviceType = this.DeviceType,
|
2025-07-26 10:05:43 +08:00
|
|
|
|
OpcUaServerUrl = this.OpcUaServerUrl,
|
|
|
|
|
|
IsActive = this.IsActive,
|
2025-07-27 21:08:58 +08:00
|
|
|
|
IsRunning = this.IsRunning,
|
2025-07-26 10:05:43 +08:00
|
|
|
|
Status = this.Status
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|