diff --git a/App.xaml.cs b/App.xaml.cs
index 8b5455c..a6cc4a5 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -13,6 +13,7 @@ using PMSWPF.Services;
using PMSWPF.ViewModels;
using PMSWPF.Views;
using Microsoft.Extensions.Hosting;
+using PMSWPF.ViewModels.Dialogs;
using SqlSugar;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
diff --git a/Models/VariableData.cs b/Models/VariableData.cs
index 2d6cc2f..fd15096 100644
--- a/Models/VariableData.cs
+++ b/Models/VariableData.cs
@@ -81,7 +81,8 @@ public partial class VariableData : ObservableObject
///
/// 轮询级别,例如1秒、5秒等。
///
- public PollLevelType PollLevelType { get; set; } = PollLevelType.ThirtySeconds;
+ [ObservableProperty]
+ private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
///
/// 最后一次轮询时间。
@@ -148,4 +149,8 @@ public partial class VariableData : ObservableObject
///
public List Mqtts { get; set; }
+ partial void OnPollLevelTypeChanged(PollLevelType value)
+ {
+ IsModified = true;
+ }
}
\ No newline at end of file
diff --git a/Services/DialogService.cs b/Services/DialogService.cs
index 45b2abc..f3373ae 100644
--- a/Services/DialogService.cs
+++ b/Services/DialogService.cs
@@ -1,6 +1,7 @@
using HandyControl.Tools.Extension;
using iNKORE.UI.WPF.Modern.Controls;
using NPOI.SS.Formula.Functions;
+using PMSWPF.Enums;
using PMSWPF.Models;
using PMSWPF.ViewModels.Dialogs;
using PMSWPF.Views.Dialogs;
@@ -158,4 +159,16 @@ public class DialogService :IDialogService
_ = dialog.ShowAsync(); // 不await,让它在后台显示
return dialog;
}
+
+ public async Task 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;
+ }
}
\ No newline at end of file
diff --git a/Services/IDialogService.cs b/Services/IDialogService.cs
index 71ec6fb..96b8436 100644
--- a/Services/IDialogService.cs
+++ b/Services/IDialogService.cs
@@ -1,4 +1,5 @@
using iNKORE.UI.WPF.Modern.Controls;
+using PMSWPF.Enums;
using PMSWPF.Models;
namespace PMSWPF.Services;
@@ -19,4 +20,6 @@ public interface IDialogService
Task ShowEditVarDataDialog(VariableData variableData);
Task ShowImportExcelDialog();
ContentDialog ShowProcessingDialog(string title, string message);
+ Task ShowPollLevelDialog(PollLevelType pollLevelType);
+
}
\ No newline at end of file
diff --git a/Services/S7BackgroundService.cs b/Services/S7BackgroundService.cs
index bda4ac5..29c067c 100644
--- a/Services/S7BackgroundService.cs
+++ b/Services/S7BackgroundService.cs
@@ -222,7 +222,7 @@ namespace PMSWPF.Services
variable.DataValue = value.ToString();
variable.DisplayValue = SiemensHelper.ConvertS7Value(value, variable.DataType, variable.Converstion);
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)
diff --git a/ViewModels/Dialogs/PollLevelDialogViewModel.cs b/ViewModels/Dialogs/PollLevelDialogViewModel.cs
new file mode 100644
index 0000000..9d29644
--- /dev/null
+++ b/ViewModels/Dialogs/PollLevelDialogViewModel.cs
@@ -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 PollLevelTypes { get; }
+
+ public PollLevelDialogViewModel(PollLevelType currentPollLevelType)
+ {
+ PollLevelTypes = Enum.GetValues(typeof(PollLevelType)).Cast().ToList();
+ SelectedPollLevelType = currentPollLevelType;
+ }
+ }
+}
diff --git a/ViewModels/VariableTableViewModel.cs b/ViewModels/VariableTableViewModel.cs
index 906be53..07ffc2b 100644
--- a/ViewModels/VariableTableViewModel.cs
+++ b/ViewModels/VariableTableViewModel.cs
@@ -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]
// private async void ImportFromExcel()
// {
diff --git a/Views/Dialogs/PollLevelDialog.xaml b/Views/Dialogs/PollLevelDialog.xaml
new file mode 100644
index 0000000..7d7ebc2
--- /dev/null
+++ b/Views/Dialogs/PollLevelDialog.xaml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Views/VariableTableView.xaml b/Views/VariableTableView.xaml
index 14be491..8019985 100644
--- a/Views/VariableTableView.xaml
+++ b/Views/VariableTableView.xaml
@@ -21,6 +21,8 @@
+
+
@@ -250,6 +258,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -284,4 +311,4 @@
-
\ No newline at end of file
+