feat(mqtt): 实现MQTT别名批量修改功能
主要改动: - 在 MqttServerDetailView 中,允许用户在关联变量列表中进行多项选择。 - 修改了 ModifyAlias 命令,使其能够处理多个选中项,并调用批量编辑对话框。 - 新增了 MqttAliasBatchEditDialogViewModel 的构造函数,使其可以接收并编辑已存在的别名列表。 - 通过 SelectedItemsBehavior 辅助类,实现了 DataGrid 中 SelectedItems 的双向绑定。 - 更新了相关视图和视图模型,以支持新的批量操作流程。
This commit is contained in:
@@ -5,9 +5,10 @@ using DMS.Application.Interfaces;
|
||||
using DMS.Application.Interfaces.Management;
|
||||
using DMS.Core.Models;
|
||||
using DMS.WPF.Interfaces;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ItemViewModel;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace DMS.WPF.ViewModels
|
||||
@@ -39,6 +40,9 @@ namespace DMS.WPF.ViewModels
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<MqttAlias> _associatedVariables;
|
||||
|
||||
[ObservableProperty]
|
||||
private IList _selectedMqttAliaes = new ArrayList();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数。
|
||||
@@ -198,9 +202,9 @@ namespace DMS.WPF.ViewModels
|
||||
/// 修改变量的MQTT发送名称
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private async Task ModifyAlias(MqttAlias variableAlias)
|
||||
private async Task ModifyAlias()
|
||||
{
|
||||
if (variableAlias == null)
|
||||
if (SelectedMqttAliaes.Count == 0)
|
||||
{
|
||||
_notificationService.ShowError("请选择要修改的变量项。");
|
||||
return;
|
||||
@@ -208,38 +212,52 @@ namespace DMS.WPF.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
List<MqttAliasItem> selectedMqttAliaes = SelectedMqttAliaes.Cast<MqttAliasItem>().ToList();
|
||||
// 创建一个用于输入新名称的简单对话框
|
||||
var oldAlias = variableAlias.Alias;
|
||||
InputDialogViewModel viewModel = new InputDialogViewModel("修改发送名称", "请输入新的MQTT发送名称:", oldAlias);
|
||||
var dialogResult = await _dialogService.ShowDialogAsync(viewModel);
|
||||
|
||||
if (dialogResult != null) // 用户没有取消操作
|
||||
|
||||
MqttAliasBatchEditDialogViewModel viewModel = new MqttAliasBatchEditDialogViewModel(selectedMqttAliaes);
|
||||
var resMqttAliaes = await _dialogService.ShowDialogAsync(viewModel);
|
||||
|
||||
if (resMqttAliaes is null) // 用户没有取消操作
|
||||
{
|
||||
var newAlias = dialogResult.Trim();
|
||||
|
||||
if (string.IsNullOrEmpty(newAlias))
|
||||
return;
|
||||
}
|
||||
foreach (var item in resMqttAliaes)
|
||||
{
|
||||
foreach (var selectItem in selectedMqttAliaes)
|
||||
{
|
||||
_notificationService.ShowWarn("发送名称不能为空。");
|
||||
return;
|
||||
if (item.Id == selectItem.Id)
|
||||
{
|
||||
selectItem.Alias = item.Alias;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新变量的发送名称
|
||||
variableAlias.Alias = newAlias;
|
||||
|
||||
// 保存更改到数据服务
|
||||
// var result = await _wpfDataService.UpdateMqttServer(CurrentMqtt);
|
||||
//
|
||||
// if (result)
|
||||
// {
|
||||
// _notificationService.ShowSuccess($"变量 '{variableAlias.Variable.Name}' 的发送名称已更新为 '{newAlias}'");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _notificationService.ShowError("更新发送名称失败。");
|
||||
// // 如果更新失败,恢复原来的值
|
||||
// variableAlias.Alias = oldAlias;
|
||||
// }
|
||||
}
|
||||
|
||||
//var newAlias = dialogResult.Trim();
|
||||
|
||||
//if (string.IsNullOrEmpty(newAlias))
|
||||
//{
|
||||
// _notificationService.ShowWarn("发送名称不能为空。");
|
||||
// return;
|
||||
//}
|
||||
|
||||
//// 更新变量的发送名称
|
||||
//variableAlias.Alias = newAlias;
|
||||
|
||||
// 保存更改到数据服务
|
||||
// var result = await _wpfDataService.UpdateMqttServer(CurrentMqtt);
|
||||
//
|
||||
// if (result)
|
||||
// {
|
||||
// _notificationService.ShowSuccess($"变量 '{variableAlias.Variable.Name}' 的发送名称已更新为 '{newAlias}'");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _notificationService.ShowError("更新发送名称失败。");
|
||||
// // 如果更新失败,恢复原来的值
|
||||
// variableAlias.Alias = oldAlias;
|
||||
// }
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user