修复数据类型属性不统一的问题

This commit is contained in:
2025-09-02 16:45:24 +08:00
parent b770abe3f9
commit 6d7636d664
16 changed files with 88 additions and 76 deletions

View File

@@ -287,7 +287,7 @@ public partial class DataServices : ObservableRecipient, IRecipient<LoadMessage>
if (existingItem.AlarmMaxValue != dto.AlarmMaxValue) existingItem.AlarmMaxValue = dto.AlarmMaxValue;
if (existingItem.AlarmDeadband != dto.AlarmDeadband) existingItem.AlarmDeadband = dto.AlarmDeadband;
if (existingItem.Protocol != dto.Protocol) existingItem.Protocol = dto.Protocol;
if (existingItem.CSharpDataType != dto.CSharpDataType) existingItem.CSharpDataType = dto.CSharpDataType;
if (existingItem.DataType != dto.DataType) existingItem.DataType = dto.DataType;
if (existingItem.ConversionFormula != dto.ConversionFormula)
existingItem.ConversionFormula = dto.ConversionFormula;
if (existingItem.CreatedAt != dto.CreatedAt) existingItem.CreatedAt = dto.CreatedAt;

View File

@@ -331,7 +331,7 @@ public partial class ImportOpcUaDialogViewModel : DialogViewModelBase<List<Varia
Name = child.DisplayName, // 变量名称
OpcUaNodeId = child.NodeId.ToString(), // OPC UA节点ID
Protocol = ProtocolType.OpcUa, // 协议类型
CSharpDataType = child.DataType, // C#数据类型
DataType = child.DataType, // C#数据类型
IsActive = true // 默认激活状态
});
}

View File

@@ -143,7 +143,7 @@ public partial class VariableItemViewModel : ObservableObject
/// 获取或设置变量在C#中对应的数据类型。
/// </summary>
[ObservableProperty]
private CSharpDataType _cSharpDataType;
private DataType _dataType;
/// <summary>
/// 获取或设置值的转换公式。

View File

@@ -277,6 +277,11 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
{
try
{
if (CurrentVariableTable.Device==null)
{
NotificationHelper.ShowError("当前变量表的Device对象为空请检查。");
return;
}
// 检查OPC UA Endpoint URL是否已设置
string opcUaEndpointUrl = CurrentVariableTable.Device.OpcUaServerUrl;
if (string.IsNullOrEmpty(opcUaEndpointUrl))
@@ -286,48 +291,54 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
}
// 显示OPC UA导入对话框让用户选择要导入的变量
ImportOpcUaDialogViewModel importOpcUaDialogViewModel = App.Current.Services.GetRequiredService<ImportOpcUaDialogViewModel>() ;
ImportOpcUaDialogViewModel importOpcUaDialogViewModel = App.Current.Services.GetRequiredService<ImportOpcUaDialogViewModel>();
importOpcUaDialogViewModel.EndpointUrl = opcUaEndpointUrl; // 设置Endpoint URL
var importedVariables = await _dialogService.ShowDialogAsync(importOpcUaDialogViewModel);
if (importedVariables == null || !importedVariables.Any())
{
return; // 用户取消或没有选择任何变量
}
//var importedVariableDtos = _mapper.Map<List<VariableDto>>(importedVariables);
//foreach (var variableDto in importedVariableDtos)
//{
// variableDto.CreatedAt = DateTime.Now;
// variableDto.UpdatedAt = DateTime.Now;
// variableDto.VariableTableId = CurrentVariableTable.Id;
// variableDto.Protocol = ProtocolType.OpcUa; // 确保协议类型正确
//}
// 将导入的变量转换为DTO并设置必要的属性
var importedVariableDtos = _mapper.Map<List<VariableDto>>(importedVariables);
foreach (var variableDto in importedVariableDtos)
{
variableDto.CreatedAt = DateTime.Now;
variableDto.UpdatedAt = DateTime.Now;
variableDto.VariableTableId = CurrentVariableTable.Id;
}
//var existList = await _variableAppService.FindExistingVariablesAsync(importedVariableDtos);
//if (existList.Count > 0)
//{
// // 拼接要删除的变量名称,用于确认提示
// var existNames = string.Join("、", existList.Select(v => v.Name));
// var confrimDialogViewModel
// = new ConfirmDialogViewModel("存在已经添加的变量", $"变量名称:{existNames},已经存在,是否跳过继续添加其他的变量。取消则不添加任何变量", "继续");
// var res = await _dialogService.ShowDialogAsync(confrimDialogViewModel);
// if (!res) return;
// // 从导入列表中删除已经存在的变量
// importedVariableDtos.RemoveAll(variableDto => existList.Contains(variableDto));
//}
// 检查是否存在同名变量
var existList = await _variableAppService.FindExistingVariablesAsync(importedVariableDtos);
if (existList.Count > 0)
{
// 拼接要删除的变量名称,用于确认提示
var existNames = string.Join("、", existList.Select(v => v.Name));
var confirmDialogViewModel = new ConfirmDialogViewModel("存在已经添加的变量", $"变量名称:{existNames},已经存在,是否跳过继续添加其他的变量。取消则不添加任何变量", "继续");
var res = await _dialogService.ShowDialogAsync(confirmDialogViewModel);
if (!res) return;
// 从导入列表中删除已经存在的变量
importedVariableDtos.RemoveAll(variableDto => existList.Contains(variableDto));
}
//if (importedVariableDtos.Count != 0)
//{
// var isSuccess = await _variableAppService.BatchImportVariablesAsync(importedVariableDtos);
// if (isSuccess)
// {
// _variableItemList.AddRange(_mapper.Map<List<VariableItemViewModel>>(importedVariableDtos));
// NotificationHelper.ShowSuccess($"从OPC UA服务器导入变量成功共导入变量{importedVariableDtos.Count}个");
// }
//}
//else
//{
// NotificationHelper.ShowSuccess($"列表中没有要添加的变量了。");
//}
// 如果还有变量需要导入,则执行导入操作
if (importedVariableDtos.Count != 0)
{
var isSuccess = await _variableAppService.BatchImportVariablesAsync(importedVariableDtos);
if (isSuccess)
{
_variableItemList.AddRange(_mapper.Map<List<VariableItemViewModel>>(importedVariableDtos));
NotificationHelper.ShowSuccess($"从OPC UA服务器导入变量成功共导入变量{importedVariableDtos.Count}个");
}
else
{
NotificationHelper.ShowError("从OPC UA服务器导入变量失败");
}
}
else
{
NotificationHelper.ShowSuccess("列表中没有要添加的变量了。");
}
}
catch (Exception e)
{

View File

@@ -25,7 +25,7 @@
<ex:EnumBindingSource x:Key="ProtocolType" EnumType="{x:Type en:ProtocolType}" />
<ex:EnumBindingSource x:Key="SignalType" EnumType="{x:Type enums:SignalType}" />
<ex:EnumBindingSource x:Key="PollLevelType" EnumType="{x:Type enums:PollLevelType}" />
<ex:EnumBindingSource x:Key="CSharpDataType" EnumType="{x:Type enums:CSharpDataType}" />
<ex:EnumBindingSource x:Key="CSharpDataType" EnumType="{x:Type enums:DataType}" />
</ui:ContentDialog.Resources>
<ScrollViewer VerticalScrollBarVisibility="Auto">

View File

@@ -251,7 +251,7 @@
IsReadOnly="True"
Visibility="{Binding Source={StaticResource proxy}, Path=Data.IsOpcUaProtocolSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
<DataGridTextColumn
Binding="{Binding CSharpDataType}"
Binding="{Binding DataType}"
Header="数据类型"
IsReadOnly="True" />
<DataGridTemplateColumn Header="信号类型" SortMemberPath="SignalType">