完成修改更新频率

This commit is contained in:
2025-09-02 17:42:11 +08:00
parent 6d7636d664
commit 94aa9b0485
8 changed files with 118 additions and 54 deletions

View File

@@ -20,6 +20,7 @@ namespace DMS.WPF.Services
{ typeof(ImportExcelDialogViewModel), typeof(ImportExcelDialog) },
{ typeof(ImportOpcUaDialogViewModel), typeof(ImportOpcUaDialog) },
{ typeof(VariableDialogViewModel), typeof(VariableDialog) },
{ typeof(PollLevelDialogViewModel), typeof(PollLevelDialog) },
// { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here
// ... other dialogs
};

View File

@@ -2,11 +2,12 @@ using System;
using System.Collections.Generic;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Enums;
namespace DMS.WPF.ViewModels.Dialogs
{
public partial class PollLevelDialogViewModel : ObservableObject
public partial class PollLevelDialogViewModel : DialogViewModelBase<PollLevelType?>
{
[ObservableProperty]
private PollLevelType _selectedPollLevelType;
@@ -17,6 +18,20 @@ namespace DMS.WPF.ViewModels.Dialogs
{
PollLevelTypes = Enum.GetValues(typeof(PollLevelType)).Cast<PollLevelType>().ToList();
SelectedPollLevelType = currentPollLevelType;
Title = "修改轮询频率";
PrimaryButText = "确定";
}
[RelayCommand]
private void PrimaryButton()
{
Close(SelectedPollLevelType);
}
[RelayCommand]
private void CancleButton()
{
Close(null);
}
}
}

View File

@@ -277,7 +277,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
{
try
{
if (CurrentVariableTable.Device==null)
if (CurrentVariableTable.Device == null)
{
NotificationHelper.ShowError("当前变量表的Device对象为空请检查。");
return;
@@ -454,37 +454,44 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
/// </summary>
/// <param name="variablesToChange">要修改轮询频率的变量数据列表。</param>
[RelayCommand]
public async Task ChangePollLevel(IList<object> variablesToChange)
public async Task ChangePollLevel()
{
// var validVariables = variablesToChange?.OfType<Variable>()
// .ToList();
//
// // 检查是否有变量被选中
// if (validVariables == null || !validVariables.Any())
// {
// NotificationHelper.ShowInfo("请选择要修改轮询频率的变量");
// return;
// }
//
// // 显示轮询频率选择对话框,并传入第一个变量的当前轮询频率作为默认值
// var newPollLevelType = await _dialogService.ShowPollLevelDialog(validVariables.First()
// .PollLevelType);
// if (newPollLevelType.HasValue)
// {
// // 更新所有选定变量的轮询频率和修改状态
// foreach (var variable in validVariables)
// {
// variable.PollLevelType = newPollLevelType.Value;
// variable.IsModified = false; // 标记为未修改,因为已保存到数据库
// }
//
// // 批量更新数据库中的变量数据
// await _varDataRepository.UpdateAsync(validVariables);
//
// await RefreshDataView();
// // 显示成功通知
// NotificationHelper.ShowSuccess($"已成功更新 {validVariables.Count} 个变量的轮询频率");
// }
// 检查是否有变量被选中
if (SelectedVariables.Count == 0)
{
NotificationHelper.ShowInfo("请选择要修改轮询频率的变量");
return;
}
// 获取选中的变量列表
var validVariables = SelectedVariables.Cast<VariableItemViewModel>().ToList();
// 显示轮询频率选择对话框,并传入第一个变量的当前轮询频率作为默认值
PollLevelDialogViewModel viewModel = new PollLevelDialogViewModel(validVariables.First().PollLevel);
var newPollLevelType = await _dialogService.ShowDialogAsync(viewModel);
if (newPollLevelType.HasValue)
{
// 更新所有选定变量的轮询频率和修改状态
foreach (var variable in validVariables)
{
variable.PollLevel = newPollLevelType.Value;
variable.UpdatedAt = DateTime.Now;
}
// 批量更新数据库中的变量数据
var variableDtos = _mapper.Map<List<VariableDto>>(validVariables);
var result = await _variableAppService.UpdateVariablesAsync(variableDtos);
if (result > 0)
{
// 显示成功通知
NotificationHelper.ShowSuccess($"已成功更新 {validVariables.Count} 个变量的轮询频率");
}
else
{
NotificationHelper.ShowError("更新轮询频率失败");
}
}
}
/// <summary>

View File

@@ -1,28 +1,30 @@
<ui:ContentDialog x:Class="DMS.WPF.Views.Dialogs.PollLevelDialog"
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:enums="clr-namespace:DMS.Core.Enums"
xmlns:extensions="clr-namespace:DMS.Extensions"
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
xmlns:valueConverts="clr-namespace:DMS.WPF.ValueConverts"
mc:Ignorable="d"
Title="修改轮询频率"
PrimaryButtonText="确定"
CloseButtonText="取消"
d:DesignHeight="150" d:DesignWidth="300">
<ui:ContentDialog
x:Class="DMS.WPF.Views.Dialogs.PollLevelDialog"
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:PollLevelDialogViewModel}"
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>
<ComboBox
ItemsSource="{Binding PollLevelTypes}"
SelectedItem="{Binding SelectedPollLevelType}"
Margin="20">
<ComboBox
Margin="20"
ItemsSource="{Binding PollLevelTypes}"
SelectedItem="{Binding SelectedPollLevelType}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"/>
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

View File

@@ -5,10 +5,9 @@ namespace DMS.WPF.Views.Dialogs
{
public partial class PollLevelDialog : ContentDialog
{
public PollLevelDialog(PollLevelDialogViewModel viewModel)
public PollLevelDialog()
{
InitializeComponent();
DataContext = viewModel;
}
}
}

View File

@@ -148,7 +148,7 @@
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding AddVarDataCommand}" Header="添加变量">
<MenuItem Command="{Binding AddVariableCommand}" Header="添加变量">
<MenuItem.Icon>
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Add}" />
</MenuItem.Icon>