临时提交
This commit is contained in:
@@ -24,7 +24,7 @@ namespace DMS.WPF.ViewModels;
|
||||
/// </summary>
|
||||
public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
{
|
||||
public DataServices DataServices { get; }
|
||||
public DataServices DataServices { get; }
|
||||
private readonly IDeviceAppService _deviceAppService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IDialogService _dialogService;
|
||||
@@ -120,29 +120,10 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
return;
|
||||
}
|
||||
|
||||
// DeviceItemViewModel device = new DeviceItemViewModel()
|
||||
// {
|
||||
// Name = "Test",
|
||||
// Description = "Test Device",
|
||||
// IpAddress = "127.0.0.1",
|
||||
// Port = 8080,
|
||||
// Protocol = ProtocolType.S7,
|
||||
// CpuType = "S7-1200",
|
||||
// DeviceType = DeviceType.SiemensPLC,
|
||||
// IsActive = true,
|
||||
//
|
||||
// };
|
||||
|
||||
|
||||
CreateDeviceWithDetailsDto dto = new CreateDeviceWithDetailsDto();
|
||||
dto.Device = _mapper.Map<DeviceDto>(device);
|
||||
|
||||
dto.VariableTable = new VariableTableDto()
|
||||
{
|
||||
Name = "默认变量表",
|
||||
Description = "默认变量表",
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
dto.DeviceMenu = new MenuBeanDto()
|
||||
{
|
||||
@@ -150,18 +131,34 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
Icon = SegoeFluentIcons.Devices2.Glyph,
|
||||
TargetViewKey = "DevicesView"
|
||||
};
|
||||
|
||||
dto.VariableTableMenu = new MenuBeanDto()
|
||||
if (device.IsAddDefVarTable)
|
||||
{
|
||||
dto.VariableTable = new VariableTableDto()
|
||||
{
|
||||
Header = dto.VariableTable.Name,
|
||||
Icon = SegoeFluentIcons.DataSense.Glyph,
|
||||
TargetViewKey = "VariableTableView"
|
||||
Name = "默认变量表",
|
||||
Description = "默认变量表",
|
||||
IsActive = true
|
||||
};
|
||||
dto.VariableTableMenu = new MenuBeanDto()
|
||||
{
|
||||
Header = dto.VariableTable.Name,
|
||||
Icon = SegoeFluentIcons.DataSense.Glyph,
|
||||
TargetViewKey = "VariableTableView"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
var addDto = await _deviceAppService.CreateDeviceWithDetailsAsync(dto);
|
||||
DataServices.Devices.Add(_mapper.Map<DeviceItemViewModel>(addDto.Device));
|
||||
//
|
||||
// await _deviceRepository.AddAsync(device);
|
||||
|
||||
DataServices.Devices.Add(_mapper.Map<DeviceItemViewModel>(addDto.Device));
|
||||
if (addDto.DeviceMenu != null)
|
||||
{
|
||||
var deviceMenu = DataServices.Menus.FirstOrDefault(m => m.Id == addDto.DeviceMenu.ParentId);
|
||||
if (deviceMenu!=null)
|
||||
{
|
||||
deviceMenu.Children.Add(_mapper.Map<MenuBeanItemViewModel>(addDto.DeviceMenu));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Core.Enums;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Items;
|
||||
@@ -53,55 +52,26 @@ public partial class DeviceItemViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string _status;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isAddDefVarTable;
|
||||
|
||||
partial void OnProtocolChanged(ProtocolType oldValue, ProtocolType newValue)
|
||||
partial void OnIpAddressChanged(string newIpAddress)
|
||||
{
|
||||
|
||||
if (Protocol == ProtocolType.OpcUa)
|
||||
{
|
||||
OpcUaServerUrl="opc.tcp://" + IpAddress+":"+Port;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnPortChanged(int newPort)
|
||||
{
|
||||
if (Protocol == ProtocolType.OpcUa)
|
||||
{
|
||||
OpcUaServerUrl="opc.tcp://" + IpAddress+":"+Port;
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<VariableTableItemViewModel> VariableTables { get; set; } = new();
|
||||
|
||||
public DeviceItemViewModel(DeviceDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_name = dto.Name;
|
||||
_description = dto.Description;
|
||||
_protocol = dto.Protocol;
|
||||
_ipAddress = dto.IpAddress;
|
||||
_port = dto.Port;
|
||||
_rack = dto.Rack;
|
||||
_slot = dto.Slot;
|
||||
_cpuType = dto.CpuType;
|
||||
_deviceType = dto.DeviceType;
|
||||
_opcUaServerUrl = dto.OpcUaServerUrl;
|
||||
_isActive = dto.IsActive;
|
||||
_isRunning = dto.IsRunning;
|
||||
_status = dto.Status;
|
||||
}
|
||||
|
||||
public DeviceItemViewModel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DeviceDto ToDto()
|
||||
{
|
||||
return new DeviceDto
|
||||
{
|
||||
Id = this.Id,
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
Protocol = this.Protocol,
|
||||
IpAddress = this.IpAddress,
|
||||
Port = this.Port,
|
||||
Rack = this.Rack,
|
||||
Slot = this.Slot,
|
||||
CpuType = this.CpuType,
|
||||
DeviceType = this.DeviceType,
|
||||
OpcUaServerUrl = this.OpcUaServerUrl,
|
||||
IsActive = this.IsActive,
|
||||
IsRunning = this.IsRunning,
|
||||
Status = this.Status
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,22 +52,5 @@ public partial class MqttServerItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableMqttAliasItemViewModel> _variableAliases = new();
|
||||
|
||||
public MqttServerItemViewModel(MqttServerDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_serverName = dto.ServerName;
|
||||
_brokerAddress = dto.BrokerAddress;
|
||||
_port = dto.Port;
|
||||
_username = dto.Username;
|
||||
_password = dto.Password;
|
||||
_isActive = dto.IsActive;
|
||||
_subscribeTopic = dto.SubscribeTopic;
|
||||
_publishTopic = dto.PublishTopic;
|
||||
_clientId = dto.ClientId;
|
||||
_createdAt = dto.CreatedAt;
|
||||
_connectedAt = dto.ConnectedAt;
|
||||
_connectionDuration = dto.ConnectionDuration;
|
||||
_messageFormat = dto.MessageFormat;
|
||||
_variableAliases = new ObservableCollection<VariableMqttAliasItemViewModel>(dto.VariableAliases.Select(va => new VariableMqttAliasItemViewModel(va)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,11 +16,5 @@ public partial class UserItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private bool _isActive;
|
||||
|
||||
public UserItemViewModel(UserDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_username = dto.Username;
|
||||
_role = dto.Role;
|
||||
_isActive = dto.IsActive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,11 +17,5 @@ public partial class VariableHistoryItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private DateTime _timestamp;
|
||||
|
||||
public VariableHistoryItemViewModel(VariableHistoryDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_variableId = dto.VariableId;
|
||||
_value = dto.Value;
|
||||
_timestamp = dto.Timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,34 +89,5 @@ public partial class VariableItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private OpcUaUpdateType _opcUaUpdateType;
|
||||
|
||||
public VariableItemViewModel(VariableDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_name = dto.Name;
|
||||
_s7Address = dto.S7Address;
|
||||
_dataValue = dto.DataValue;
|
||||
_displayValue = dto.DisplayValue;
|
||||
_variableTable = dto.VariableTable;
|
||||
_mqttAliases = dto.MqttAliases;
|
||||
_signalType = dto.SignalType;
|
||||
_pollLevel = dto.PollLevel;
|
||||
_isActive = dto.IsActive;
|
||||
_variableTableId = dto.VariableTableId;
|
||||
_opcUaNodeId = dto.OpcUaNodeId;
|
||||
_isHistoryEnabled = dto.IsHistoryEnabled;
|
||||
_historyDeadband = dto.HistoryDeadband;
|
||||
_isAlarmEnabled = dto.IsAlarmEnabled;
|
||||
_alarmMinValue = dto.AlarmMinValue;
|
||||
_alarmMaxValue = dto.AlarmMaxValue;
|
||||
_alarmDeadband = dto.AlarmDeadband;
|
||||
_protocol = dto.Protocol;
|
||||
_cSharpDataType = dto.CSharpDataType;
|
||||
_conversionFormula = dto.ConversionFormula;
|
||||
_createdAt = dto.CreatedAt;
|
||||
_updatedAt = dto.UpdatedAt;
|
||||
_updatedBy = dto.UpdatedBy;
|
||||
_isModified = dto.IsModified;
|
||||
_description = dto.Description;
|
||||
_opcUaUpdateType = dto.OpcUaUpdateType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,5 @@ public partial class VariableMqttAliasItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _alias;
|
||||
|
||||
public VariableMqttAliasItemViewModel(VariableMqttAliasDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_variableId = dto.VariableId;
|
||||
_mqttServerId = dto.MqttServerId;
|
||||
_mqttServerName = dto.MqttServerName;
|
||||
_alias = dto.Alias;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,14 +28,5 @@ public partial class VariableTableItemViewModel : ObservableObject
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableItemViewModel> _variables = new();
|
||||
|
||||
public VariableTableItemViewModel(VariableTableDto dto)
|
||||
{
|
||||
Id = dto.Id;
|
||||
_name = dto.Name;
|
||||
_description = dto.Description;
|
||||
_isActive = dto.IsActive;
|
||||
_deviceId = dto.DeviceId;
|
||||
_protocol = dto.Protocol;
|
||||
_variables = new ObservableCollection<VariableItemViewModel>(dto.Variables.Select(v => new VariableItemViewModel(v)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user