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
+33 -9
View File
@@ -5,7 +5,7 @@ using System.Windows.Forms;
namespace ASCOM.Meade.net
{
[ComVisible(false)] // Form not registered for COM!
[ComVisible(false)] // Form not registered for COM!
public partial class SetupDialogForm : Form
{
public SetupDialogForm()
@@ -33,14 +33,15 @@ namespace ASCOM.Meade.net
{
MessageBox.Show(other.Message);
}
}
}
public void SetProfile(ProfileProperties profileProperties)
{
chkTrace.Checked = profileProperties.TraceLogger;
// set the list of com ports to those that are currently available
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
if (comboBoxComPort.Items.Contains(profileProperties.ComPort))
{
@@ -56,7 +57,7 @@ namespace ASCOM.Meade.net
{
TraceLogger = chkTrace.Checked,
ComPort = comboBoxComPort.SelectedItem.ToString(),
GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text)
GuideRateArcSecondsPerSecond = double.Parse(txtGuideRate.Text.Trim())
};
return profileProperties;
@@ -67,15 +68,38 @@ namespace ASCOM.Meade.net
Activate();
}
private bool _guideRateValid = true;
private void TextBox1_TextChanged(object sender, EventArgs e)
{
//const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second
var newGuideRate = double.Parse(txtGuideRate.Text);
//const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second
try
{
double newGuideRate = double.Parse(txtGuideRate.Text.Trim());
const double siderealArcSecondsPerSecond = 15.041;
var percentOfSideReal = (newGuideRate / siderealArcSecondsPerSecond * 100);
const double siderealArcSecondsPerSecond = 15.041;
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;
resources.ApplyResources(this.comboBoxComPort, "comboBoxComPort");
this.comboBoxComPort.Name = "comboBoxComPort";
this.comboBoxComPort.SelectedValueChanged += new System.EventHandler(this.ComboBoxComPort_SelectedValueChanged);
//
// label3
//