BusynessNotification

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7f680bada1f61293ec4a77a2a3ec985110afee32
parent 10c846c02ab0cd97a125cec88dc2e982f2084981
Author: Minerva_juppiter <ryouturn@gmail.com>
Date:   Thu, 21 Mar 2024 15:55:18 +0900

設定値の例外処理を追加

Diffstat:
MMainWindow.xaml.cs | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 57 insertions(+), 27 deletions(-)

diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs @@ -18,28 +18,45 @@ namespace BusynessNotification /// </summary> public partial class MainWindow : Window { + bool CheckCPU = true; + bool CheckMemory = true; + bool CheckDisk = true; + + double SliderCPU = 50; + double SliderMemory = 50; + double SliderDisk = 50; + + int SecCPU = 5; + int SecMemory = 5; + int SecDisk = 5; public MainWindow() { InitializeComponent(); ///設定値の読み取り - bool CheckCPU = Properties.Settings.Default.CheckCPU; - bool CheckMemory = Properties.Settings.Default.CheckMemory; - bool CheckDisk = Properties.Settings.Default.CheckDisk; - - double SliderCPU = Properties.Settings.Default.SliderCPU; - double SliderMemory = Properties.Settings.Default.SliderMemory; - double SliderDisk = Properties.Settings.Default.SliderDisk; - - int SecCPU = Properties.Settings.Default.SecCPU; - int SecMemory = Properties.Settings.Default.SecMemory; - int SecDisk = Properties.Settings.Default.SecDisk; try { CheckCPU = Properties.Settings.Default.CheckCPU; CheckMemory = Properties.Settings.Default.CheckMemory; CheckDisk = Properties.Settings.Default.CheckDisk; + + SliderCPU = Properties.Settings.Default.SliderCPU; + SliderMemory = Properties.Settings.Default.SliderMemory; + SliderDisk = Properties.Settings.Default.SliderDisk; + + SecCPU = Properties.Settings.Default.SecCPU; + SecMemory = Properties.Settings.Default.SecMemory; + SecDisk = Properties.Settings.Default.SecDisk; + }catch (Exception) + { + string messageBoxText = "Please try to set this app expect on secur app"; + string caption = "Failed to get setting"; + MessageBoxButton button = MessageBoxButton.OK; + MessageBoxImage icon = MessageBoxImage.Warning; + MessageBoxResult result; + + result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); } ///取得した値をUIに適応 @@ -69,12 +86,12 @@ namespace BusynessNotification private void TextBox_CPUSlider_TextChanged(object sender, TextChangedEventArgs e) { - TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text,Properties.Settings.Default.SliderCPU).ToString(); + TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text,SliderCPU).ToString(); } private void TextBox_MemorySlider_TextChanged(object sender, TextChangedEventArgs e) { - TextBox_MemorySlider.Text = InputNormalizerToDouble(TextBox_MemorySlider.Text,Properties.Settings.Default.SliderMemory).ToString(); + TextBox_MemorySlider.Text = InputNormalizerToDouble(TextBox_MemorySlider.Text,SliderMemory).ToString(); } private void MemorySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e) @@ -93,39 +110,52 @@ namespace BusynessNotification private void TextBox_DiskSlider_TextChanged(object sender, TextChangedEventArgs e) { - TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text.ToString(), Properties.Settings.Default.SliderDisk).ToString(); + TextBox_CPUSlider.Text = InputNormalizerToDouble(TextBox_CPUSlider.Text.ToString(), SliderDisk).ToString(); } private void CPUSecTextBox_TextChanged(object sender, TextChangedEventArgs e) { - CPUSecTextBox.Text = InputNormalizerToDouble(CPUSecTextBox.Text,Properties.Settings.Default.SecCPU).ToString(); + CPUSecTextBox.Text = InputNormalizerToDouble(CPUSecTextBox.Text,SecCPU).ToString(); } private void MemorySecTextBox_TextChanged(object sender, TextChangedEventArgs e) { - MemorySecTextBox.Text = InputNormalizerToDouble(MemorySecTextBox.Text.ToString(), Properties.Settings.Default.SecMemory).ToString(); + MemorySecTextBox.Text = InputNormalizerToDouble(MemorySecTextBox.Text.ToString(), SecMemory).ToString(); } private void DiskSecTextBox_TextChanged(object sender, TextChangedEventArgs e) { - DiskSecTextBox.Text = InputNormalizerToDouble(DiskSecTextBox.Text.ToString(), Properties.Settings.Default.SecDisk).ToString(); + DiskSecTextBox.Text = InputNormalizerToDouble(DiskSecTextBox.Text.ToString(), SecDisk).ToString(); } private void SaveSettingButton_Click(object sender, RoutedEventArgs e) { - Properties.Settings.Default.CheckCPU = CPUcheck.IsChecked.Value; - Properties.Settings.Default.CheckMemory = Memorycheck.IsChecked.Value; - Properties.Settings.Default.CheckDisk = Diskcheck.IsChecked.Value; + try + { + Properties.Settings.Default.CheckCPU = CPUcheck.IsChecked.Value; + Properties.Settings.Default.CheckMemory = Memorycheck.IsChecked.Value; + Properties.Settings.Default.CheckDisk = Diskcheck.IsChecked.Value; - Properties.Settings.Default.SliderCPU = CPUSlider.Value; - Properties.Settings.Default.SliderMemory = MemorySlider.Value; - Properties.Settings.Default.SliderDisk = DiskSlider.Value; + Properties.Settings.Default.SliderCPU = CPUSlider.Value; + Properties.Settings.Default.SliderMemory = MemorySlider.Value; + Properties.Settings.Default.SliderDisk = DiskSlider.Value; - Properties.Settings.Default.SecCPU = int.Parse(CPUSecTextBox.Text.ToString()); - Properties.Settings.Default.SecMemory = int.Parse(MemorySecTextBox.Text.ToString()); - Properties.Settings.Default.SecDisk = int.Parse(DiskSecTextBox.Text.ToString()); + Properties.Settings.Default.SecCPU = int.Parse(CPUSecTextBox.Text.ToString()); + Properties.Settings.Default.SecMemory = int.Parse(MemorySecTextBox.Text.ToString()); + Properties.Settings.Default.SecDisk = int.Parse(DiskSecTextBox.Text.ToString()); + + Properties.Settings.Default.Save(); + }catch (Exception) + { + string messageBoxText = "Please try to set this app expect on secur app"; + string caption = "Failed to get setting"; + MessageBoxButton button = MessageBoxButton.OK; + MessageBoxImage icon = MessageBoxImage.Warning; + MessageBoxResult result; + + result = System.Windows.MessageBox.Show(messageBoxText, caption, button, icon); + } - Properties.Settings.Default.Save(); } static double InputNormalizerToDouble(string input,double oldValue)