diff ServerMonitor/Controls/FileCheckControl.cs @ 3:96f0b028176d

File check
author Brad Greco <brad@bgreco.net>
date Fri, 11 Jan 2019 22:34:18 -0500
parents
children 7127d5b5ac75
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ServerMonitor/Controls/FileCheckControl.cs	Fri Jan 11 22:34:18 2019 -0500
@@ -0,0 +1,79 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace ServerMonitorApp
+{
+    [CheckType(typeof(FileCheck))]
+    public partial class FileCheckControl : CheckControl
+    {
+        public FileCheckControl()
+        {
+            InitializeComponent();
+        }
+
+        private void DiskSpaceCheckControl_Load(object sender, EventArgs e)
+        {
+            FileSizeComparisonComboBox.SelectedIndex = 0;
+            DateModifiedComparisonComboBox.SelectedIndex = 0;
+        }
+
+        public override void LoadCheck(Check check1)
+        {
+            FileCheck check = (FileCheck)check1;
+            FileTextBox.Text = check.File;
+            FileSizeCheckBox.Checked = check.CheckFileSize;
+            FileSizeComparisonComboBox.SelectedIndex = check.FileSizeLessThan ? 0 : 1;
+            FileSizeTextBox.Text = check.FileSizeInSelectedUnits.ToString();
+            FileSizeUnitsComboBox.SelectedIndex = (int)check.FileSizeUnits;
+            DateModifiedCheckBox.Checked = check.CheckDateModified;
+            DateModifiedComparisonComboBox.SelectedIndex = check.DateModifiedOlderThan ? 0 : 1;
+            DateModifiedTextBox.Text = check.DateModified.ToString();
+            DateModifiedUnitsComboBox.SelectedIndex = (int)check.DateModifiedUnits;
+
+            if (FileSizeTextBox.Text == "0")
+                FileSizeTextBox.Clear();
+            if (DateModifiedTextBox.Text == "0")
+                DateModifiedTextBox.Clear();
+        }
+
+        public override void UpdateCheck(Check check1)
+        {
+            FileCheck check = (FileCheck)check1;
+            check.File = FileTextBox.Text;
+            check.CheckFileSize = FileSizeCheckBox.Checked;
+            check.FileSizeLessThan = FileSizeComparisonComboBox.SelectedIndex == 0;
+            try
+            {
+                check.FileSizeInSelectedUnits = double.Parse(FileSizeTextBox.Text);
+            }
+            catch
+            {
+                if (check.CheckFileSize)
+                    throw new UpdateCheckException("File size must be numeric.");
+                else
+                    check.FileSizeInSelectedUnits = 0;
+            }
+            check.FileSizeUnits = (SizeUnits)FileSizeUnitsComboBox.SelectedIndex;
+            check.CheckDateModified = DateModifiedCheckBox.Checked;
+            check.DateModifiedOlderThan = DateModifiedComparisonComboBox.SelectedIndex == 0;
+            try
+            {
+                check.DateModified = double.Parse(DateModifiedTextBox.Text);
+            }
+            catch
+            {
+                if (check.CheckDateModified)
+                    throw new UpdateCheckException("Date modified must be numeric.");
+                else
+                    check.DateModified = 0;
+            }
+            check.DateModifiedUnits = (TimeUnits)DateModifiedUnitsComboBox.SelectedIndex;
+        }
+    }
+}
\ No newline at end of file