annotate ServerMonitor/Controls/FileCheckControl.cs @ 32:2342e9459444

Fix schedule times not being saved.
author Brad Greco <brad@bgreco.net>
date Sun, 16 Jun 2019 16:55:14 -0400
parents 832a07de0f90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 namespace ServerMonitorApp
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 {
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
5 /// <summary>Control for editing a file check.</summary>
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 [CheckType(typeof(FileCheck))]
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 public partial class FileCheckControl : CheckControl
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 public FileCheckControl()
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 InitializeComponent();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 private void DiskSpaceCheckControl_Load(object sender, EventArgs e)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 {
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
16 // Initialize the combo boxes to non-empty values.
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 FileSizeComparisonComboBox.SelectedIndex = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 DateModifiedComparisonComboBox.SelectedIndex = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
21 /// <summary>Sets the values of the controls from a check's properties.</summary>
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 public override void LoadCheck(Check check1)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 FileCheck check = (FileCheck)check1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25 FileTextBox.Text = check.File;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 FileSizeCheckBox.Checked = check.CheckFileSize;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 FileSizeComparisonComboBox.SelectedIndex = check.FileSizeLessThan ? 0 : 1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 FileSizeTextBox.Text = check.FileSizeInSelectedUnits.ToString();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 FileSizeUnitsComboBox.SelectedIndex = (int)check.FileSizeUnits;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 DateModifiedCheckBox.Checked = check.CheckDateModified;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 DateModifiedComparisonComboBox.SelectedIndex = check.DateModifiedOlderThan ? 0 : 1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32 DateModifiedTextBox.Text = check.DateModified.ToString();
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 DateModifiedUnitsComboBox.SelectedIndex = (int)check.DateModifiedUnits;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
35 // Blank out text boxes that are disabled and have a blank-looking value.
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
36 if (FileSizeTextBox.Text == "0" && !check.CheckFileSize)
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37 FileSizeTextBox.Clear();
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
38 if (DateModifiedTextBox.Text == "0" && !check.CheckDateModified)
21
832a07de0f90 Fix server name descenders being cut off.
Brad Greco <brad@bgreco.net>
parents: 9
diff changeset
39 DateModifiedTextBox.Clear();
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41
9
7127d5b5ac75 Code cleanup and comments
Brad Greco <brad@bgreco.net>
parents: 3
diff changeset
42 /// <summary>Updates the properties of a check from user input.</summary>
3
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 public override void UpdateCheck(Check check1)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 FileCheck check = (FileCheck)check1;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 check.File = FileTextBox.Text;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 check.CheckFileSize = FileSizeCheckBox.Checked;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 check.FileSizeLessThan = FileSizeComparisonComboBox.SelectedIndex == 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 try
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 check.FileSizeInSelectedUnits = double.Parse(FileSizeTextBox.Text);
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 catch
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 if (check.CheckFileSize)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56 throw new UpdateCheckException("File size must be numeric.");
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 else
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 check.FileSizeInSelectedUnits = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 check.FileSizeUnits = (SizeUnits)FileSizeUnitsComboBox.SelectedIndex;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 check.CheckDateModified = DateModifiedCheckBox.Checked;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 check.DateModifiedOlderThan = DateModifiedComparisonComboBox.SelectedIndex == 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 try
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 check.DateModified = double.Parse(DateModifiedTextBox.Text);
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67 catch
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 {
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69 if (check.CheckDateModified)
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 throw new UpdateCheckException("Date modified must be numeric.");
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71 else
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72 check.DateModified = 0;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 check.DateModifiedUnits = (TimeUnits)DateModifiedUnitsComboBox.SelectedIndex;
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 }
96f0b028176d File check
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77 }