diff --git a/App.xaml.cs b/App.xaml.cs index fab722e..1c09666 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.Config; using PMSWPF.ViewModels.Dialogs; using SqlSugar; using LogLevel = Microsoft.Extensions.Logging.LogLevel; @@ -81,8 +82,14 @@ public partial class App : Application services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddHostedService(); // Register as HostedService - services.AddHostedService(); + if (ConnectionSettings.Load().EnableS7Service) + { + services.AddHostedService(); // Register as HostedService + } + if (ConnectionSettings.Load().EnableMqttService) + { + services.AddHostedService(); + } services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/Config/ConnectionSettings.cs b/Config/ConnectionSettings.cs index feecc4f..e96efcf 100644 --- a/Config/ConnectionSettings.cs +++ b/Config/ConnectionSettings.cs @@ -12,6 +12,8 @@ namespace PMSWPF.Config public string UserId { get; set; } = "root"; public string Password { get; set; } = "Pgw15221236646"; public string Database { get; set; } = "pmswpf"; + public bool EnableS7Service { get; set; } = true; + public bool EnableMqttService { get; set; } = true; private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "connectionSettings.json"); diff --git a/ViewModels/Dialogs/IsActiveDialogViewModel.cs b/ViewModels/Dialogs/IsActiveDialogViewModel.cs new file mode 100644 index 0000000..1628186 --- /dev/null +++ b/ViewModels/Dialogs/IsActiveDialogViewModel.cs @@ -0,0 +1,28 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using PMSWPF.Enums; + +namespace PMSWPF.ViewModels.Dialogs; + +public partial class IsActiveDialogViewModel : ObservableObject +{ + [ObservableProperty] + private bool? _selectedIsActive; + + public IsActiveDialogViewModel(bool? currentIsActive) + { + _selectedIsActive = currentIsActive; + } + + [RelayCommand] + private void SelectIsActive(bool isActive) + { + SelectedIsActive = isActive; + } + + [RelayCommand] + private void Cancel() + { + SelectedIsActive = null; + } +} \ No newline at end of file diff --git a/ViewModels/SettingViewModel.cs b/ViewModels/SettingViewModel.cs index 0314195..280f670 100644 --- a/ViewModels/SettingViewModel.cs +++ b/ViewModels/SettingViewModel.cs @@ -106,6 +106,34 @@ public partial class SettingViewModel : ViewModelBase } } + public bool EnableS7Service + { + get => _connectionSettings.EnableS7Service; + set + { + if (_connectionSettings.EnableS7Service != value) + { + _connectionSettings.EnableS7Service = value; + OnPropertyChanged(); + _connectionSettings.Save(); + } + } + } + + public bool EnableMqttService + { + get => _connectionSettings.EnableMqttService; + set + { + if (_connectionSettings.EnableMqttService != value) + { + _connectionSettings.EnableMqttService = value; + OnPropertyChanged(); + _connectionSettings.Save(); + } + } + } + [RelayCommand] private async Task TestConnection() { diff --git a/Views/Dialogs/IsActiveDialog.xaml b/Views/Dialogs/IsActiveDialog.xaml new file mode 100644 index 0000000..f666194 --- /dev/null +++ b/Views/Dialogs/IsActiveDialog.xaml @@ -0,0 +1,22 @@ + + + + + + + + + \ No newline at end of file diff --git a/Views/Dialogs/IsActiveDialog.xaml.cs b/Views/Dialogs/IsActiveDialog.xaml.cs new file mode 100644 index 0000000..a2fe762 --- /dev/null +++ b/Views/Dialogs/IsActiveDialog.xaml.cs @@ -0,0 +1,33 @@ +using System.Windows; +using iNKORE.UI.WPF.Modern.Controls; +using PMSWPF.ViewModels.Dialogs; + +namespace PMSWPF.Views.Dialogs; + +public partial class IsActiveDialog : ContentDialog +{ + public IsActiveDialogViewModel ViewModel { get; } + + public IsActiveDialog(IsActiveDialogViewModel viewModel) + { + InitializeComponent(); + ViewModel = viewModel; + DataContext = ViewModel; + } + + private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + // 确认按钮点击时,ViewModel.SelectedIsActive 已经通过绑定更新 + // 如果用户没有选择任何选项,可以阻止关闭对话框 + if (!ViewModel.SelectedIsActive.HasValue) + { + args.Cancel = true; + } + } + + private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + // 取消按钮点击时,将 SelectedIsActive 设置为 null + ViewModel.SelectedIsActive = null; + } +} \ No newline at end of file diff --git a/Views/SettingView.xaml b/Views/SettingView.xaml index a24e621..7f901c9 100644 --- a/Views/SettingView.xaml +++ b/Views/SettingView.xaml @@ -108,6 +108,25 @@ + + + + + + + + + + + + + +