初步完成报警设置
This commit is contained in:
@@ -295,6 +295,7 @@ public partial class App : System.Windows.Application
|
|||||||
services.AddTransient<MqttSelectionDialogViewModel>();
|
services.AddTransient<MqttSelectionDialogViewModel>();
|
||||||
services.AddTransient<MqttAliasBatchEditDialogViewModel>();
|
services.AddTransient<MqttAliasBatchEditDialogViewModel>();
|
||||||
services.AddTransient<HistorySettingsDialogViewModel>();
|
services.AddTransient<HistorySettingsDialogViewModel>();
|
||||||
|
services.AddTransient<AlarmSettingsDialogViewModel>();
|
||||||
|
|
||||||
// 注册View视图
|
// 注册View视图
|
||||||
services.AddSingleton<SplashWindow>();
|
services.AddSingleton<SplashWindow>();
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ namespace DMS.WPF.Services
|
|||||||
{ typeof(MqttDialogViewModel), typeof(MqttDialog) },
|
{ typeof(MqttDialogViewModel), typeof(MqttDialog) },
|
||||||
{ typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) },
|
{ typeof(MqttSelectionDialogViewModel), typeof(MqttSelectionDialog) },
|
||||||
{ typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) },
|
{ typeof(MqttAliasBatchEditDialogViewModel), typeof(MqttAliasBatchEditDialog) },
|
||||||
{ typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) }
|
{ typeof(HistorySettingsDialogViewModel), typeof(HistorySettingsDialog) },
|
||||||
|
{ typeof(AlarmSettingsDialogViewModel), typeof(AlarmSettingsDialog) }
|
||||||
// Add other mappings here
|
// Add other mappings here
|
||||||
// ... other dialogs
|
// ... other dialogs
|
||||||
};
|
};
|
||||||
|
|||||||
51
DMS.WPF/ViewModels/Dialogs/AlarmSettingsDialogViewModel.cs
Normal file
51
DMS.WPF/ViewModels/Dialogs/AlarmSettingsDialogViewModel.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace DMS.WPF.ViewModels.Dialogs
|
||||||
|
{
|
||||||
|
public partial class AlarmSettingsDialogViewModel : DialogViewModelBase<AlarmSettingsResult>
|
||||||
|
{
|
||||||
|
[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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -764,6 +764,57 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 修改选定变量的报警设置。
|
||||||
|
/// </summary>
|
||||||
|
[RelayCommand]
|
||||||
|
public async Task ChangeAlarmSettings()
|
||||||
|
{
|
||||||
|
// 检查是否有变量被选中
|
||||||
|
if (SelectedVariables.Count == 0)
|
||||||
|
{
|
||||||
|
_notificationService.ShowInfo("请选择要修改报警设置的变量");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取选中的变量列表
|
||||||
|
var validVariables = SelectedVariables.Cast<VariableItemViewModel>()
|
||||||
|
.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<List<VariableDto>>(validVariables);
|
||||||
|
var updateResult = await _variableAppService.UpdateVariablesAsync(variableDtos);
|
||||||
|
|
||||||
|
if (updateResult > 0)
|
||||||
|
{
|
||||||
|
// 显示成功通知
|
||||||
|
_notificationService.ShowSuccess($"已成功更新 {validVariables.Count} 个变量的报警设置");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_notificationService.ShowError("更新报警设置失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当变量表的启用/禁用状态改变时调用。
|
/// 当变量表的启用/禁用状态改变时调用。
|
||||||
/// 更新数据库中变量表的激活状态,并显示相应的通知。
|
/// 更新数据库中变量表的激活状态,并显示相应的通知。
|
||||||
|
|||||||
66
DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml
Normal file
66
DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.AlarmSettingsDialog"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
|
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
|
||||||
|
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DataContext="{d:DesignInstance vmd:AlarmSettingsDialogViewModel}"
|
||||||
|
Title="{Binding Title}"
|
||||||
|
PrimaryButtonText="{Binding PrimaryButText}"
|
||||||
|
CloseButtonText="取消"
|
||||||
|
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
|
||||||
|
CloseButtonCommand="{Binding CancleButtonCommand}">
|
||||||
|
<ui:ContentDialog.Resources>
|
||||||
|
<valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||||
|
</ui:ContentDialog.Resources>
|
||||||
|
<Grid Margin="20">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
Grid.Row="0"
|
||||||
|
Margin="0,10"
|
||||||
|
Content="启用报警"
|
||||||
|
IsChecked="{Binding IsAlarmEnabled}" />
|
||||||
|
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="1"
|
||||||
|
Margin="0,10"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<TextBlock
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Text="报警最小值: " />
|
||||||
|
<TextBox
|
||||||
|
Width="100"
|
||||||
|
Margin="10,0"
|
||||||
|
Text="{Binding AlarmMinValue}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<StackPanel
|
||||||
|
Grid.Row="2"
|
||||||
|
Margin="0,10"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<TextBlock
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Text="报警最大值: " />
|
||||||
|
<TextBox
|
||||||
|
Width="100"
|
||||||
|
Margin="10,0"
|
||||||
|
Text="{Binding AlarmMaxValue}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock
|
||||||
|
Grid.Row="3"
|
||||||
|
Margin="0,10"
|
||||||
|
FontStyle="Italic"
|
||||||
|
Text="注意:最小值应小于最大值,否则可能导致报警异常" />
|
||||||
|
</Grid>
|
||||||
|
</ui:ContentDialog>
|
||||||
21
DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml.cs
Normal file
21
DMS.WPF/Views/Dialogs/AlarmSettingsDialog.xaml.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
<ui:ContentDialog
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
x:Class="DMS.WPF.Views.Dialogs.HistorySettingsDialog"
|
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.HistorySettingsDialog"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
|
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
|
||||||
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||||
Title="{Binding Title}"
|
mc:Ignorable="d"
|
||||||
d:DataContext="{d:DesignInstance vmd:HistorySettingsDialogViewModel}"
|
d:DataContext="{d:DesignInstance vmd:HistorySettingsDialogViewModel}"
|
||||||
CloseButtonCommand="{Binding CancleButtonCommand}"
|
Title="{Binding Title}"
|
||||||
CloseButtonText="取消"
|
PrimaryButtonText="{Binding PrimaryButText}"
|
||||||
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
|
CloseButtonText="取消"
|
||||||
PrimaryButtonText="{Binding PrimaryButText}"
|
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
|
||||||
mc:Ignorable="d">
|
CloseButtonCommand="{Binding CancleButtonCommand}">
|
||||||
<ui:ContentDialog.Resources>
|
<ui:ContentDialog.Resources>
|
||||||
<valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
<valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||||
</ui:ContentDialog.Resources>
|
</ui:ContentDialog.Resources>
|
||||||
|
|||||||
@@ -218,6 +218,14 @@
|
|||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
|
<MenuItem
|
||||||
|
Command="{Binding ChangeAlarmSettingsCommand}"
|
||||||
|
Header="修改报警设置">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem
|
<MenuItem
|
||||||
Command="{Binding ToHistoryCommand}"
|
Command="{Binding ToHistoryCommand}"
|
||||||
Header="查看历史记录">
|
Header="查看历史记录">
|
||||||
|
|||||||
Reference in New Issue
Block a user