Exemple #1
0
        /// <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);
        }
Exemple #3
0
        /// <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);
        }