comparison ServerMonitor/Forms/CheckForm.cs @ 8:052aa62cb42a

Single instance. Add autorun option. Add icons. General enhancements.
author Brad Greco <brad@bgreco.net>
date Sat, 09 Mar 2019 20:14:03 -0500
parents 3142e52cbe69
children 7127d5b5ac75
comparison
equal deleted inserted replaced
7:8486ab7d2357 8:052aa62cb42a
1 using System; 1 using ServerMonitorApp.Properties;
2 using System;
2 using System.Collections.Generic; 3 using System.Collections.Generic;
3 using System.ComponentModel; 4 using System.ComponentModel;
4 using System.Data; 5 using System.Data;
5 using System.Drawing; 6 using System.Drawing;
6 using System.Linq; 7 using System.Linq;
60 CheckTypePanel.LocationChanged += CheckTypePanel_LocationChanged; 61 CheckTypePanel.LocationChanged += CheckTypePanel_LocationChanged;
61 GeneralGroupBox.Click += Control_Click; 62 GeneralGroupBox.Click += Control_Click;
62 CheckSettingsPanel.Click += Control_Click; 63 CheckSettingsPanel.Click += Control_Click;
63 64
64 CheckTypeComboBox.SelectedItem = Check?.GetType(); 65 CheckTypeComboBox.SelectedItem = Check?.GetType();
66 SetTitle();
67 Icon = Resources.icon;
65 if (Check != null) 68 if (Check != null)
66 LoadCheck(Check); 69 LoadCheck(Check);
70 }
71
72 private void SetTitle()
73 {
74 string name = NameTextBox.Text.IsNullOrEmpty() ? "New Check" : NameTextBox.Text;
75 Text = string.Format("{0}: {1}", server.Name, name);
67 } 76 }
68 77
69 private void CheckTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) 78 private void CheckTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
70 { 79 {
71 ShowCheckControl(); 80 ShowCheckControl();
104 CheckSettingsPanel.Controls.Add(checkControl); 113 CheckSettingsPanel.Controls.Add(checkControl);
105 } 114 }
106 } 115 }
107 if (checkControl != null) 116 if (checkControl != null)
108 { 117 {
109 CheckSettingsPanel.Height = checkControl.Height; 118 //CheckSettingsPanel.Height = checkControl.Height;
110 //Height = 230 + checkControl.Height; 119 //Height = 230 + checkControl.Height;
111 checkControl.Show(); 120 checkControl.Show();
112 } 121 }
113 } 122 }
114 123
115 private void LoadCheck(Check check) 124 private void LoadCheck(Check check)
116 { 125 {
126 Icon = Check.LastRunStatus.GetIcon();
117 NameTextBox.Text = Check.Name; 127 NameTextBox.Text = Check.Name;
118 EnabledCheckBox.Checked = check.Enabled; 128 EnabledCheckBox.Checked = check.Enabled;
119 TimeoutInput.Value = check.Timeout; 129 TimeoutInput.Value = check.Timeout;
120 SeverityComboBox.SelectedItem = check.FailStatus; 130 SeverityComboBox.SelectedItem = check.FailStatus;
131 FailuresInput.Value = check.MaxConsecutiveFailures;
121 FrequencyUnitsComboBox.SelectedItem = check.Schedule.Units; 132 FrequencyUnitsComboBox.SelectedItem = check.Schedule.Units;
122 FrequencyUpDown.Value = check.Schedule.Frequency; 133 FrequencyUpDown.Value = check.Schedule.Frequency;
123 StartTimePicker.Value = new DateTime(1970, 1, 1) + check.Schedule.StartTime; 134 StartTimePicker.Value = new DateTime(1970, 1, 1) + check.Schedule.StartTime;
124 EndTimePicker.Value = new DateTime(1970, 1, 1) + check.Schedule.EndTime; 135 EndTimePicker.Value = new DateTime(1970, 1, 1) + check.Schedule.EndTime;
125 checkControl?.LoadCheck(check); 136 checkControl?.LoadCheck(check);
138 check.Server = server; 149 check.Server = server;
139 check.Name = NameTextBox.Text; 150 check.Name = NameTextBox.Text;
140 check.Enabled = EnabledCheckBox.Checked; 151 check.Enabled = EnabledCheckBox.Checked;
141 check.Timeout = (int)TimeoutInput.Value; 152 check.Timeout = (int)TimeoutInput.Value;
142 check.FailStatus = (CheckStatus)SeverityComboBox.SelectedItem; 153 check.FailStatus = (CheckStatus)SeverityComboBox.SelectedItem;
154 check.MaxConsecutiveFailures = (int)FailuresInput.Value;
143 check.Schedule = new Schedule((FrequencyUnits)FrequencyUnitsComboBox.SelectedItem, (int)FrequencyUpDown.Value, StartTimePicker.Value.TimeOfDay, EndTimePicker.Value.TimeOfDay); 155 check.Schedule = new Schedule((FrequencyUnits)FrequencyUnitsComboBox.SelectedItem, (int)FrequencyUpDown.Value, StartTimePicker.Value.TimeOfDay, EndTimePicker.Value.TimeOfDay);
144 try 156 try
145 { 157 {
146 checkControl?.UpdateCheck(check); 158 checkControl?.UpdateCheck(check);
147 result = check.Validate(saving); 159 result = check.Validate(saving);
237 CancelRunButton.Visible = false; 249 CancelRunButton.Visible = false;
238 if (result != null) 250 if (result != null)
239 { 251 {
240 ResultLabel.Text = result.Message; 252 ResultLabel.Text = result.Message;
241 //ResultLabel.ForeColor = result.CheckStatus == CheckStatus.Success ? Color.Green : Color.Red; 253 //ResultLabel.ForeColor = result.CheckStatus == CheckStatus.Success ? Color.Green : Color.Red;
242 ResultIconPictureBox.Image = result.CheckStatus.GetIcon(); 254 ResultIconPictureBox.Image = result.CheckStatus.GetImage();
243 ResultLabel.Visible = ResultIconPictureBox.Visible = true; 255 ResultLabel.Visible = ResultIconPictureBox.Visible = true;
244 } 256 }
245 } 257 }
246 258
247 /*private class CheckInfo 259 /*private class CheckInfo
331 343
332 private void FrequencyUnitsComboBox_Format(object sender, ListControlConvertEventArgs e) 344 private void FrequencyUnitsComboBox_Format(object sender, ListControlConvertEventArgs e)
333 { 345 {
334 e.Value = e.Value.ToString().ToLower() + 's'; 346 e.Value = e.Value.ToString().ToLower() + 's';
335 } 347 }
348
349 private void NameTextBox_TextChanged(object sender, EventArgs e)
350 {
351 SetTitle();
352 }
336 } 353 }
337 354
338 public class HelpLocationChangedEventArgs : EventArgs 355 public class HelpLocationChangedEventArgs : EventArgs
339 { 356 {
340 public Point HelpLocation { get; private set; } 357 public Point HelpLocation { get; private set; }