From c8d7543c7e036a204241efae1183231e0c662723 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Fri, 12 Sep 2025 08:57:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DMS.WPF/App.xaml.cs | 1 + DMS.WPF/Services/DialogService.cs | 3 +- .../Dialogs/HistorySettingsDialogViewModel.cs | 47 ++++++++++++++++++ DMS.WPF/ViewModels/VariableTableViewModel.cs | 49 +++++++++++++++++++ .../Views/Dialogs/HistorySettingsDialog.xaml | 48 ++++++++++++++++++ .../Dialogs/HistorySettingsDialog.xaml.cs | 21 ++++++++ DMS.WPF/Views/VariableTableView.xaml | 11 ++++- 7 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs create mode 100644 DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml create mode 100644 DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs index 7848d09..a33c081 100644 --- a/DMS.WPF/App.xaml.cs +++ b/DMS.WPF/App.xaml.cs @@ -294,6 +294,7 @@ public partial class App : System.Windows.Application services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); // 注册View视图 services.AddSingleton(); diff --git a/DMS.WPF/Services/DialogService.cs b/DMS.WPF/Services/DialogService.cs index 5fdb4bb..536bf10 100644 --- a/DMS.WPF/Services/DialogService.cs +++ b/DMS.WPF/Services/DialogService.cs @@ -25,7 +25,8 @@ namespace DMS.WPF.Services { typeof(IsActiveDialogViewModel), typeof(IsActiveDialog) }, { typeof(MqttDialogViewModel), typeof(MqttDialog) }, { typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) }, - { typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) } + { typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) }, + { typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) } // Add other mappings here // ... other dialogs }; diff --git a/DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs new file mode 100644 index 0000000..277ddb5 --- /dev/null +++ b/DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using System.Linq; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace DMS.WPF.ViewModels.Dialogs +{ + public partial class HistorySettingsDialogViewModel : DialogViewModelBase + { + [ObservableProperty] + private bool _isHistoryEnabled; + + [ObservableProperty] + private double _historyDeadband; + + public HistorySettingsDialogViewModel(bool currentIsHistoryEnabled, double currentHistoryDeadband) + { + IsHistoryEnabled = currentIsHistoryEnabled; + HistoryDeadband = currentHistoryDeadband; + Title = "修改历史记录设置"; + PrimaryButText = "确定"; + } + + [RelayCommand] + private void PrimaryButton() + { + var result = new HistorySettingsResult + { + IsHistoryEnabled = IsHistoryEnabled, + HistoryDeadband = HistoryDeadband + }; + Close(result); + } + + [RelayCommand] + private void CancleButton() + { + Close(null); + } + } + + public class HistorySettingsResult + { + public bool IsHistoryEnabled { get; set; } + public double HistoryDeadband { get; set; } + } +} \ No newline at end of file diff --git a/DMS.WPF/ViewModels/VariableTableViewModel.cs b/DMS.WPF/ViewModels/VariableTableViewModel.cs index 47b01ea..f62a93e 100644 --- a/DMS.WPF/ViewModels/VariableTableViewModel.cs +++ b/DMS.WPF/ViewModels/VariableTableViewModel.cs @@ -715,6 +715,55 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable navigationService.NavigateToAsync(viewModel); } + /// + /// 修改选定变量的历史记录设置。 + /// + [RelayCommand] + public async Task ChangeHistorySettings(IList variablesToChange) + { + // 过滤出有效的VariableItemViewModel对象 + var validVariables = variablesToChange?.OfType() + .ToList(); + + // 检查是否有变量被选中 + if (validVariables == null || !validVariables.Any()) + { + _notificationService.ShowInfo("请选择要修改历史记录设置的变量"); + return; + } + + // 显示历史记录设置对话框,并传入第一个变量的当前设置作为默认值 + var viewModel = new HistorySettingsDialogViewModel( + validVariables.First().IsHistoryEnabled, + validVariables.First().HistoryDeadband); + var result = await _dialogService.ShowDialogAsync(viewModel); + + if (result != null) + { + // 更新所有选定变量的历史记录设置 + foreach (var variable in validVariables) + { + variable.IsHistoryEnabled = result.IsHistoryEnabled; + variable.HistoryDeadband = result.HistoryDeadband; + variable.UpdatedAt = DateTime.Now; + } + + // 批量更新数据库中的变量数据 + var variableDtos = _mapper.Map>(validVariables); + var updateResult = await _variableAppService.UpdateVariablesAsync(variableDtos); + + if (updateResult > 0) + { + // 显示成功通知 + _notificationService.ShowSuccess($"已成功更新 {validVariables.Count} 个变量的历史记录设置"); + } + else + { + _notificationService.ShowError("更新历史记录设置失败"); + } + } + } + /// /// 当变量表的启用/禁用状态改变时调用。 /// 更新数据库中变量表的激活状态,并显示相应的通知。 diff --git a/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml new file mode 100644 index 0000000..023b080 --- /dev/null +++ b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs new file mode 100644 index 0000000..52632a8 --- /dev/null +++ b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs @@ -0,0 +1,21 @@ +using System.Windows; +using DMS.WPF.ViewModels.Dialogs; + +namespace DMS.WPF.Views.Dialogs +{ + /// <summary> + /// HistorySettingsDialog.xaml 的交互逻辑 + /// </summary> + public partial class HistorySettingsDialog + { + public HistorySettingsDialog() + { + InitializeComponent(); + } + + public HistorySettingsDialog(HistorySettingsDialogViewModel viewModel) : this() + { + DataContext = viewModel; + } + } +} \ No newline at end of file diff --git a/DMS.WPF/Views/VariableTableView.xaml b/DMS.WPF/Views/VariableTableView.xaml index 3b5a334..9c1b11f 100644 --- a/DMS.WPF/Views/VariableTableView.xaml +++ b/DMS.WPF/Views/VariableTableView.xaml @@ -209,11 +209,20 @@ + + + + + + - +