临时提交
This commit is contained in:
@@ -44,7 +44,7 @@ public partial class DeviceDetailViewModel : ViewModelBase, INavigatable
|
||||
{
|
||||
VariableTableDialogViewModel variableTableDialogViewModel = new VariableTableDialogViewModel()
|
||||
{
|
||||
PrimaryButContent = "添加变量表"
|
||||
PrimaryButText = "添加变量表"
|
||||
};
|
||||
// 1. 显示添加设备对话框
|
||||
var variableTableItemViewModel = await _dialogService.ShowDialogAsync(variableTableDialogViewModel);
|
||||
@@ -86,7 +86,7 @@ public partial class DeviceDetailViewModel : ViewModelBase, INavigatable
|
||||
|
||||
VariableTableDialogViewModel variableTableDialogViewModel = new VariableTableDialogViewModel(SelectedVariableTable)
|
||||
{
|
||||
PrimaryButContent = "编辑变量表"
|
||||
PrimaryButText = "编辑变量表"
|
||||
};
|
||||
// 1. 显示变量表对话框
|
||||
VariableTableItemViewModel variableTable = await _dialogService.ShowDialogAsync(variableTableDialogViewModel);
|
||||
|
||||
@@ -87,7 +87,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
{
|
||||
DeviceDialogViewModel deviceDialogViewModel = new DeviceDialogViewModel()
|
||||
{
|
||||
PrimaryButContent = "添加设备"
|
||||
PrimaryButText = "添加设备"
|
||||
};
|
||||
// 1. 显示添加设备对话框
|
||||
DeviceItemViewModel device = await _dialogService.ShowDialogAsync(deviceDialogViewModel);
|
||||
@@ -190,7 +190,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
|
||||
DeviceDialogViewModel deviceDialogViewModel = new DeviceDialogViewModel(SelectedDevice)
|
||||
{
|
||||
PrimaryButContent = "编辑设备"
|
||||
PrimaryButText = "编辑设备"
|
||||
};
|
||||
// 1. 显示设备对话框
|
||||
DeviceItemViewModel device = await _dialogService.ShowDialogAsync(deviceDialogViewModel);
|
||||
|
||||
@@ -13,7 +13,7 @@ public partial class ConfrimDialogViewModel : DialogViewModelBase<Boolean>
|
||||
{
|
||||
Message = message;
|
||||
Title = title;
|
||||
PrimaryButContent = primaryButText;
|
||||
PrimaryButText = primaryButText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace DMS.WPF.ViewModels.Dialogs
|
||||
private string _title;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _primaryButContent;
|
||||
private string _primaryButText;
|
||||
|
||||
public event Func<TResult, Task> CloseRequested;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class VarDataDialogViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private VariableItemViewModel _variable;
|
||||
[ObservableProperty]
|
||||
private string title;
|
||||
[ObservableProperty]
|
||||
private string primaryButtonText;
|
||||
}
|
||||
37
DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs
Normal file
37
DMS.WPF/ViewModels/Dialogs/VariableDialogViewModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class VariableDialogViewModel : DialogViewModelBase<VariableItemViewModel>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private VariableItemViewModel _variable;
|
||||
|
||||
public VariableDialogViewModel(string title,string primaryButText,VariableItemViewModel variable=null)
|
||||
{
|
||||
if (variable==null)
|
||||
{
|
||||
Variable=new VariableItemViewModel();
|
||||
}
|
||||
else
|
||||
{
|
||||
Variable=variable;
|
||||
}
|
||||
|
||||
Title=title;
|
||||
PrimaryButText=primaryButText;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void PrimaryButton()
|
||||
{
|
||||
Close(Variable);
|
||||
}
|
||||
[RelayCommand]
|
||||
private void CancleButton()
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
}
|
||||
@@ -6,88 +6,190 @@ using System.Collections.Generic;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Items;
|
||||
|
||||
/// <summary>
|
||||
/// 表示单个变量项的视图模型。
|
||||
/// 此类用于UI层的数据绑定,封装了变量数据以及与UI相关的状态和逻辑。
|
||||
/// 它继承自 ObservableObject,以便于实现 INotifyPropertyChanged 接口,从而支持WPF的双向绑定。
|
||||
/// </summary>
|
||||
public partial class VariableItemViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置变量的唯一标识符 (ID)。
|
||||
/// 通常对应数据库中的主键。
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的名称。
|
||||
/// 这个名称会显示在UI界面上,例如在列表或标签中。
|
||||
/// [ObservableProperty] 特性会自动生成支持变更通知的属性。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _name;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的S7通信地址。
|
||||
/// 例如:"DB1.DBD0"。仅在协议为S7时有效。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string? _s7Address;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置从设备读取到的原始数据值。
|
||||
/// 这通常是未经转换的字符串形式的值。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string? _dataValue;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用于在界面上显示的值。
|
||||
/// 这可能是经过公式转换、格式化或添加了单位后的值。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string? _displayValue;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置此变量所属的变量表 (VariableTable) 的数据传输对象 (DTO)。
|
||||
/// 用于在界面上显示变量表的关联信息。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private VariableTableDto? _variableTable;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置与此变量关联的MQTT别名列表。
|
||||
/// 一个变量可以有多个MQTT别名。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private List<VariableMqttAliasDto>? _mqttAliases;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的信号类型 (如:AI, DI, AO, DO)。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private SignalType _signalType ;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的轮询等级。
|
||||
/// 用于决定数据采集的频率(如:高、中、低)。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private PollLevelType _pollLevel;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置一个值,该值指示此变量是否被激活。
|
||||
/// 未激活的变量将不会被后台服务轮询。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isActive;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量所属的变量表的ID。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private int _variableTableId;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的OPC UA节点ID。
|
||||
/// 例如:"ns=2;s=MyDevice.MyVariable"。仅在协议为OpcUa时有效。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _opcUaNodeId;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否为此变量启用历史记录。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isHistoryEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置历史记录的死区值。
|
||||
/// 当值的变化超过此死区值时,才会记录历史数据,用于减少不必要的数据存储。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private double _historyDeadband;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否为此变量启用报警功能。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isAlarmEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置报警的下限值。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private double _alarmMinValue;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置报警的上限值。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private double _alarmMaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置报警的死区值。
|
||||
/// 用于防止在临界点附近频繁触发或解除报警。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private double _alarmDeadband;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量使用的通信协议(如:S7, OpcUa, Modbus)。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private ProtocolType _protocol;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量在C#中对应的数据类型。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private CSharpDataType _cSharpDataType;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置值的转换公式。
|
||||
/// 例如:"x * 10" 或 "(x / 100) + 5"。'x' 代表原始值。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _conversionFormula;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置记录的创建时间。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private DateTime _createdAt;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置记录的最后更新时间。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private DateTime _updatedAt;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置最后更新此记录的用户或进程。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _updatedBy;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置一个值,该值指示此视图模型中的数据是否已被修改。
|
||||
/// 用于跟踪UI上的更改,以便提示用户保存。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private bool _isModified;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的描述信息。
|
||||
/// 提供关于该变量的更多上下文或备注。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private string _description;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置OPC UA值的更新方式(轮询或订阅)。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private OpcUaUpdateType _opcUaUpdateType;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,17 @@ using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.Application.Services;
|
||||
using DMS.Helper;
|
||||
using DMS.WPF.Views;
|
||||
using DMS.WPF.Views.HandyDialogs;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Extension;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ObservableCollections;
|
||||
|
||||
@@ -482,78 +488,88 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
/// </summary>
|
||||
/// <param name="variableTable">当前操作的变量表,用于设置新变量的所属ID。</param>
|
||||
[RelayCommand]
|
||||
private async void AddVarData(VariableTable variableTable)
|
||||
private async void AddVariable(VariableTable variableTable)
|
||||
{
|
||||
// try
|
||||
// {
|
||||
// // 显示添加变量数据的对话框
|
||||
// var varData = await _dialogService.ShowAddVarDataDialog();
|
||||
//
|
||||
// // 如果用户取消或对话框未返回数据,则直接返回
|
||||
// if (varData == null)
|
||||
// return;
|
||||
//
|
||||
// // 设置新变量的所属变量表ID
|
||||
// varData.VariableTableId = variableTable.Id;
|
||||
//
|
||||
// // --- 重复性检查逻辑开始 ---
|
||||
// bool isDuplicate = false;
|
||||
// string duplicateReason = string.Empty;
|
||||
//
|
||||
// // 检查名称是否重复
|
||||
// if (Variables.Any(v => v.Name == varData.Name))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"名称 '{varData.Name}' 已存在。";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 根据协议类型检查S7地址或NodeId是否重复
|
||||
// if (variableTable.ProtocolType == ProtocolType.S7)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(varData.S7Address) &&
|
||||
// Variables.Any(v => v.S7Address == varData.S7Address))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"S7地址 '{varData.S7Address}' 已存在。";
|
||||
// }
|
||||
// }
|
||||
// else if (variableTable.ProtocolType == ProtocolType.OpcUA)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(varData.NodeId) && Variables.Any(v => v.NodeId == varData.NodeId))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"OPC UA NodeId '{varData.NodeId}' 已存在。";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (isDuplicate)
|
||||
// {
|
||||
// NotificationHelper.ShowError($"添加变量失败:{duplicateReason}");
|
||||
// return;
|
||||
// }
|
||||
// // --- 重复性检查逻辑结束 ---
|
||||
//
|
||||
// // 添加变量数据到数据库
|
||||
// var resVarData = await _varDataRepository.AddAsync(varData);
|
||||
// if (resVarData == null)
|
||||
// {
|
||||
// NotificationHelper.ShowError($"添加变量失败了:{varData?.Name}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 更新当前页面显示的数据:将新变量添加到集合中
|
||||
// Variables.Add(resVarData);
|
||||
//
|
||||
// // 显示成功通知
|
||||
// NotificationHelper.ShowSuccess($"添加变量成功:{varData?.Name}");
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// // 捕获并显示错误通知
|
||||
// NotificationHelper.ShowError($"添加变量的过程中发生了不可预期的错误:{e.Message}", e);
|
||||
// }
|
||||
try
|
||||
{
|
||||
// 显示添加变量数据的对话框
|
||||
VariableDialogViewModel variableDialogViewModel=new VariableDialogViewModel("添加变量","添加变量");
|
||||
|
||||
VariableEditorDialog editorDialog = new VariableEditorDialog() { DataContext = variableDialogViewModel };
|
||||
|
||||
Dialog.Show(new MessageBoxInfo()
|
||||
{
|
||||
Message = "操作成功",
|
||||
Caption = "提示",
|
||||
Button = MessageBoxButton.OKCancel,
|
||||
});
|
||||
// var variableItemViewModel = await _dialogService.ShowDialogAsync(variableDialogViewModel);
|
||||
|
||||
// 如果用户取消或对话框未返回数据,则直接返回
|
||||
// if (res == null)
|
||||
// return;
|
||||
|
||||
// // 设置新变量的所属变量表ID
|
||||
// varData.VariableTableId = variableTable.Id;
|
||||
//
|
||||
// // --- 重复性检查逻辑开始 ---
|
||||
// bool isDuplicate = false;
|
||||
// string duplicateReason = string.Empty;
|
||||
//
|
||||
// // 检查名称是否重复
|
||||
// if (Variables.Any(v => v.Name == varData.Name))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"名称 '{varData.Name}' 已存在。";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 根据协议类型检查S7地址或NodeId是否重复
|
||||
// if (variableTable.ProtocolType == ProtocolType.S7)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(varData.S7Address) &&
|
||||
// Variables.Any(v => v.S7Address == varData.S7Address))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"S7地址 '{varData.S7Address}' 已存在。";
|
||||
// }
|
||||
// }
|
||||
// else if (variableTable.ProtocolType == ProtocolType.OpcUA)
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(varData.NodeId) && Variables.Any(v => v.NodeId == varData.NodeId))
|
||||
// {
|
||||
// isDuplicate = true;
|
||||
// duplicateReason = $"OPC UA NodeId '{varData.NodeId}' 已存在。";
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (isDuplicate)
|
||||
// {
|
||||
// NotificationHelper.ShowError($"添加变量失败:{duplicateReason}");
|
||||
// return;
|
||||
// }
|
||||
// // --- 重复性检查逻辑结束 ---
|
||||
//
|
||||
// // 添加变量数据到数据库
|
||||
// var resVarData = await _varDataRepository.AddAsync(varData);
|
||||
// if (resVarData == null)
|
||||
// {
|
||||
// NotificationHelper.ShowError($"添加变量失败了:{varData?.Name}");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 更新当前页面显示的数据:将新变量添加到集合中
|
||||
// Variables.Add(resVarData);
|
||||
//
|
||||
// // 显示成功通知
|
||||
// NotificationHelper.ShowSuccess($"添加变量成功:{varData?.Name}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// 捕获并显示错误通知
|
||||
NotificationHelper.ShowError($"添加变量的过程中发生了不可预期的错误:{e.Message}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user