初步完成报警设置
This commit is contained in:
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>
|
||||
/// 当变量表的启用/禁用状态改变时调用。
|
||||
/// 更新数据库中变量表的激活状态,并显示相应的通知。
|
||||
|
||||
Reference in New Issue
Block a user