将所有的VariableData改为Variable,将DataVariables改为Variables,修复了变量添加MQTT服务器后,服务器列表不更新的问题

This commit is contained in:
2025-07-17 20:13:21 +08:00
parent 6b21c387d5
commit 018fe7c9d0
44 changed files with 410 additions and 407 deletions

View File

@@ -11,7 +11,7 @@ public partial class ImportExcelDialogViewModel : ObservableObject
private string? _filePath;
[ObservableProperty]
private ObservableCollection<VariableData> _variableData = new();
private ObservableCollection<Variable> _variables = new();
partial void OnFilePathChanged(string? value)
{
@@ -23,7 +23,7 @@ public partial class ImportExcelDialogViewModel : ObservableObject
try
{
var data = ExcelHelper.ImprotFromTiaVariableTable(value);
VariableData = new ObservableCollection<VariableData>(data);
Variables = new ObservableCollection<Variable>(data);
}
catch (System.Exception ex)
{

View File

@@ -17,7 +17,7 @@ public partial class MqttAliasBatchEditDialogViewModel : ObservableObject
public Mqtt SelectedMqtt { get; private set; }
public MqttAliasBatchEditDialogViewModel(List<VariableData> selectedVariables, Mqtt selectedMqtt)
public MqttAliasBatchEditDialogViewModel(List<Variable> selectedVariables, Mqtt selectedMqtt)
{
SelectedMqtt = selectedMqtt;
Title=$"设置:{SelectedMqtt.Name}-MQTT服务器关联变量的别名";

View File

@@ -3,12 +3,12 @@ using CommunityToolkit.Mvvm.ComponentModel;
using PMSWPF.Models;
using PMSWPF.Data.Repositories;
using System.Threading.Tasks;
using PMSWPF.Services;
namespace PMSWPF.ViewModels.Dialogs;
public partial class MqttSelectionDialogViewModel : ObservableObject
{
private readonly MqttRepository _mqttRepository;
[ObservableProperty]
private ObservableCollection<Mqtt> mqtts;
@@ -16,26 +16,10 @@ public partial class MqttSelectionDialogViewModel : ObservableObject
[ObservableProperty]
private Mqtt? selectedMqtt;
public MqttSelectionDialogViewModel(MqttRepository mqttRepository)
public MqttSelectionDialogViewModel(DataServices dataServices)
{
_mqttRepository = mqttRepository;
LoadMqtts();
Mqtts = new ObservableCollection<Mqtt>(dataServices.Mqtts);
}
private async void LoadMqtts()
{
try
{
var allMqtts = await _mqttRepository.GetAllAsync();
Mqtts = new ObservableCollection<Mqtt>(allMqtts);
}
catch (Exception ex)
{
// 这里需要一个日志记录器但由于ViewModel中没有直接注入ILogger
// 暂时使用Console.WriteLine或NotificationHelper
// 更好的做法是注入ILogger或使用静态日志类
Console.WriteLine($"加载MQTT服务器列表失败: {ex.Message}");
// 或者使用NotificationHelper.ShowMessage("加载MQTT服务器列表失败", NotificationType.Error);
}
}
}

View File

@@ -21,9 +21,9 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
private ObservableCollection<OpcUaNode> _opcUaNodes;
[ObservableProperty]
private ObservableCollection<VariableData> _selectedNodeVariables;
private ObservableCollection<Variable> _selectedNodeVariables;
public List<VariableData> SelectedVariables { get; set; }=new List<VariableData>();
public List<Variable> SelectedVariables { get; set; }=new List<Variable>();
[ObservableProperty]
private bool _selectAllVariables;
@@ -36,7 +36,7 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
public OpcUaImportDialogViewModel()
{
OpcUaNodes = new ObservableCollection<OpcUaNode>();
SelectedNodeVariables = new ObservableCollection<VariableData>();
SelectedNodeVariables = new ObservableCollection<Variable>();
// Automatically connect when the ViewModel is created
ConnectCommand.Execute(null);
@@ -141,7 +141,7 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
{
// 如果是变量节点,直接显示它
SelectedNodeVariables.Clear();
SelectedNodeVariables.Add(new VariableData
SelectedNodeVariables.Add(new Variable
{
Name = node.DisplayName,
NodeId = node.NodeId.ToString(),
@@ -230,7 +230,7 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
dataType = _session.NodeCache.GetDisplayText(dataTypeNodeId);
}
SelectedNodeVariables.Add(new VariableData
SelectedNodeVariables.Add(new Variable
{
Name = opcUaNode.DisplayName,
OpcUaNodeId = opcUaNode.NodeId.ToString(),
@@ -254,8 +254,8 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
}
}
public ObservableCollection<VariableData> GetSelectedVariables()
public ObservableCollection<Variable> GetSelectedVariables()
{
return new ObservableCollection<VariableData>(SelectedVariables);
return new ObservableCollection<Variable>(SelectedVariables);
}
}

View File

@@ -6,7 +6,7 @@ namespace PMSWPF.ViewModels.Dialogs;
public partial class VarDataDialogViewModel : ObservableObject
{
[ObservableProperty]
private VariableData variableData;
private Variable _variable;
[ObservableProperty]
private string title;
[ObservableProperty]