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 @@ + + + + + + - +