private void paramTypeCombo_SelectedIndexChanged(object sender, EventArgs e) { MssParamType paramType = (MssParamType)this.paramTypeCombo.SelectedIndex; if (paramType != this.inputParamInfo.paramType) { this.inputParamInfo = Factory_MssParamInfo.Create(paramType, this.paramNameTextBox.Text); ConfigureFieldsFromInputParamInfo(); } }
protected bool AttemptToSetResultParamInfo() { bool resultParamInfoSetSuccessfully = true; MssParamType paramType = (MssParamType)this.paramTypeCombo.SelectedIndex; string paramName = this.paramNameTextBox.Text; this.resultParamInfo = Factory_MssParamInfo.Create(paramType, paramName); //Ensure that the min field is valid. double minValue = -1; bool minIsValidNumber = true; if (this.inputParamInfo.methodOfValueInput == ValueInputType.Number) { if (double.TryParse(this.minParamValueTextBox.Text, out minValue) == false) { this.errorProvider.SetError(this.minParamValueTextBox, ERR_NOT_NUMBER); resultParamInfoSetSuccessfully = false; minIsValidNumber = false; } else { this.errorProvider.SetError(this.minParamValueTextBox, ""); } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Integer) { int minValueAsInt; if (int.TryParse(this.minParamValueTextBox.Text, out minValueAsInt) == false) { this.errorProvider.SetError(this.minParamValueTextBox, ERR_NOT_INT); resultParamInfoSetSuccessfully = false; minIsValidNumber = false; } else { this.errorProvider.SetError(this.minParamValueTextBox, ""); minValue = minValueAsInt; } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Selection) { minValue = this.inputParamInfo.MinValue; } else { //Unknown value input type. Debug.Assert(false); } //Ensure that the max field is valid. double maxValue = -1; bool maxIsValidNumber = true; if (this.inputParamInfo.methodOfValueInput == ValueInputType.Number) { if (double.TryParse(this.maxParamValueTextBox.Text, out maxValue) == false) { this.errorProvider.SetError(this.maxParamValueTextBox, ERR_NOT_NUMBER); resultParamInfoSetSuccessfully = false; maxIsValidNumber = false; } else { this.errorProvider.SetError(this.maxParamValueTextBox, ""); } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Integer) { int maxValueAsInt; if (int.TryParse(this.maxParamValueTextBox.Text, out maxValueAsInt) == false) { this.errorProvider.SetError(this.maxParamValueTextBox, ERR_NOT_INT); resultParamInfoSetSuccessfully = false; maxIsValidNumber = false; } else { this.errorProvider.SetError(this.maxParamValueTextBox, ""); maxValue = maxValueAsInt; } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Selection) { maxValue = this.inputParamInfo.MaxValue; } else { //Unknown value input type. Debug.Assert(false); } //Ensure that the min value is not greater then the max value. bool maxMinMakeValidRange = false; if (maxIsValidNumber && minIsValidNumber) { if (minValue >= maxValue) { this.errorProvider.SetError(this.minParamValueTextBox, ERR_MIN_GREATER_THAN_MAX); this.errorProvider.SetError(this.maxParamValueTextBox, ERR_MIN_GREATER_THAN_MAX); resultParamInfoSetSuccessfully = false; } else { this.errorProvider.SetError(this.minParamValueTextBox, ""); this.errorProvider.SetError(this.maxParamValueTextBox, ""); maxMinMakeValidRange = true; } } //Check the value field. double value = -1; bool valueIsValidNumber = true; if (this.inputParamInfo.methodOfValueInput == ValueInputType.Number) { if (double.TryParse(this.paramValueTextBox.Text, out value) == false) { this.errorProvider.SetError(this.paramValueTextBox, ERR_NOT_NUMBER); resultParamInfoSetSuccessfully = false; valueIsValidNumber = false; } else { this.errorProvider.SetError(this.paramValueTextBox, ""); } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Integer) { int valueAsInt; if (int.TryParse(this.paramValueTextBox.Text, out valueAsInt) == false) { this.errorProvider.SetError(this.paramValueTextBox, ERR_NOT_INT); resultParamInfoSetSuccessfully = false; valueIsValidNumber = false; } else { this.errorProvider.SetError(this.paramValueTextBox, ""); value = valueAsInt; } } else if (this.inputParamInfo.methodOfValueInput == ValueInputType.Selection) { value = this.paramValueCombo.SelectedIndex; } else { //Unknown value input type. Debug.Assert(false); } if (valueIsValidNumber && maxMinMakeValidRange) { if (value < minValue || value > maxValue) { this.errorProvider.SetError(this.paramValueTextBox, ERR_VALUE_OUTSIDE_RANGE); resultParamInfoSetSuccessfully = false; } else { this.errorProvider.SetError(this.paramValueTextBox, ""); } } //Set the resulting param info if there were no errors. if (resultParamInfoSetSuccessfully) { this.resultParamInfo.MinValue = minValue; this.resultParamInfo.MaxValue = maxValue; this.resultParamInfo.RawValue = value; } return(resultParamInfoSetSuccessfully); }