功能增强:添加 InputDialog 并改进变量管理功能
- 新增 InputDialog 组件:
- 添加了 InputDialog.xaml 和 InputDialog.xaml.cs 文件
- 创建了 InputDialogViewModel.cs,继承自 DialogViewModelBase<string?>
- 实现了可重用的输入对话框,支持自定义标题、消息、标签和占位符
- 完善变量管理服务:
- 在 MappingProfile.cs 中添加了 VariableDto 到 VariableDto 的映射配置
- 在 VariableManagementService.cs 中注入 IMapper 依赖项
- 修改了 UpdateVariablesAsync 方法,使用 AutoMapper 进行更安全的更新操作
- 扩展变量表功能:
- 在 VariableTableViewModel.cs 中添加了 ModifyConversionFormula 命令
- 实现了批量修改变量转换公式功能,支持用户通过对话框输入新公式
- 添加了相应的 UI 通知和错误处理
- 在 VariableTableView.xaml 中添加了"修改数值转换公式"菜单项
- 集成 InputDialog 到对话框服务:
- 在 DialogService.cs 中注册了 InputDialogViewModel 和 InputDialog 的映射关系
This commit is contained in:
@@ -24,6 +24,8 @@ public class MappingProfile : Profile
|
||||
|
||||
CreateMap<VariableDto, Variable>()
|
||||
.ReverseMap();
|
||||
CreateMap<VariableDto, VariableDto>()
|
||||
.ReverseMap();
|
||||
|
||||
// MqttServer 映射
|
||||
CreateMap<MqttServer, MqttServerDto>().ReverseMap();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using AutoMapper;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Application.Events;
|
||||
using DMS.Application.Interfaces;
|
||||
@@ -15,17 +16,20 @@ public class VariableManagementService : IVariableManagementService
|
||||
{
|
||||
private readonly IVariableAppService _variableAppService;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IAppDataStorageService _appDataStorageService;
|
||||
private readonly IDataProcessingService _dataProcessingService;
|
||||
|
||||
|
||||
public VariableManagementService(IVariableAppService variableAppService,
|
||||
IEventService eventService,
|
||||
IMapper mapper,
|
||||
IAppDataStorageService appDataStorageService,
|
||||
IDataProcessingService dataProcessingService)
|
||||
{
|
||||
_variableAppService = variableAppService;
|
||||
_eventService = eventService;
|
||||
_mapper = mapper;
|
||||
_appDataStorageService = appDataStorageService;
|
||||
_dataProcessingService = dataProcessingService;
|
||||
}
|
||||
@@ -116,7 +120,12 @@ public class VariableManagementService : IVariableManagementService
|
||||
variableTableDto = variableTable;
|
||||
}
|
||||
|
||||
_appDataStorageService.Variables.AddOrUpdate(variableDto.Id, variableDto, (key, oldValue) => variableDto);
|
||||
if (_appDataStorageService.Variables.TryGetValue(variableDto.Id,out var mVariableDto))
|
||||
{
|
||||
_mapper.Map(variableDto, mVariableDto);
|
||||
}
|
||||
|
||||
// _appDataStorageService.Variables.AddOrUpdate(variableDto.Id, variableDto, (key, oldValue) => variableDto);
|
||||
_eventService.RaiseVariableChanged(
|
||||
this, new VariableChangedEventArgs(DataChangeType.Updated, variableDto, variableTableDto));
|
||||
}
|
||||
|
||||
@@ -25,7 +25,8 @@ namespace DMS.WPF.Services
|
||||
{ typeof(AlarmSettingsDialogViewModel), typeof(AlarmSettingsDialog) },
|
||||
{ typeof(EmailAccountDialogViewModel), typeof(EmailAccountDialog) },
|
||||
{ typeof(EmailTemplateDialogViewModel), typeof(EmailTemplateDialog) },
|
||||
{ typeof(TriggerDialogViewModel), typeof(TriggerDialog) }
|
||||
{ typeof(TriggerDialogViewModel), typeof(TriggerDialog) },
|
||||
{ typeof(InputDialogViewModel), typeof(InputDialog) }
|
||||
// Add other mappings here
|
||||
// ... other dialogs
|
||||
};
|
||||
|
||||
64
DMS.WPF/ViewModels/Dialogs/InputDialogViewModel.cs
Normal file
64
DMS.WPF/ViewModels/Dialogs/InputDialogViewModel.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class InputDialogViewModel : DialogViewModelBase<string?>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _message = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _inputLabel = "输入";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _inputPlaceholder = "请输入...";
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _inputText;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _primaryButtonText = "确定";
|
||||
|
||||
[ObservableProperty]
|
||||
private string _closeButtonText = "取消";
|
||||
|
||||
public InputDialogViewModel(string title, string message)
|
||||
{
|
||||
Title = title;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public InputDialogViewModel(string title, string message, string inputLabel) : this(title, message)
|
||||
{
|
||||
InputLabel = inputLabel;
|
||||
}
|
||||
|
||||
public InputDialogViewModel(string title, string message, string inputLabel, string inputPlaceholder) : this(title, message, inputLabel)
|
||||
{
|
||||
InputPlaceholder = inputPlaceholder;
|
||||
}
|
||||
|
||||
public InputDialogViewModel(string title, string message, string inputLabel, string inputPlaceholder, string? defaultValue) : this(title, message, inputLabel, inputPlaceholder)
|
||||
{
|
||||
InputText = defaultValue;
|
||||
}
|
||||
|
||||
public InputDialogViewModel()
|
||||
{
|
||||
Title = "输入";
|
||||
Message = "请输入信息:";
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
Close(InputText);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using DMS.Core.Events;
|
||||
using DMS.Core.Models;
|
||||
using DMS.WPF.Interfaces;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ObservableCollections;
|
||||
@@ -539,6 +540,48 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task ModifyConversionFormula()
|
||||
{
|
||||
// 检查是否有变量被选中
|
||||
if (SelectedVariables.Count == 0)
|
||||
{
|
||||
_notificationService.ShowInfo("请选择要修改转换公式的变量");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取选中的变量列表
|
||||
var validVariables = SelectedVariables.Cast<VariableItemViewModel>().ToList();
|
||||
|
||||
// --- 对话框调用 ---
|
||||
var viewModel = new InputDialogViewModel("修改数值转换公式", "请输入新的转换公式 (使用'x'代表变量值):", validVariables.First().ConversionFormula);
|
||||
string newFormula = await _dialogService.ShowDialogAsync(viewModel);
|
||||
|
||||
if (newFormula != null) // 当用户输入了新公式并确认后
|
||||
{
|
||||
// 更新所有选定变量的转换公式
|
||||
foreach (var variable in validVariables)
|
||||
{
|
||||
variable.ConversionFormula = newFormula;
|
||||
variable.UpdatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
// 批量更新数据库中的变量数据
|
||||
var variableDtos = _mapper.Map<List<VariableDto>>(validVariables);
|
||||
var result = await _variableManagementService.UpdateVariablesAsync(variableDtos);
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
// 显示成功通知
|
||||
_notificationService.ShowSuccess($"已成功更新 {validVariables.Count} 个变量的转换公式");
|
||||
}
|
||||
else
|
||||
{
|
||||
_notificationService.ShowError("更新转换公式失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 为选定的变量添加MQTT服务器。
|
||||
|
||||
25
DMS.WPF/Views/Dialogs/InputDialog.xaml
Normal file
25
DMS.WPF/Views/Dialogs/InputDialog.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<ui:ContentDialog
|
||||
x:Class="DMS.WPF.Views.Dialogs.InputDialog"
|
||||
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:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:vm="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance vm:InputDialogViewModel}"
|
||||
Title="{Binding Title}"
|
||||
PrimaryButtonText="{Binding PrimaryButtonText}"
|
||||
CloseButtonText="{Binding CloseButtonText}"
|
||||
PrimaryButtonCommand="{Binding ConfirmCommand}"
|
||||
CloseButtonCommand="{Binding CancelCommand}">
|
||||
<Grid>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBlock Text="{Binding Message}" Margin="0,0,0,10" TextWrapping="Wrap"/>
|
||||
<hc:TextBox Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
hc:InfoElement.Title="{Binding InputLabel}"
|
||||
hc:InfoElement.Placeholder="{Binding InputPlaceholder}"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ui:ContentDialog>
|
||||
11
DMS.WPF/Views/Dialogs/InputDialog.xaml.cs
Normal file
11
DMS.WPF/Views/Dialogs/InputDialog.xaml.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
|
||||
namespace DMS.WPF.Views.Dialogs;
|
||||
|
||||
public partial class InputDialog : ContentDialog
|
||||
{
|
||||
public InputDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,13 @@
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
Command="{Binding ModifyConversionFormulaCommand}"
|
||||
Header="修改数值转换公式">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
Command="{Binding ModifyOpcUaUpdateTypeCommand}"
|
||||
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
|
||||
|
||||
Reference in New Issue
Block a user