初步完成变量选择Mqtt服务器
This commit is contained in:
@@ -195,7 +195,16 @@ public partial class App : System.Windows.Application
|
||||
services.AddSingleton<DevicesViewModel>();
|
||||
services.AddSingleton<DataTransformViewModel>();
|
||||
services.AddSingleton<SettingViewModel>();
|
||||
services.AddTransient<VariableTableViewModel>();
|
||||
services.AddTransient<VariableTableViewModel>(provider =>
|
||||
new VariableTableViewModel(
|
||||
provider.GetRequiredService<IMapper>(),
|
||||
provider.GetRequiredService<IDialogService>(),
|
||||
provider.GetRequiredService<IVariableAppService>(),
|
||||
provider.GetRequiredService<IMqttAliasAppService>(),
|
||||
provider.GetRequiredService<IMqttAppService>(),
|
||||
provider.GetRequiredService<DataServices>(),
|
||||
provider.GetRequiredService<INotificationService>()
|
||||
));
|
||||
services.AddSingleton<DeviceDetailViewModel>();
|
||||
services.AddSingleton<MqttsViewModel>(provider =>
|
||||
new MqttsViewModel(
|
||||
@@ -210,10 +219,18 @@ public partial class App : System.Windows.Application
|
||||
);
|
||||
services.AddScoped<MqttServerDetailViewModel>();
|
||||
|
||||
// 注册对话框模型
|
||||
// 注册对话框视图模型
|
||||
services.AddTransient<DeviceDialogViewModel>();
|
||||
services.AddTransient<ConfirmDialogViewModel>();
|
||||
services.AddTransient<VariableTableDialogViewModel>();
|
||||
services.AddTransient<ImportExcelDialogViewModel>();
|
||||
services.AddTransient<ImportOpcUaDialogViewModel>();
|
||||
services.AddTransient<VariableDialogViewModel>();
|
||||
services.AddTransient<PollLevelDialogViewModel>();
|
||||
services.AddTransient<IsActiveDialogViewModel>();
|
||||
services.AddTransient<MqttDialogViewModel>();
|
||||
services.AddTransient<MqttSelectionDialogViewModel>();
|
||||
services.AddTransient<MqttAliasBatchEditDialogViewModel>();
|
||||
|
||||
// 注册View视图
|
||||
services.AddSingleton<SplashWindow>();
|
||||
|
||||
@@ -23,7 +23,10 @@ namespace DMS.WPF.Services
|
||||
{ typeof(VariableDialogViewModel), typeof(VariableDialog) },
|
||||
{ typeof(PollLevelDialogViewModel), typeof(PollLevelDialog) },
|
||||
{ typeof(IsActiveDialogViewModel), typeof(IsActiveDialog) },
|
||||
{ typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here
|
||||
{ typeof(MqttDialogViewModel), typeof(MqttDialog) },
|
||||
{ typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) },
|
||||
{ typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) }
|
||||
// Add other mappings here
|
||||
// ... other dialogs
|
||||
};
|
||||
|
||||
|
||||
@@ -1,34 +1,100 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class MqttAliasBatchEditDialogViewModel : ObservableObject
|
||||
namespace DMS.WPF.ViewModels.Dialogs
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _title = "批量设置MQTT别名";
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableMqttAlias> _variablesToEdit;
|
||||
|
||||
public MqttServerItemViewModel SelectedMqtt { get; private set; }
|
||||
|
||||
public MqttAliasBatchEditDialogViewModel(List<VariableItemViewModel> selectedVariables, MqttServerItemViewModel selectedMqtt)
|
||||
/// <summary>
|
||||
/// MQTT别名批量编辑对话框的视图模型
|
||||
/// </summary>
|
||||
public partial class MqttAliasBatchEditDialogViewModel : DialogViewModelBase<List<VariableMqttAliasItemViewModel>>
|
||||
{
|
||||
SelectedMqtt = selectedMqtt;
|
||||
Title=$"设置:{SelectedMqtt.ServerName}-MQTT服务器关联变量的别名";
|
||||
// VariablesToEdit = new ObservableCollection<VariableMqttAlias>(
|
||||
// selectedVariables.Select(v => new VariableMqttAlias(v, selectedMqtt))
|
||||
// );
|
||||
}
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<VariableMqttAliasItemViewModel> _variableMqttAliases = new();
|
||||
|
||||
public MqttAliasBatchEditDialogViewModel()
|
||||
{
|
||||
// For design time
|
||||
// VariablesToEdit = new ObservableCollection<VariableMqtt>();
|
||||
[ObservableProperty]
|
||||
private MqttServerItemViewModel _selectedMqttServer;
|
||||
|
||||
public MqttAliasBatchEditDialogViewModel(
|
||||
List<VariableItemViewModel> variables,
|
||||
MqttServerItemViewModel mqttServer)
|
||||
{
|
||||
_selectedMqttServer = mqttServer;
|
||||
InitializeVariableMqttAliases(variables);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化变量MQTT别名列表
|
||||
/// </summary>
|
||||
private void InitializeVariableMqttAliases(List<VariableItemViewModel> variables)
|
||||
{
|
||||
VariableMqttAliases.Clear();
|
||||
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
// 检查该变量是否已经有针对此MQTT服务器的别名
|
||||
var existingAlias = variable.MqttAliases?.FirstOrDefault(ma => ma.MqttServerId == SelectedMqttServer.Id);
|
||||
|
||||
var variableMqttAlias = new VariableMqttAliasItemViewModel
|
||||
{
|
||||
VariableId = variable.Id,
|
||||
MqttServerId = SelectedMqttServer.Id,
|
||||
MqttServerName = SelectedMqttServer.ServerName,
|
||||
MqttServer = SelectedMqttServer,
|
||||
Alias = existingAlias?.Alias ?? GenerateDefaultAlias(variable)
|
||||
};
|
||||
|
||||
VariableMqttAliases.Add(variableMqttAlias);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成默认别名
|
||||
/// </summary>
|
||||
private string GenerateDefaultAlias(VariableItemViewModel variable)
|
||||
{
|
||||
// 可以根据需要自定义默认别名生成逻辑
|
||||
return $"{variable.Name}_{Guid.NewGuid().ToString("N")[..8]}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认编辑
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
var result = VariableMqttAliases.ToList();
|
||||
Close(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消编辑
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部应用相同的别名前缀
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void ApplySamePrefix(string prefix)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(prefix))
|
||||
return;
|
||||
|
||||
foreach (var alias in VariableMqttAliases)
|
||||
{
|
||||
alias.Alias = $"{prefix}_{alias.VariableId}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,90 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DMS.WPF.Services;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Application.Interfaces;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class MqttSelectionDialogViewModel : ObservableObject
|
||||
namespace DMS.WPF.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// MQTT服务器选择对话框的视图模型
|
||||
/// </summary>
|
||||
public partial class MqttSelectionDialogViewModel : DialogViewModelBase<MqttServerItemViewModel>
|
||||
{
|
||||
private readonly IMqttAppService _mqttAppService;
|
||||
|
||||
// [ObservableProperty]
|
||||
// private ObservableCollection<Mqtt> mqtts;
|
||||
//
|
||||
// [ObservableProperty]
|
||||
// private Mqtt? selectedMqtt;
|
||||
//
|
||||
// public MqttSelectionDialogViewModel(DataServices _dataServices)
|
||||
// {
|
||||
// Mqtts = new ObservableCollection<Mqtt>(_dataServices.Mqtts);
|
||||
// }
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<MqttServerItemViewModel> _mqttServers = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private MqttServerItemViewModel _selectedMqttServer;
|
||||
|
||||
public MqttSelectionDialogViewModel(IMqttAppService mqttAppService)
|
||||
{
|
||||
_mqttAppService = mqttAppService;
|
||||
LoadMqttServersAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载所有MQTT服务器
|
||||
/// </summary>
|
||||
private async void LoadMqttServersAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mqttServerDtos = await _mqttAppService.GetAllMqttServersAsync();
|
||||
MqttServers.Clear();
|
||||
|
||||
foreach (var dto in mqttServerDtos)
|
||||
{
|
||||
MqttServers.Add(new MqttServerItemViewModel
|
||||
{
|
||||
Id = dto.Id,
|
||||
ServerName = dto.ServerName,
|
||||
ServerUrl = dto.ServerUrl,
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录错误日志
|
||||
System.Console.WriteLine($"加载MQTT服务器失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认选择
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
if (SelectedMqttServer != null)
|
||||
{
|
||||
Close(SelectedMqttServer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取消选择
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public partial class VariableItemViewModel : ObservableObject
|
||||
/// 一个变量可以有多个MQTT别名。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private List<VariableMqttAliasDto>? _mqttAliases;
|
||||
private List<VariableMqttAliasItemViewModel>? _mqttAliases;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置变量的信号类型 (如:AI, DI, AO, DO)。
|
||||
|
||||
@@ -18,6 +18,7 @@ public partial class VariableMqttAliasItemViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private string _alias;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private MqttServerItemViewModel _mqttServer;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
private readonly IDialogService _dialogService;
|
||||
|
||||
private readonly IVariableAppService _variableAppService;
|
||||
private readonly IMqttAliasAppService _mqttAliasAppService;
|
||||
private readonly IMqttAppService _mqttAppService;
|
||||
|
||||
/// <summary>
|
||||
/// 当前正在操作的变量表实体。
|
||||
@@ -89,11 +91,14 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
private readonly INotificationService _notificationService;
|
||||
|
||||
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, IVariableAppService variableAppService,
|
||||
IMqttAliasAppService mqttAliasAppService, IMqttAppService mqttAppService,
|
||||
DataServices dataServices, INotificationService notificationService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_dialogService = dialogService;
|
||||
_variableAppService = variableAppService;
|
||||
_mqttAliasAppService = mqttAliasAppService;
|
||||
_mqttAppService = mqttAppService;
|
||||
_dataServices = dataServices;
|
||||
_notificationService = notificationService;
|
||||
IsLoadCompletion = false; // 初始设置为 false,表示未完成加载
|
||||
@@ -556,101 +561,96 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
[RelayCommand]
|
||||
public async Task AddMqttServerToVariables(IList<object> variablesToAddMqtt)
|
||||
{
|
||||
// var validVariables = variablesToAddMqtt?.OfType<Variable>()
|
||||
// .ToList();
|
||||
//
|
||||
// // 检查是否有变量被选中
|
||||
// if (validVariables == null || !validVariables.Any())
|
||||
// {
|
||||
// NotificationHelper.ShowInfo("请选择要添加MQTT服务器的变量");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// // 显示MQTT服务器选择对话框,让用户选择一个MQTT服务器
|
||||
// var selectedMqtt = await _dialogService.ShowMqttSelectionDialog();
|
||||
// if (selectedMqtt == null)
|
||||
// {
|
||||
// return; // 用户取消选择
|
||||
// }
|
||||
//
|
||||
// // 显示批量编辑别名对话框
|
||||
// var editedVariableMqtts = await _dialogService.ShowMqttAliasBatchEditDialog(validVariables, selectedMqtt);
|
||||
//
|
||||
// if (editedVariableMqtts == null || !editedVariableMqtts.Any())
|
||||
// {
|
||||
// NotificationHelper.ShowInfo("没有变量别名被设置或已取消。");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// int totalAffectedCount = 0;
|
||||
// // 调用仓库方法来添加或更新MQTT服务器关联和别名
|
||||
// var resCount = await _varDataRepository.AddMqttToVariablesAsync(editedVariableMqtts);
|
||||
// totalAffectedCount += resCount;
|
||||
//
|
||||
//
|
||||
// //更新变量Variable的VariableMqtts列表
|
||||
// foreach (var editedVariableMqtt in editedVariableMqtts)
|
||||
// {
|
||||
// // 更新内存中的 Variable 对象
|
||||
// var originalVariable = VariableTable.Variables.FirstOrDefault(v=>v.Id==editedVariableMqtt.Variable.Id);
|
||||
// if (originalVariable == null)
|
||||
// {
|
||||
// NlogHelper.Warn($"没有在VariableTable.Variables中找到,ID:{editedVariableMqtt.Variable.Id},Name:{editedVariableMqtt.Variable.Name}的对象");
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (originalVariable.VariableMqtts == null)
|
||||
// {
|
||||
// originalVariable.VariableMqtts = new List<VariableMqtt>();
|
||||
// }
|
||||
//
|
||||
// // 检查是否已存在该变量与该MQTT服务器的关联
|
||||
// var existingVariableMqtt
|
||||
// = originalVariable.VariableMqtts.FirstOrDefault(vm => vm.MqttId ==
|
||||
// editedVariableMqtt.Mqtt.Id);
|
||||
//
|
||||
// if (existingVariableMqtt == null)
|
||||
// {
|
||||
// // 如果不存在,则添加新的关联
|
||||
// var variableMqtt = new VariableMqtt(originalVariable,editedVariableMqtt.Mqtt)
|
||||
// {
|
||||
// VariableId = originalVariable.Id,
|
||||
// MqttId = editedVariableMqtt.Mqtt.Id,
|
||||
// MqttAlias = editedVariableMqtt.MqttAlias,
|
||||
// Mqtt = editedVariableMqtt.Mqtt // 关联Mqtt对象,方便UI显示
|
||||
// };
|
||||
// originalVariable.VariableMqtts.Add(variableMqtt);
|
||||
// //更新MQTT服务器对应的的VariableMqtts列表
|
||||
// selectedMqtt.VariableMqtts.Add(variableMqtt);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // 如果存在,则更新别名
|
||||
// existingVariableMqtt.MqttAlias = editedVariableMqtt.MqttAlias;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (totalAffectedCount > 0)
|
||||
// {
|
||||
// // 刷新界面以反映更改
|
||||
// await RefreshDataView();
|
||||
// NotificationHelper.ShowSuccess($"已成功为 {totalAffectedCount} 个变量添加/更新MQTT服务器: {selectedMqtt.Name} 的别名。");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// NotificationHelper.ShowInfo($"没有新的变量关联或别名更新到MQTT服务器: {selectedMqtt.Name}。");
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// // 捕获并显示错误通知
|
||||
// NotificationHelper.ShowError($"添加MQTT服务器失败: {ex.Message}", ex);
|
||||
// }
|
||||
var validVariables = variablesToAddMqtt?.OfType<VariableItemViewModel>()
|
||||
.ToList();
|
||||
|
||||
// 检查是否有变量被选中
|
||||
if (validVariables == null || !validVariables.Any())
|
||||
{
|
||||
_notificationService.ShowInfo("请选择要添加MQTT服务器的变量");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 显示MQTT服务器选择对话框,让用户选择一个MQTT服务器
|
||||
var mqttSelectionViewModel = new MqttSelectionDialogViewModel(_mqttAppService);
|
||||
var selectedMqtt = await _dialogService.ShowDialogAsync(mqttSelectionViewModel);
|
||||
if (selectedMqtt == null)
|
||||
{
|
||||
return; // 用户取消选择
|
||||
}
|
||||
|
||||
// 显示批量编辑别名对话框
|
||||
var mqttAliasBatchEditViewModel = new MqttAliasBatchEditDialogViewModel(validVariables, selectedMqtt);
|
||||
var editedVariableMqtts = await _dialogService.ShowDialogAsync(mqttAliasBatchEditViewModel);
|
||||
|
||||
if (editedVariableMqtts == null || !editedVariableMqtts.Any())
|
||||
{
|
||||
_notificationService.ShowInfo("没有变量别名被设置或已取消。");
|
||||
return;
|
||||
}
|
||||
|
||||
int totalAffectedCount = 0;
|
||||
|
||||
// 为每个变量分配MQTT别名
|
||||
foreach (var editedVariableMqtt in editedVariableMqtts)
|
||||
{
|
||||
await _mqttAliasAppService.AssignAliasAsync(
|
||||
editedVariableMqtt.VariableId,
|
||||
selectedMqtt.Id,
|
||||
editedVariableMqtt.Alias);
|
||||
|
||||
totalAffectedCount++;
|
||||
|
||||
// 更新内存中的 Variable 对象
|
||||
var originalVariable = validVariables.FirstOrDefault(v => v.Id == editedVariableMqtt.VariableId);
|
||||
if (originalVariable == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (originalVariable.MqttAliases == null)
|
||||
{
|
||||
originalVariable.MqttAliases = new ();
|
||||
}
|
||||
|
||||
// 检查是否已存在该变量与该MQTT服务器的关联
|
||||
var existingVariableMqtt = originalVariable.MqttAliases.FirstOrDefault(vm => vm.MqttServerId == selectedMqtt.Id);
|
||||
|
||||
if (existingVariableMqtt == null)
|
||||
{
|
||||
// 如果不存在,则添加新的关联
|
||||
var variableMqtt = new VariableMqttAliasItemViewModel
|
||||
{
|
||||
VariableId = originalVariable.Id,
|
||||
MqttServerId = selectedMqtt.Id,
|
||||
Alias = editedVariableMqtt.Alias,
|
||||
MqttServer = selectedMqtt
|
||||
};
|
||||
// originalVariable.MqttAliases.Add(variableMqtt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果存在,则更新别名
|
||||
existingVariableMqtt.Alias = editedVariableMqtt.Alias;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalAffectedCount > 0)
|
||||
{
|
||||
_notificationService.ShowSuccess($"已成功为 {totalAffectedCount} 个变量添加/更新MQTT服务器: {selectedMqtt.ServerName} 的别名。");
|
||||
}
|
||||
else
|
||||
{
|
||||
_notificationService.ShowInfo($"没有新的变量关联或别名更新到MQTT服务器: {selectedMqtt.ServerName}。");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 捕获并显示错误通知
|
||||
_notificationService.ShowError($"添加MQTT服务器失败: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,38 +1,86 @@
|
||||
<ui:ContentDialog
|
||||
x:Class="DMS.WPF.Views.Dialogs.MqttAliasBatchEditDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:vm="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
xmlns:models="clr-namespace:DMS.Core.Models"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance vm:MqttAliasBatchEditDialogViewModel}"
|
||||
Title="{Binding Title}"
|
||||
PrimaryButtonText="确定"
|
||||
CloseButtonText="取消"
|
||||
>
|
||||
<StackPanel Margin="10">
|
||||
<TextBlock TextWrapping="WrapWithOverflow" Margin="5 10" FontSize="13" Foreground="#666">设置的别名,当变量向MQTT服务器发送数据时就会按照设置设置好的别名发送,请在MQTT服务端,按照设置的名称接受。</TextBlock>
|
||||
<DataGrid ItemsSource="{Binding VariablesToEdit}"
|
||||
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.MqttAliasBatchEditDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:vm="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
d:DataContext="{d:DesignInstance vm:MqttAliasBatchEditDialogViewModel}"
|
||||
Title="批量编辑MQTT别名"
|
||||
PrimaryButtonText="确定"
|
||||
CloseButtonText="取消"
|
||||
PrimaryButtonCommand="{Binding ConfirmCommand}"
|
||||
CloseButtonCommand="{Binding CloseCommand}"
|
||||
DefaultButton="Primary"
|
||||
Background="White"
|
||||
mc:Ignorable="d"
|
||||
>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="为目标MQTT服务器设置变量别名:"
|
||||
Margin="0,0,0,10"
|
||||
Style="{StaticResource BodyTextBlockStyle}" />
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<TextBlock Text="MQTT服务器:" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding SelectedMqttServer.ServerName}"
|
||||
FontWeight="Bold"
|
||||
Margin="5,0,0,0"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
|
||||
<DataGrid Grid.Row="2"
|
||||
ItemsSource="{Binding VariableMqttAliases}"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False"
|
||||
CanUserDeleteRows="False"
|
||||
IsReadOnly="False">
|
||||
Margin="0,0,0,10"
|
||||
MinHeight="300"
|
||||
MaxHeight="500">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="变量名称" Binding="{Binding Variable.Name}" IsReadOnly="True" Width="*"/>
|
||||
<DataGridTextColumn Header="标识符" Binding="{Binding Identifier}" IsReadOnly="True" Width="*"/>
|
||||
<DataGridTemplateColumn Header="MQTT别名" Width="*">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<hc:TextBox Text="{Binding MqttAlias, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
hc:InfoElement.Placeholder="请输入别名"/>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn Header="变量名称"
|
||||
Binding="{Binding VariableId}"
|
||||
IsReadOnly="True"
|
||||
Width="*" />
|
||||
<DataGridTextColumn Header="别名"
|
||||
Binding="{Binding Alias}"
|
||||
Width="*" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<TextBox x:Name="PrefixTextBox"
|
||||
Width="150"
|
||||
Margin="0,0,10,0">
|
||||
<TextBox.Resources>
|
||||
<VisualBrush x:Key="HintText" AlignmentX="Left" AlignmentY="Center" Stretch="None">
|
||||
<VisualBrush.Visual>
|
||||
<TextBlock Text="输入前缀" Foreground="Gray" Margin="5,0,0,0" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</TextBox.Resources>
|
||||
<TextBox.Style>
|
||||
<Style TargetType="TextBox">
|
||||
<Setter Property="Background" Value="White" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Text" Value="">
|
||||
<Setter Property="Background" Value="{StaticResource HintText}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBox.Style>
|
||||
</TextBox>
|
||||
<Button Content="应用前缀"
|
||||
Command="{Binding ApplySamePrefixCommand}"
|
||||
CommandParameter="{Binding Text, ElementName=PrefixTextBox}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ui:ContentDialog>
|
||||
@@ -1,13 +1,29 @@
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DMS.WPF.Views.Dialogs;
|
||||
|
||||
public partial class MqttAliasBatchEditDialog : ContentDialog
|
||||
namespace DMS.WPF.Views.Dialogs
|
||||
{
|
||||
public MqttAliasBatchEditDialog(MqttAliasBatchEditDialogViewModel viewModel)
|
||||
/// <summary>
|
||||
/// MqttAliasBatchEditDialog.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MqttAliasBatchEditDialog : ContentDialog
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
public MqttAliasBatchEditDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,37 @@
|
||||
<controls:ContentDialog x:Class="DMS.WPF.Views.Dialogs.MqttSelectionDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:controls="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance vm:MqttSelectionDialogViewModel}"
|
||||
Title="选择MQTT服务器"
|
||||
PrimaryButtonText="确定"
|
||||
SecondaryButtonText="取消"
|
||||
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
|
||||
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">
|
||||
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.MqttSelectionDialog"
|
||||
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
d:DataContext="{d:DesignInstance vmd:MqttSelectionDialogViewModel}"
|
||||
Title="选择MQTT服务器"
|
||||
PrimaryButtonText="确定"
|
||||
CloseButtonText="取消"
|
||||
PrimaryButtonCommand="{Binding ConfirmCommand}"
|
||||
CloseButtonCommand="{Binding CloseCommand}"
|
||||
DefaultButton="Primary"
|
||||
mc:Ignorable="d"
|
||||
>
|
||||
|
||||
<Grid>
|
||||
<ListBox ItemsSource="{Binding Mqtts}"
|
||||
SelectedItem="{Binding SelectedMqtt}"
|
||||
DisplayMemberPath="Name" />
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="请选择要关联的MQTT服务器:"
|
||||
Margin="0,0,0,10"
|
||||
Style="{StaticResource BodyTextBlockStyle}" />
|
||||
|
||||
<ListBox Grid.Row="1"
|
||||
ItemsSource="{Binding MqttServers}"
|
||||
SelectedItem="{Binding SelectedMqttServer}"
|
||||
DisplayMemberPath="ServerName"
|
||||
MinHeight="200"
|
||||
MaxHeight="400" />
|
||||
</Grid>
|
||||
</controls:ContentDialog>
|
||||
</ui:ContentDialog>
|
||||
@@ -1,29 +1,29 @@
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace DMS.WPF.Views.Dialogs;
|
||||
|
||||
public partial class MqttSelectionDialog : ContentDialog
|
||||
namespace DMS.WPF.Views.Dialogs
|
||||
{
|
||||
public MqttSelectionDialog(MqttSelectionDialogViewModel viewModel)
|
||||
/// <summary>
|
||||
/// MqttSelectionDialog.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class MqttSelectionDialog : ContentDialog
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
// 在这里可以添加一些验证逻辑,例如确保选择了MQTT服务器
|
||||
// var viewModel = (MqttSelectionDialogViewModel)DataContext;
|
||||
// if (viewModel.SelectedMqtt == null)
|
||||
// {
|
||||
// args.Cancel = true; // 取消关闭对话框
|
||||
// // 可以显示一个警告消息
|
||||
// }
|
||||
}
|
||||
|
||||
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
|
||||
{
|
||||
// 用户点击取消,不需要额外处理
|
||||
public MqttSelectionDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user