/// <summary> /// Pop Scale Factor Validating Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBoxPopScaleFactors_Validating(object sender, CancelEventArgs e) { double scaleFactor; NftTextBox txtBootFac = sender as NftTextBox; if (double.TryParse(txtBootFac.Text, out scaleFactor)) { if (scaleFactor < 0) { MessageBox.Show("Bootsrap Population Scale Factors must be a positive number.", "AGEPRO", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtBootFac.Text = txtBootFac.PrevValidValue; e.Cancel = true; return; } } else { MessageBox.Show("Bootstrap Population Scale Factors must be a numeric value.", "AGEPRO", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtBootFac.Text = txtBootFac.PrevValidValue; e.Cancel = true; return; } }
/// <summary> /// Paramertic Parameter input data validation. Invalid data is reverted to previous valid value the NftTextBox /// object stored. /// </summary> /// <remarks> /// For consistent validation with nullable and non-nullable data bounded objects, <code>DataSourceUpdateMode</code> /// should be set that to default, <code>OnValidation</code>. /// </remarks> /// <param name="txtParam"></param> /// <param name="e"></param> protected void ValidateParamerticParameter(NftTextBox txtParam, CancelEventArgs e) { if (!double.TryParse(txtParam.Text, out _)) { _ = MessageBox.Show($"Invalid input for {txtParam.ParamName}: Must be a numeric value.", "AGEPRO Recruitment", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtParam.Text = txtParam.PrevValidValue; e.Cancel = true; return; } }
/// <summary> /// Paramertic Parameter input data validation. Invalid data is reverted to previous valid value the NftTextBox /// object stored. /// </summary> /// <remarks> /// For consistent validation with nullable and non-nullable data bounded objects, <code>DataSourceUpdateMode</code> /// should be set that to default, <code>OnValidation</code>. /// </remarks> /// <param name="txtParam"></param> /// <param name="e"></param> protected void ValidateParamerticParameter(NftTextBox txtParam, CancelEventArgs e) { double parametricVal; if (!(double.TryParse(txtParam.Text, out parametricVal))) { MessageBox.Show("Invalid input for " + txtParam.ParamName + ": Must be a numeric value.", "AGEPRO", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtParam.Text = txtParam.PrevValidValue; e.Cancel = true; return; } }
private void SetControlDataBindings(NftTextBox ctl, Nmfs.Agepro.CoreLib.MiscOptionsParameter miscOptSrc, string miscOptField, bool decimalZeroFormat = false) { //Clear any existing (if any) bindings before creating new ones. ctl.DataBindings.Clear(); Binding b = new Binding("Text", miscOptSrc, miscOptField, true, DataSourceUpdateMode.OnPropertyChanged); if (decimalZeroFormat) { b.Format += new ConvertEventHandler(DoubleToString); b.Parse += new ConvertEventHandler(StringToDouble); ctl.DataBindings.Add(b); } else { ctl.DataBindings.Add(b); } }
private bool ValidateScalingFactor(NftTextBox txtFactor, string paramName) { double scaleFactor; if (double.TryParse(txtFactor.Text, out scaleFactor)) { if (scaleFactor < 0) { MessageBox.Show(paramName + " must be a positive number.", "AGEPRO", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtFactor.Text = txtFactor.PrevValidValue; return(false); } } else { MessageBox.Show(paramName + " must be a numeric value.", "AGEPRO", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtFactor.Text = txtFactor.PrevValidValue; return(false); } return(true); // If Valid }