diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs index a33c081..41a8334 100644 --- a/DMS.WPF/App.xaml.cs +++ b/DMS.WPF/App.xaml.cs @@ -295,6 +295,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 536bf10..bb49052 100644 --- a/DMS.WPF/Services/DialogService.cs +++ b/DMS.WPF/Services/DialogService.cs @@ -26,7 +26,8 @@ namespace DMS.WPF.Services { typeof(MqttDialogViewModel), typeof(MqttDialog) }, { typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) }, { typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) }, - { typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) } + { typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) }, + { typeof(AlarmSettingsDialogViewModel), typeof(AlarmSettingsDialog) } // Add other mappings here // ... other dialogs }; diff --git a/DMS.WPF/ViewModels/Dialogs/AlarmSettingsDialogViewModel.cs b/DMS.WPF/ViewModels/Dialogs/AlarmSettingsDialogViewModel.cs new file mode 100644 index 0000000..d084e4c --- /dev/null +++ b/DMS.WPF/ViewModels/Dialogs/AlarmSettingsDialogViewModel.cs @@ -0,0 +1,51 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; + +namespace DMS.WPF.ViewModels.Dialogs +{ + public partial class AlarmSettingsDialogViewModel : DialogViewModelBase + { + [ObservableProperty] + private bool _isAlarmEnabled; + + [ObservableProperty] + private double _alarmMinValue; + + [ObservableProperty] + private double _alarmMaxValue; + + public AlarmSettingsDialogViewModel(bool currentIsAlarmEnabled, double currentAlarmMinValue, double currentAlarmMaxValue) + { + IsAlarmEnabled = currentIsAlarmEnabled; + AlarmMinValue = currentAlarmMinValue; + AlarmMaxValue = currentAlarmMaxValue; + Title = "修改报警设置"; + PrimaryButText = "确定"; + } + + [RelayCommand] + private void PrimaryButton() + { + var result = new AlarmSettingsResult + { + IsAlarmEnabled = IsAlarmEnabled, + AlarmMinValue = AlarmMinValue, + AlarmMaxValue = AlarmMaxValue + }; + Close(result); + } + + [RelayCommand] + private void CancleButton() + { + Close(null); + } + } + + public class AlarmSettingsResult + { + public bool IsAlarmEnabled { get; set; } + public double AlarmMinValue { get; set; } + public double AlarmMaxValue { get; set; } + } +} \ No newline at end of file diff --git a/DMS.WPF/ViewModels/VariableTableViewModel.cs b/DMS.WPF/ViewModels/VariableTableViewModel.cs index f62a93e..234ddb4 100644 --- a/DMS.WPF/ViewModels/VariableTableViewModel.cs +++ b/DMS.WPF/ViewModels/VariableTableViewModel.cs @@ -764,6 +764,57 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable } } + /// + /// 修改选定变量的报警设置。 + /// + [RelayCommand] + public async Task ChangeAlarmSettings() + { + // 检查是否有变量被选中 + if (SelectedVariables.Count == 0) + { + _notificationService.ShowInfo("请选择要修改报警设置的变量"); + return; + } + + // 获取选中的变量列表 + var validVariables = SelectedVariables.Cast() + .ToList(); + + // 显示报警设置对话框,并传入第一个变量的当前报警设置作为默认值 + var viewModel = new AlarmSettingsDialogViewModel( + validVariables.First().IsAlarmEnabled, + validVariables.First().AlarmMinValue, + validVariables.First().AlarmMaxValue); + var result = await _dialogService.ShowDialogAsync(viewModel); + + if (result != null) + { + // 更新所有选定变量的报警设置 + foreach (var variable in validVariables) + { + variable.IsAlarmEnabled = result.IsAlarmEnabled; + variable.AlarmMinValue = result.AlarmMinValue; + variable.AlarmMaxValue = result.AlarmMaxValue; + 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/AlarmSettingsDialog.xaml b/DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml new file mode 100644 index 0000000..88ea741 --- /dev/null +++ b/DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml.cs b/DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml.cs new file mode 100644 index 0000000..647593d --- /dev/null +++ b/DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml.cs @@ -0,0 +1,21 @@ +using System.Windows; +using DMS.WPF.ViewModels.Dialogs; + +namespace DMS.WPF.Views.Dialogs +{ + /// <summary> + /// AlarmSettingsDialog.xaml 的交互逻辑 + /// </summary> + public partial class AlarmSettingsDialog + { + public AlarmSettingsDialog() + { + InitializeComponent(); + } + + public AlarmSettingsDialog(AlarmSettingsDialogViewModel viewModel) : this() + { + DataContext = viewModel; + } + } +} \ No newline at end of file diff --git a/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml index 023b080..92dc9af 100644 --- a/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml +++ b/DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml @@ -1,19 +1,19 @@ - + + diff --git a/DMS.WPF/Views/VariableTableView.xaml b/DMS.WPF/Views/VariableTableView.xaml index 9c1b11f..82f4b30 100644 --- a/DMS.WPF/Views/VariableTableView.xaml +++ b/DMS.WPF/Views/VariableTableView.xaml @@ -218,6 +218,14 @@ + + + + + +