view ServerMonitor/Controls/FileCheckControl.cs @ 7:8486ab7d2357

Add/remove files
author Brad Greco <brad@bgreco.net>
date Fri, 01 Mar 2019 21:39:22 -0500
parents 96f0b028176d
children 7127d5b5ac75
line wrap: on
line source

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;
        }
    }
}