Added validation to the setup dialog.

This commit is contained in:
2019-07-23 23:42:14 +01:00
parent 93c63cc014
commit 027cb24d3f
2 changed files with 34 additions and 9 deletions
+32 -8
View File
@@ -5,7 +5,7 @@ using System.Windows.Forms;
namespace ASCOM.Meade.net namespace ASCOM.Meade.net
{ {
[ComVisible(false)] // Form not registered for COM! [ComVisible(false)] // Form not registered for COM!
public partial class SetupDialogForm : Form public partial class SetupDialogForm : Form
{ {
public SetupDialogForm() public SetupDialogForm()
@@ -40,7 +40,8 @@ namespace ASCOM.Meade.net
chkTrace.Checked = profileProperties.TraceLogger; chkTrace.Checked = profileProperties.TraceLogger;
// set the list of com ports to those that are currently available // set the list of com ports to those that are currently available
comboBoxComPort.Items.Clear(); comboBoxComPort.Items.Clear();
comboBoxComPort.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames()); // use System.IO because it's static comboBoxComPort.Items.AddRange(System.IO.Ports.SerialPort
.GetPortNames()); // use System.IO because it's static
// select the current port if possible // select the current port if possible
if (comboBoxComPort.Items.Contains(profileProperties.ComPort)) if (comboBoxComPort.Items.Contains(profileProperties.ComPort))
{ {
@@ -56,7 +57,7 @@ namespace ASCOM.Meade.net
{ {
TraceLogger = chkTrace.Checked, TraceLogger = chkTrace.Checked,
ComPort = comboBoxComPort.SelectedItem.ToString(), ComPort = comboBoxComPort.SelectedItem.ToString(),
GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text) GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim())
}; };
return profileProperties; return profileProperties;
@@ -67,15 +68,38 @@ namespace ASCOM.Meade.net
Activate(); Activate();
} }
private bool _guideRateValid = true;
private void TextBox1_TextChanged(object sender, EventArgs e) private void TextBox1_TextChanged(object sender, EventArgs e)
{ {
//const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second //const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second
var newGuideRate = double.Parse(txtGuideRate.Text); try
{
double newGuideRate = double.Parse(txtGuideRate.Text.Trim());
const double siderealArcSecondsPerSecond = 15.041; const double siderealArcSecondsPerSecond = 15.041;
var percentOfSideReal = (newGuideRate / siderealArcSecondsPerSecond * 100); var percentOfSideReal = (newGuideRate / siderealArcSecondsPerSecond * 100);
lblPercentOfSiderealRate.Text = $"({percentOfSideReal:00.0}% of sidereal rate)"; lblPercentOfSiderealRate.Text = $"({percentOfSideReal:00.0}% of sidereal rate)";
_guideRateValid = true;
}
catch (Exception exception)
{
//Surpressing this exception as if the value is not valid then it's not useful.
_guideRateValid = false;
}
UpdateOKButton();
}
private void UpdateOKButton()
{
cmdOK.Enabled = _guideRateValid && (comboBoxComPort.SelectedItem != null);
}
private void ComboBoxComPort_SelectedValueChanged(object sender, EventArgs e)
{
UpdateOKButton();
} }
} }
} }
+1
View File
@@ -89,6 +89,7 @@ namespace ASCOM.Meade.net
this.comboBoxComPort.FormattingEnabled = true; this.comboBoxComPort.FormattingEnabled = true;
resources.ApplyResources(this.comboBoxComPort, "comboBoxComPort"); resources.ApplyResources(this.comboBoxComPort, "comboBoxComPort");
this.comboBoxComPort.Name = "comboBoxComPort"; this.comboBoxComPort.Name = "comboBoxComPort";
this.comboBoxComPort.SelectedValueChanged += new System.EventHandler(this.ComboBoxComPort_SelectedValueChanged);
// //
// label3 // label3
// //