/// <summary> /// Process the action related to the TextChanged event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void ProcessMaskedTextBoxITTextChanged(object sender, EventArgs e) { RestoreMask(true); // Clear the ErrorProvider control. if (mErrorProvider != null) { mErrorProvider.Clear(); } // Raise the change value event if the control has not the focus. // If not, wait until it lose the focus. if (mMaskedTextBoxIT.Focused) { return; } // Check that the data belongs to the specified type. if (!DefaultFormats.CheckDataType(mMaskedTextBoxIT.Text, mDataType, true)) { return; } if (CheckValueChange(mMaskedTextBoxIT.Text)) { // Value changed event OnValueChanged(new ValueChangedEventArgs()); PreviousValue = mMaskedTextBoxIT.Text; } }
/// <summary> /// Executes the action related to the TextChanged event. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">EventArgs.</param> private void HandleTextBoxITTextChanged(object sender, EventArgs e) { // Clear the ErrorProvider control. if (mErrorProvider != null) { mErrorProvider.Clear(); } // Raise the change value event if the control has not the focus. // If not, wait until it lose the focus. if (mTextBoxIT.Focused) { return; } // Check that the data belongs to the specified type. if (!DefaultFormats.CheckDataType(mTextBoxIT.Text, mDataType, true)) { return; } if (CheckValueChange(mTextBoxIT.Text)) { // Throw value changed event. OnValueChanged(new ValueChangedEventArgs()); PreviousValue = mTextBoxIT.Text; } }
/// <summary> /// Validates the control value. /// </summary> /// <param name="defaultErrorMessage">Default validation message.</param> /// <returns>Boolean value indicating if the validation was ok or not.</returns> public bool Validate(string defaultErrorMessage) { if ((this.mErrorProvider != null) && (this.mTextBoxIT != null)) { mErrorProvider.SetIconPadding(this.mTextBoxIT, -20); // Null validation. if ((!this.NullAllowed) && (this.mTextBoxIT.Text == string.Empty)) { mErrorProvider.SetError(this.mTextBoxIT, defaultErrorMessage); // Validation error. return(false); } // Format validation. if (this.mTextBoxIT.Text != string.Empty) { if (!DefaultFormats.CheckDataType(this.mTextBoxIT.Text, mDataType, mNullAllowed)) { string lMask = DefaultFormats.GetHelpMask(mDataType, string.Empty); mErrorProvider.SetError(this.mTextBoxIT, CultureManager.TranslateString(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK)); // Validation error. return(false); } } else { // Size Validation if ((mMaxLength != 0) && (mTextBoxIT.Text.Length > mMaxLength)) { mErrorProvider.SetError(this.mTextBoxIT, CultureManager.TranslateString(LanguageConstantKeys.L_VALIDATION_SIZE_WITHOUT_ARGUMENT, LanguageConstantValues.L_VALIDATION_SIZE_WITHOUT_ARGUMENT) + mMaxLength); return(false); } } } // Set the value with the correct format. this.Value = Logics.Logic.StringToModel(mDataType, mTextBoxIT.Text); // Validation OK. return(true); }
/// <summary> /// Validates the control value. /// </summary> /// <param name="defaultErrorMessage">Default validation message.</param> /// <returns>Boolean value indicating if the validation was ok or not.</returns> public bool Validate(string defaultErrorMessage) { // No graphical editor. if (mMaskedTextBoxIT == null) { return(true); } // Null validation. if (!NullAllowed && !HasValue()) { // Validation error. if (mErrorProvider != null) { mErrorProvider.SetError(this.mMaskedTextBoxIT, defaultErrorMessage); } return(false); } // No value in the editor. if (NullAllowed && !HasValue()) { return(true); } // There is a value in the editor. bool lIsValid = true; // If there is a mask defined, it has to be validated the value according the mask format. if (!string.IsNullOrEmpty(Mask)) { // Format validation for String and Time data types which have any introduction mask. // String data type if (mDataType == ModelType.String) { lIsValid = IsValidStringAccordingMask(this.mMaskedTextBoxIT.Text); } // Time data type if (mDataType == ModelType.Time) { lIsValid = DefaultFormats.CheckDataType(this.mMaskedTextBoxIT.Text, mDataType, mNullAllowed) && this.mMaskedTextBoxIT.MaskCompleted && IsValidTimeAccordingMask(this.mMaskedTextBoxIT.Text); } } else { // Value data type validation, when there is not a mask defined. lIsValid = DefaultFormats.CheckDataType(this.mMaskedTextBoxIT.Text, mDataType, mNullAllowed); #region Numeric format validation if (NumericFormatValidationRequired()) { // Check the value according numeric introduction pattern. decimal?lValue = null; try { lValue = decimal.Parse(mMaskedTextBoxIT.Text, System.Globalization.NumberStyles.Number, CultureManager.Culture); } catch { lIsValid = false; } if (!lIsValid) { // It is not a numeric value, or it is not a correct value according the data type. object[] lArgs = new object[1]; lArgs[0] = DefaultFormats.GetHelpMask(mDataType, string.Empty); string lErrorMessage = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK, lArgs); mErrorProvider.SetError(this.mMaskedTextBoxIT, lErrorMessage); return(false); } if (lValue != null) { // Number of integer and decimal digits. int lDecimalDigits = GetNumberDecimalDigits(mMaskedTextBoxIT.Text); int lIntegerDigits = GetNumberIntegerDigits(mMaskedTextBoxIT.Text); if (MinDecimalDigits > 0) { if (lDecimalDigits < MinDecimalDigits) { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); return(false); } } if (lDecimalDigits > MaxDecimalDigits) { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); return(false); } if (MaxIntegerDigits != null) { if (lIntegerDigits > MaxIntegerDigits) { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); return(false); } } // Minimum and Maximum value validation. if ((mMinValue != null || mMaxValue != null) && (mMinValue != mMaxValue)) { if (mMinValue != null && lValue < mMinValue) { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); return(false); } if (mMaxValue != null && lValue > mMaxValue) { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); return(false); } } } } #endregion Numeric format validation } // Show the suitable error message. if (!lIsValid) { // Default or introduction pattern error message if (string.IsNullOrEmpty(IPValidationMessage)) { object[] lArgs = new object[1]; lArgs[0] = DefaultFormats.GetHelpMask(mDataType, string.Empty); string lErrorMessage = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK, lArgs); mErrorProvider.SetError(this.mMaskedTextBoxIT, lErrorMessage); } else { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); } // Validation error. return(false); } else { // Size validation. if ((mMaxLength != 0) && (mMaskedTextBoxIT.Text.Length > mMaxLength)) { string lMessageError = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_SIZE_WITHOUT_ARGUMENT, LanguageConstantValues.L_VALIDATION_SIZE_WITHOUT_ARGUMENT, mMaxLength); mErrorProvider.SetError(this.mMaskedTextBoxIT, lMessageError); return(false); } } // Restore the mask to the graphical control RestoreMask(false); // Validation OK. return(true); }
private void mbOK_Click(object sender, EventArgs e) { #region Actualize current language // Get the current language from the combobox language selector. CultureManager.Culture = new System.Globalization.CultureInfo(((KeyValuePair <string, string>) this.mLanguage.SelectedItem).Key); #endregion Actualize current language string lAgentClassName = (mAgent.SelectedItem as Logics.LogInAgent).Name; Oids.Oid lagent = Oids.Oid.Create(lAgentClassName); lagent.ClearValues(); AgentInfo lAgentInfo = lagent as AgentInfo; Logics.LogInAgent lLogInAgent = Logics.Agents.GetLogInAgentByName(lAgentClassName); // Check if the connected agent has alternate key. if (lLogInAgent.AlternateKeyName != string.Empty) { // Obtain the Alternate Key used by the connected agent class, // in order to be able of filling in the field values from the editors. lagent = (Oid)lagent.GetAlternateKey(lLogInAgent.AlternateKeyName); lagent.AlternateKeyName = lLogInAgent.AlternateKeyName; } if (!(lAgentInfo is AnonymousAgentInfo)) { // To validate that all the login values are introduced. bool lbIsNull = false; // Error provider properties lErrorProvider.Clear(); lErrorProvider.BlinkRate = 500; lErrorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink; #region Validate that the login and password are introduced // Validate the password field. if (mTextBoxPassword.Text == string.Empty) { // Set the focus and error mTextBoxPassword.Focus(); lErrorProvider.SetError(mTextBoxPassword, CultureManager.TranslateString(LanguageConstantKeys.L_PASSWORD_NOT_NULL, LanguageConstantValues.L_PASSWORD_NOT_NULL)); lErrorProvider.SetIconPadding(mTextBoxPassword, -20); lbIsNull = true; } // Validate the login fields. for (int i = mEditors.Length - 1; i >= 0; i--) { if (mEditors[i].Visible) { // Null validation. if (mEditors[i].Text == string.Empty) { // Set the focus and error mEditors[i].Focus(); lErrorProvider.SetError(mEditors[i], CultureManager.TranslateString(LanguageConstantKeys.L_LOGIN_NOT_NULL, LanguageConstantValues.L_LOGIN_NOT_NULL)); lErrorProvider.SetIconPadding(mEditors[i], -20); lbIsNull = true; } } } // If there are any empty argument. if (lbIsNull == true) { // Do not continue return; } #endregion Validate that the login and password are introduced } #region Create the agent int lOidField = 0; try { if (!(lAgentInfo is AnonymousAgentInfo)) { // Set the OID type to the proper control. foreach (Control item in mEditors) { if (item.Visible == true) { try { if (!DefaultFormats.CheckDataType(item.Text, lagent.Fields[lOidField].Type, false)) { string lText = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_BAD_IDENTITY, LanguageConstantValues.L_ERROR_BAD_IDENTITY); string lMessage = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR); MessageBox.Show(lText, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } object value = Logics.Logic.StringToModel(lagent.Fields[lOidField].Type, item.Text); lagent.SetValue(lOidField, value); lOidField++; } catch { string lText = CultureManager.TranslateString(LanguageConstantKeys.L_LOGIN_INCORRECT, LanguageConstantValues.L_LOGIN_INCORRECT); string lMessage = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR); MessageBox.Show(lText, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } } } #region Agent authentication if (lagent is AlternateKey) { AuthenticateAlternateKey(lagent, mTextBoxPassword.Text); } else { Authenticate(lagent as AgentInfo, mTextBoxPassword.Text); } #endregion Agent authentication } catch { string lMessage = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR, LanguageConstantValues.L_ERROR); string lExcepMsg = CultureManager.TranslateString(LanguageConstantKeys.L_ERROR_BAD_IDENTITY, LanguageConstantValues.L_ERROR_BAD_IDENTITY); MessageBox.Show(lExcepMsg, lMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } #endregion Create the agent. }
/// <summary> /// Validates the control value. /// </summary> /// <param name="defaultErrorMessage">Default validation message.</param> /// <returns>Boolean value indicating if the validation was ok or not.</returns> public bool Validate(string defaultErrorMessage) { // No graphical editor. if (mMaskedTextBoxIT == null) { return(true); } // Null validation. if (!NullAllowed && !HasValue()) { // Validation error. if (mErrorProvider != null) { mErrorProvider.SetError(this.mMaskedTextBoxIT, defaultErrorMessage); } return(false); } // No value in the editor. if (NullAllowed && !HasValue()) { return(true); } // There is a value in the editor. bool lIsValid = true; if (string.IsNullOrEmpty(Mask)) { // If there is not a mask, check the value according data type. lIsValid = DefaultFormats.CheckDataType(this.mMaskedTextBoxIT.Text, mDataType, mNullAllowed); } else { lIsValid = !(Logics.Logic.StringToDateTime(mMaskedTextBoxIT.Text, Mask) == null); if (mDataType == ModelType.DateTime) { lIsValid = lIsValid && IsValidDateTimeAccordingMask(this.mMaskedTextBoxIT.Text); } // If the editor had lost the mask and now has a valid value -> re-assign the mask. if (lIsValid) { RestoreMask(false); } } // Show the suitable error message. if (!lIsValid) { // Default or introduction pattern error message if (string.IsNullOrEmpty(IPValidationMessage)) { object[] lArgs = new object[1]; lArgs[0] = DefaultFormats.GetHelpMask(mDataType, string.Empty);; string lErrorMessage = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK, lArgs); mErrorProvider.SetError(this.mMaskedTextBoxIT, lErrorMessage); mDateTimePickerIT.Value = DateTime.Now; } else { mErrorProvider.SetError(this.mMaskedTextBoxIT, IPValidationMessage); } return(false); } // Validation OK. return(true); }
/// <summary> /// Validates the modified rows values. Not Null and datatype /// </summary> /// <param name="modifiedRows"></param> /// <returns></returns> private bool ValidateModifiedRows(DataTable modifiedRows) { // Error datatable DataTable errorReport = new DataTable(); // Column for the OID string instanceColumnsName = CurrentDisplaySet.ServiceInfo.SelectedInstanceArgumentAlias; errorReport.Columns.Add(instanceColumnsName); // Column for the error message string lReportMessage = CultureManager.TranslateString(LanguageConstantKeys.L_MULTIEXE_EXECUTION, LanguageConstantValues.L_MULTIEXE_EXECUTION); errorReport.Columns.Add(lReportMessage); // Not null and Datatype validation foreach (DataRow rowValues in modifiedRows.Rows) { Oid instanceOID = Adaptor.ServerConnection.GetOid(modifiedRows, rowValues); foreach (DisplaySetServiceArgumentInfo argumentInfo in CurrentDisplaySet.ServiceInfo.ArgumentDisplaySetPairs.Values) { object value = rowValues[argumentInfo.DSElementName]; // Null validation if (value.GetType() == typeof(System.DBNull)) { if (!argumentInfo.AllowsNull) { // Add a nuw row in the error datatable DataRow newReportRow = errorReport.NewRow(); string nameInScenario = argumentInfo.Alias; object[] lArgs = new object[1]; lArgs[0] = nameInScenario; string lErrorMessage = CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_NECESARY, LanguageConstantValues.L_VALIDATION_NECESARY, lArgs); newReportRow[lReportMessage] = lErrorMessage; newReportRow[instanceColumnsName] = UtilFunctions.OidFieldsToString(instanceOID, ' '); errorReport.Rows.Add(newReportRow); } } else { // Data type validation if (!DefaultFormats.CheckDataType(value.ToString(), argumentInfo.DataType, false)) { // Add a nuw row in the error datatable DataRow newReportRow = errorReport.NewRow(); string lMask = DefaultFormats.GetHelpMask(argumentInfo.DataType, string.Empty); object[] lArgs = new object[1]; lArgs[0] = lMask; string lErrorMessage = argumentInfo.Alias + ": "; lErrorMessage += CultureManager.TranslateStringWithParams(LanguageConstantKeys.L_VALIDATION_INVALID_FORMAT_MASK, LanguageConstantValues.L_VALIDATION_INVALID_FORMAT_MASK, lArgs); newReportRow[lReportMessage] = lErrorMessage; newReportRow[instanceColumnsName] = UtilFunctions.OidFieldsToString(instanceOID, ' '); errorReport.Rows.Add(newReportRow); } } } } // If errors have been found, show them if (errorReport.Rows.Count > 0) { // Show error message to the user ScenarioManager.LaunchMultiExecutionReportScenario(errorReport, CurrentDisplaySet.ServiceInfo.ServiceAlias, null, null); return(false); } return(true); }