Added validation to the setup dialog.
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+1
@@ -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
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user