- 新增 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 的映射关系
74 lines
3.1 KiB
C#
74 lines
3.1 KiB
C#
using DMS.WPF.Interfaces;
|
|
using DMS.WPF.ViewModels.Dialogs;
|
|
using DMS.WPF.Views.Dialogs;
|
|
using iNKORE.UI.WPF.Modern.Controls;
|
|
|
|
namespace DMS.WPF.Services
|
|
{
|
|
public class DialogService : IDialogService
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
private static readonly Dictionary<Type, Type> _viewModelViewMap = new Dictionary<Type, Type>
|
|
{
|
|
{ typeof(DeviceDialogViewModel), typeof(DeviceDialog) },
|
|
{ typeof(ConfirmDialogViewModel), typeof(ConfirmDialog) },
|
|
{ typeof(VariableTableDialogViewModel), typeof(VariableTableDialog) },
|
|
{ typeof(ImportExcelDialogViewModel), typeof(ImportExcelDialog) },
|
|
{ typeof(ImportOpcUaDialogViewModel), typeof(ImportOpcUaDialog) },
|
|
{ typeof(VariableDialogViewModel), typeof(VariableDialog) },
|
|
{ typeof(PollLevelDialogViewModel), typeof(PollLevelDialog) },
|
|
{ typeof(IsActiveDialogViewModel), typeof(IsActiveDialog) },
|
|
{ typeof(MqttDialogViewModel), typeof(MqttDialog) },
|
|
{ typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) },
|
|
{ typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) },
|
|
{ typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) },
|
|
{ typeof(AlarmSettingsDialogViewModel), typeof(AlarmSettingsDialog) },
|
|
{ typeof(EmailAccountDialogViewModel), typeof(EmailAccountDialog) },
|
|
{ typeof(EmailTemplateDialogViewModel), typeof(EmailTemplateDialog) },
|
|
{ typeof(TriggerDialogViewModel), typeof(TriggerDialog) },
|
|
{ typeof(InputDialogViewModel), typeof(InputDialog) }
|
|
// Add other mappings here
|
|
// ... other dialogs
|
|
};
|
|
|
|
public DialogService(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public async Task<TResult> ShowDialogAsync<TResult>(DialogViewModelBase<TResult> viewModel)
|
|
{
|
|
if (_viewModelViewMap.TryGetValue(viewModel.GetType(), out var viewType))
|
|
{
|
|
var tcs = new TaskCompletionSource<TResult>();
|
|
|
|
var dialog = (ContentDialog)_serviceProvider.GetService(viewType);
|
|
if (dialog == null)
|
|
{
|
|
// If not registered in DI, create an instance directly
|
|
dialog = (ContentDialog)Activator.CreateInstance(viewType);
|
|
}
|
|
|
|
dialog.DataContext = viewModel;
|
|
|
|
Func<TResult, Task> closeHandler = null;
|
|
closeHandler = async (result) =>
|
|
{
|
|
viewModel.CloseRequested -= closeHandler;
|
|
dialog.Hide();
|
|
tcs.SetResult(result);
|
|
};
|
|
|
|
viewModel.CloseRequested += closeHandler;
|
|
|
|
_ = await dialog.ShowAsync();
|
|
|
|
return await tcs.Task;
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException($"No view registered for view model {viewModel.GetType().Name}");
|
|
}
|
|
}
|
|
}
|
|
} |