初步完成变量历史记录修改
This commit is contained in:
47
DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs
Normal file
47
DMS.WPF/ViewModels/Dialogs/HistorySettingsDialogViewModel.cs
Normal file
@@ -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<HistorySettingsResult>
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
}
|
||||
@@ -715,6 +715,55 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
navigationService.NavigateToAsync(viewModel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改选定变量的历史记录设置。
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public async Task ChangeHistorySettings(IList<object> variablesToChange)
|
||||
{
|
||||
// 过滤出有效的VariableItemViewModel对象
|
||||
var validVariables = variablesToChange?.OfType<VariableItemViewModel>()
|
||||
.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<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