添加修改轮询时间的功能
This commit is contained in:
@@ -13,6 +13,7 @@ using PMSWPF.Services;
|
|||||||
using PMSWPF.ViewModels;
|
using PMSWPF.ViewModels;
|
||||||
using PMSWPF.Views;
|
using PMSWPF.Views;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using PMSWPF.ViewModels.Dialogs;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ public partial class VariableData : ObservableObject
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 轮询级别,例如1秒、5秒等。
|
/// 轮询级别,例如1秒、5秒等。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PollLevelType PollLevelType { get; set; } = PollLevelType.ThirtySeconds;
|
[ObservableProperty]
|
||||||
|
private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最后一次轮询时间。
|
/// 最后一次轮询时间。
|
||||||
@@ -148,4 +149,8 @@ public partial class VariableData : ObservableObject
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<Mqtt> Mqtts { get; set; }
|
public List<Mqtt> Mqtts { get; set; }
|
||||||
|
|
||||||
|
partial void OnPollLevelTypeChanged(PollLevelType value)
|
||||||
|
{
|
||||||
|
IsModified = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using HandyControl.Tools.Extension;
|
using HandyControl.Tools.Extension;
|
||||||
using iNKORE.UI.WPF.Modern.Controls;
|
using iNKORE.UI.WPF.Modern.Controls;
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
|
using PMSWPF.Enums;
|
||||||
using PMSWPF.Models;
|
using PMSWPF.Models;
|
||||||
using PMSWPF.ViewModels.Dialogs;
|
using PMSWPF.ViewModels.Dialogs;
|
||||||
using PMSWPF.Views.Dialogs;
|
using PMSWPF.Views.Dialogs;
|
||||||
@@ -158,4 +159,16 @@ public class DialogService :IDialogService
|
|||||||
_ = dialog.ShowAsync(); // 不await,让它在后台显示
|
_ = dialog.ShowAsync(); // 不await,让它在后台显示
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PollLevelType?> ShowPollLevelDialog(PollLevelType pollLevelType)
|
||||||
|
{
|
||||||
|
var vm = new PollLevelDialogViewModel(pollLevelType);
|
||||||
|
var dialog = new PollLevelDialog(vm);
|
||||||
|
var result = await dialog.ShowAsync();
|
||||||
|
if (result == ContentDialogResult.Primary)
|
||||||
|
{
|
||||||
|
return vm.SelectedPollLevelType;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using iNKORE.UI.WPF.Modern.Controls;
|
using iNKORE.UI.WPF.Modern.Controls;
|
||||||
|
using PMSWPF.Enums;
|
||||||
using PMSWPF.Models;
|
using PMSWPF.Models;
|
||||||
|
|
||||||
namespace PMSWPF.Services;
|
namespace PMSWPF.Services;
|
||||||
@@ -19,4 +20,6 @@ public interface IDialogService
|
|||||||
Task<VariableData> ShowEditVarDataDialog(VariableData variableData);
|
Task<VariableData> ShowEditVarDataDialog(VariableData variableData);
|
||||||
Task<string> ShowImportExcelDialog();
|
Task<string> ShowImportExcelDialog();
|
||||||
ContentDialog ShowProcessingDialog(string title, string message);
|
ContentDialog ShowProcessingDialog(string title, string message);
|
||||||
|
Task<PollLevelType?> ShowPollLevelDialog(PollLevelType pollLevelType);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -222,7 +222,7 @@ namespace PMSWPF.Services
|
|||||||
variable.DataValue = value.ToString();
|
variable.DataValue = value.ToString();
|
||||||
variable.DisplayValue = SiemensHelper.ConvertS7Value(value, variable.DataType, variable.Converstion);
|
variable.DisplayValue = SiemensHelper.ConvertS7Value(value, variable.DataType, variable.Converstion);
|
||||||
variable.LastPollTime = DateTime.Now; // 更新最后轮询时间
|
variable.LastPollTime = DateTime.Now; // 更新最后轮询时间
|
||||||
_logger.LogDebug($"线程ID:{Environment.CurrentManagedThreadId},已读取变量 {variable.Name}: {variable.DataValue}");
|
// _logger.LogDebug($"线程ID:{Environment.CurrentManagedThreadId},已读取变量 {variable.Name}: {variable.DataValue}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
22
ViewModels/Dialogs/PollLevelDialogViewModel.cs
Normal file
22
ViewModels/Dialogs/PollLevelDialogViewModel.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using PMSWPF.Enums;
|
||||||
|
|
||||||
|
namespace PMSWPF.ViewModels.Dialogs
|
||||||
|
{
|
||||||
|
public partial class PollLevelDialogViewModel : ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private PollLevelType _selectedPollLevelType;
|
||||||
|
|
||||||
|
public List<PollLevelType> PollLevelTypes { get; }
|
||||||
|
|
||||||
|
public PollLevelDialogViewModel(PollLevelType currentPollLevelType)
|
||||||
|
{
|
||||||
|
PollLevelTypes = Enum.GetValues(typeof(PollLevelType)).Cast<PollLevelType>().ToList();
|
||||||
|
SelectedPollLevelType = currentPollLevelType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -253,6 +253,24 @@ partial class VariableTableViewModel : ViewModelBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
private async Task ChangePollLevel()
|
||||||
|
{
|
||||||
|
if (SelectedVariableData == null)
|
||||||
|
{
|
||||||
|
NotificationHelper.ShowMessage("请选择一个变量", NotificationType.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newPollLevelType = await _dialogService.ShowPollLevelDialog(SelectedVariableData.PollLevelType);
|
||||||
|
if (newPollLevelType.HasValue)
|
||||||
|
{
|
||||||
|
SelectedVariableData.PollLevelType = newPollLevelType.Value;
|
||||||
|
await _varDataRepository.UpdateAsync(SelectedVariableData);
|
||||||
|
NotificationHelper.ShowMessage($"变量 {SelectedVariableData.Name} 的轮询频率已更新", NotificationType.Success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// [RelayCommand]
|
// [RelayCommand]
|
||||||
// private async void ImportFromExcel()
|
// private async void ImportFromExcel()
|
||||||
// {
|
// {
|
||||||
|
|||||||
30
Views/Dialogs/PollLevelDialog.xaml
Normal file
30
Views/Dialogs/PollLevelDialog.xaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<ui:ContentDialog x:Class="PMSWPF.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:PMSWPF.Enums"
|
||||||
|
xmlns:extensions="clr-namespace:PMSWPF.Extensions"
|
||||||
|
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||||
|
xmlns:vc="clr-namespace:PMSWPF.ValueConverts"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="修改轮询频率"
|
||||||
|
PrimaryButtonText="确定"
|
||||||
|
CloseButtonText="取消"
|
||||||
|
d:DesignHeight="150" d:DesignWidth="300">
|
||||||
|
<ui:ContentDialog.Resources>
|
||||||
|
<vc:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||||
|
</ui:ContentDialog.Resources>
|
||||||
|
<Grid>
|
||||||
|
<ComboBox
|
||||||
|
ItemsSource="{Binding PollLevelTypes}"
|
||||||
|
SelectedItem="{Binding SelectedPollLevelType}"
|
||||||
|
Margin="20">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
</Grid>
|
||||||
|
</ui:ContentDialog>
|
||||||
@@ -21,6 +21,8 @@
|
|||||||
<ex:EnumBindingSource x:Key="protocolType"
|
<ex:EnumBindingSource x:Key="protocolType"
|
||||||
EnumType="{x:Type en:ProtocolType}" />
|
EnumType="{x:Type en:ProtocolType}" />
|
||||||
<vc:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
<vc:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||||
|
<ex:EnumBindingSource x:Key="pollLevelType"
|
||||||
|
EnumType="{x:Type en:PollLevelType}" />
|
||||||
|
|
||||||
<!-- 标签字体的样式 -->
|
<!-- 标签字体的样式 -->
|
||||||
<Style TargetType="TextBlock"
|
<Style TargetType="TextBlock"
|
||||||
@@ -183,6 +185,12 @@
|
|||||||
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Import}" />
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Import}" />
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
<MenuItem Header="修改轮询频率"
|
||||||
|
Command="{Binding ChangePollLevelCommand}">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Edit}" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</DataGrid.ContextMenu>
|
</DataGrid.ContextMenu>
|
||||||
<DataGrid.RowStyle>
|
<DataGrid.RowStyle>
|
||||||
@@ -250,6 +258,25 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</DataGridTemplateColumn.CellEditingTemplate>
|
</DataGridTemplateColumn.CellEditingTemplate>
|
||||||
</DataGridTemplateColumn>
|
</DataGridTemplateColumn>
|
||||||
|
<DataGridTemplateColumn Header="轮询频率">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding PollLevelType, Converter={StaticResource EnumDescriptionConverter}}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataGridTemplateColumn.CellEditingTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<ComboBox ItemsSource="{Binding Source={StaticResource pollLevelType}}"
|
||||||
|
SelectedItem="{Binding PollLevelType}">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellEditingTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
<DataGridTextColumn IsReadOnly="True"
|
<DataGridTextColumn IsReadOnly="True"
|
||||||
Header="S7地址"
|
Header="S7地址"
|
||||||
Binding="{Binding S7Address}" />
|
Binding="{Binding S7Address}" />
|
||||||
@@ -284,4 +311,4 @@
|
|||||||
</DataGrid>
|
</DataGrid>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
Reference in New Issue
Block a user