初步完成变量历史记录修改
This commit is contained in:
@@ -294,6 +294,7 @@ public partial class App : System.Windows.Application
|
||||
services.AddTransient<MqttDialogViewModel>();
|
||||
services.AddTransient<MqttSelectionDialogViewModel>();
|
||||
services.AddTransient<MqttAliasBatchEditDialogViewModel>();
|
||||
services.AddTransient<HistorySettingsDialogViewModel>();
|
||||
|
||||
// 注册View视图
|
||||
services.AddSingleton<SplashWindow>();
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
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>
|
||||
/// 当变量表的启用/禁用状态改变时调用。
|
||||
/// 更新数据库中变量表的激活状态,并显示相应的通知。
|
||||
|
||||
48
DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml
Normal file
48
DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml
Normal file
@@ -0,0 +1,48 @@
|
||||
<ui:ContentDialog
|
||||
x:Class="DMS.WPF.Views.Dialogs.HistorySettingsDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
|
||||
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
Title="{Binding Title}"
|
||||
d:DataContext="{d:DesignInstance vmd:HistorySettingsDialogViewModel}"
|
||||
CloseButtonCommand="{Binding CancleButtonCommand}"
|
||||
CloseButtonText="取消"
|
||||
PrimaryButtonCommand="{Binding PrimaryButtonCommand}"
|
||||
PrimaryButtonText="{Binding PrimaryButText}"
|
||||
mc:Ignorable="d">
|
||||
<ui:ContentDialog.Resources>
|
||||
<valueConverts:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||
</ui:ContentDialog.Resources>
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<CheckBox
|
||||
Grid.Row="0"
|
||||
Margin="0,10"
|
||||
Content="启用历史记录"
|
||||
IsChecked="{Binding IsHistoryEnabled}" />
|
||||
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Margin="0,10"
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
Text="历史记录死区值: " />
|
||||
<TextBox
|
||||
Width="100"
|
||||
Margin="10,0"
|
||||
Text="{Binding HistoryDeadband}" />
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
Text="(当值变化超过此值时才记录)" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ui:ContentDialog>
|
||||
21
DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs
Normal file
21
DMS.WPF/Views/Dialogs/HistorySettingsDialog.xaml.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,11 +209,20 @@
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
|
||||
<MenuItem
|
||||
Command="{Binding ChangeHistorySettingsCommand}"
|
||||
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
|
||||
Header="修改历史记录">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
|
||||
<MenuItem
|
||||
Command="{Binding ToHistoryCommand}"
|
||||
Header="查看历史记录">
|
||||
<MenuItem.Icon>
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Add}" />
|
||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.History}" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
|
||||
Reference in New Issue
Block a user