Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether automatic Data Validation code should be created for a certain Control in a YAML file.
        /// </summary>
        /// <param name="AControl">Control in YAML file.</param>
        /// <param name="AHasDataField"></param>
        /// <param name="AMasterOrDetailTable">Pass in 'true' if the YAML file has got a 'MasterTable' or 'DetailTable' Element. </param>
        /// <param name="AIncludeMasterOrDetailTableControl"></param>
        /// <param name="AScope">Scope of the Data Validation that should be checked for. Specify <see cref="TAutomDataValidationScope.advsAll"/>
        /// to find out if any of the scopes should be checked against, or use any other value of that enum to specifiy a specific scope.</param>
        /// <param name="AReasonForAutomValidation">Contains the reason why automatic data validation code needs to be generated.</param>
        /// <returns>True if automatic Data Validation code should be created for the Control in a YAML that was passed in in <paramref name="AControl" /> for
        /// the scope that was specified with <paramref name="AScope" />, otherwise false. This Method also returns false if the Control specified in
        /// <paramref name="AControl" /> isn't linked to a DB Table Field.</returns>
        public static bool GenerateAutoValidationCodeForControl(TControlDef AControl, bool AHasDataField, bool AMasterOrDetailTable,
            bool AIncludeMasterOrDetailTableControl, TAutomDataValidationScope AScope, out string AReasonForAutomValidation)
        {
            TTableField DBField = null;
            bool IsDetailNotMaster;

            AReasonForAutomValidation = String.Empty;

            if (AHasDataField)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.GetAttribute("DataField"), out IsDetailNotMaster, true);
            }
            else if (AMasterOrDetailTable && AIncludeMasterOrDetailTableControl)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.controlName.Substring(
                        AControl.controlTypePrefix.Length), out IsDetailNotMaster, false);
            }

            if (DBField != null)
            {
                return GenerateAutoValidationCodeForDBTableField(DBField, AScope, null, out AReasonForAutomValidation);
            }
            else
            {
                return false;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether automatic Data Validation code should be created for a certain DB Table Field.
        /// </summary>
        /// <param name="ADBField">DB Field.</param>
        /// <param name="AScope">Scope of the Data Validation that should be checked for. Specify <see cref="TAutomDataValidationScope.advsAll"/>
        /// to find out if any of the scopes should be checked against, or use any other value of that enum to specifiy a specific scope.</param>
        /// <param name="AConstraintsGroup">The constraints for the table associated with this column. Can be null unless this is doing table
        /// validation rather than control validation</param>
        /// <param name="AReasonForAutomValidation">Contains the reason why automatic data validation code needs to be generated.</param>
        /// <returns>True if automatic Data Validation code should be created for the DB Table Field passed in in <paramref name="ADBField" /> for
        /// the scope that was specified with <paramref name="AScope" />, otherwise false.</returns>
        public static bool GenerateAutoValidationCodeForDBTableField(TTableField ADBField,
                                                                     TAutomDataValidationScope AScope,
                                                                     List <TConstraint> AConstraintsGroup,
                                                                     out string AReasonForAutomValidation)
        {
            AReasonForAutomValidation = String.Empty;

            // NOT NULL checks
            if ((AScope == TAutomDataValidationScope.advsNotNullChecks) ||
                (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.bPartOfPrimKey)
                {
                    AReasonForAutomValidation = "must have a value (it is part of the Primary Key)";

                    if ((ADBField.strType == "varchar") || (ADBField.strType == "text"))
                    {
                        AReasonForAutomValidation += " and must not be an empty string";
                    }

                    return(true);
                }
                else if (ADBField.bNotNull)
                {
                    AReasonForAutomValidation = "must have a value (NOT NULL constraint)";

                    // If it is a string and is a foreign key then the string cannot be empty
                    if (((ADBField.strType == "varchar") || (ADBField.strType == "text")) && (AConstraintsGroup != null))
                    {
                        foreach (TConstraint c in AConstraintsGroup)
                        {
                            if ((c.strType == "foreignkey") && (c.strThisFields.Contains(ADBField.strName)))
                            {
                                // Empty String is not allowed because it isn't allowed in the foreign table
                                AReasonForAutomValidation += " and must not be an empty string (Foreign Key constraint)";
                                break;
                            }
                        }
                    }

                    return(true);
                }
            }

            // Date checks
            if ((AScope == TAutomDataValidationScope.advsDateChecks) ||
                (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.strType == "date")
                {
                    AReasonForAutomValidation = "must represent a valid date";

                    return(true);
                }
            }

            // String Length checks
            if ((AScope == TAutomDataValidationScope.advsStringLengthChecks) ||
                (AScope == TAutomDataValidationScope.advsAll))
            {
                if (((ADBField.strType == "varchar") || (ADBField.strType == "text")) &&
                    ((ADBField.strName != "s_created_by_c") &&
                     (ADBField.strName != "s_modified_by_c")))
                {
                    AReasonForAutomValidation = "must not contain more than " + (ADBField.iCharLength * 2).ToString() + " characters";

                    return(true);
                }
            }

            // Number Range checks
            if ((AScope == TAutomDataValidationScope.advsNumberRangeChecks) ||
                (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.strType == "number")
                {
                    if (ADBField.iDecimals > 0)
                    {
                        AReasonForAutomValidation = "must not have more than " +
                                                    (ADBField.iLength -
                                                     ADBField.iDecimals).ToString() + " digits before the decimal point and not more than " +
                                                    ADBField.iDecimals.ToString() +
                                                    " after the decimal point";
                    }
                    else
                    {
                        AReasonForAutomValidation = "must not have more than " + ADBField.iLength.ToString() + " digits and no decimals";
                    }

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines whether automatic Data Validation code should be created for a certain DB Table Field.
        /// </summary>
        /// <param name="ADBField">DB Field.</param>
        /// <param name="AScope">Scope of the Data Validation that should be checked for. Specify <see cref="TAutomDataValidationScope.advsAll"/>
        /// to find out if any of the scopes should be checked against, or use any other value of that enum to specifiy a specific scope.</param>
        /// <param name="AConstraintsGroup">The constraints for the table associated with this column. Can be null unless this is doing table
        /// validation rather than control validation</param>
        /// <param name="AReasonForAutomValidation">Contains the reason why automatic data validation code needs to be generated.</param>
        /// <returns>True if automatic Data Validation code should be created for the DB Table Field passed in in <paramref name="ADBField" /> for
        /// the scope that was specified with <paramref name="AScope" />, otherwise false.</returns>
        public static bool GenerateAutoValidationCodeForDBTableField(TTableField ADBField,
            TAutomDataValidationScope AScope,
            List <TConstraint>AConstraintsGroup,
            out string AReasonForAutomValidation)
        {
            AReasonForAutomValidation = String.Empty;

            // NOT NULL checks
            if ((AScope == TAutomDataValidationScope.advsNotNullChecks)
                || (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.bPartOfPrimKey)
                {
                    AReasonForAutomValidation = "must have a value (it is part of the Primary Key)";

                    if ((ADBField.strType == "varchar") || (ADBField.strType == "text"))
                    {
                        AReasonForAutomValidation += " and must not be an empty string";
                    }

                    return true;
                }
                else if (ADBField.bNotNull)
                {
                    AReasonForAutomValidation = "must have a value (NOT NULL constraint)";

                    // If it is a string and is a foreign key then the string cannot be empty
                    if (((ADBField.strType == "varchar") || (ADBField.strType == "text")) && (AConstraintsGroup != null))
                    {
                        foreach (TConstraint c in AConstraintsGroup)
                        {
                            if ((c.strType == "foreignkey") && (c.strThisFields.Contains(ADBField.strName)))
                            {
                                // Empty String is not allowed because it isn't allowed in the foreign table
                                AReasonForAutomValidation += " and must not be an empty string (Foreign Key constraint)";
                                break;
                            }
                        }
                    }

                    return true;
                }
            }

            // Date checks
            if ((AScope == TAutomDataValidationScope.advsDateChecks)
                || (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.strType == "date")
                {
                    AReasonForAutomValidation = "must represent a valid date";

                    return true;
                }
            }

            // String Length checks
            if ((AScope == TAutomDataValidationScope.advsStringLengthChecks)
                || (AScope == TAutomDataValidationScope.advsAll))
            {
                if (((ADBField.strType == "varchar") || (ADBField.strType == "text"))
                    && ((ADBField.strName != "s_created_by_c")
                        && (ADBField.strName != "s_modified_by_c")))
                {
                    AReasonForAutomValidation = "must not contain more than " + (ADBField.iCharLength * 2).ToString() + " characters";

                    return true;
                }
            }

            // Number Range checks
            if ((AScope == TAutomDataValidationScope.advsNumberRangeChecks)
                || (AScope == TAutomDataValidationScope.advsAll))
            {
                if (ADBField.strType == "number")
                {
                    if (ADBField.iDecimals > 0)
                    {
                        AReasonForAutomValidation = "must not have more than " +
                                                    (ADBField.iLength -
                                                     ADBField.iDecimals).ToString() + " digits before the decimal point and not more than " +
                                                    ADBField.iDecimals.ToString() +
                                                    " after the decimal point";
                    }
                    else
                    {
                        AReasonForAutomValidation = "must not have more than " + ADBField.iLength.ToString() + " digits and no decimals";
                    }

                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines whether automatic Data Validation code should be created for a certain Control in a YAML file.
        /// </summary>
        /// <param name="AControl">Control in YAML file.</param>
        /// <param name="AHasDataField"></param>
        /// <param name="AMasterOrDetailTable">Pass in 'true' if the YAML file has got a 'MasterTable' or 'DetailTable' Element. </param>
        /// <param name="AIncludeMasterOrDetailTableControl"></param>
        /// <param name="AScope">Scope of the Data Validation that should be checked for. Specify <see cref="TAutomDataValidationScope.advsAll"/>
        /// to find out if any of the scopes should be checked against, or use any other value of that enum to specifiy a specific scope.</param>
        /// <param name="AReasonForAutomValidation">Contains the reason why automatic data validation code needs to be generated.</param>
        /// <returns>True if automatic Data Validation code should be created for the Control in a YAML that was passed in in <paramref name="AControl" /> for
        /// the scope that was specified with <paramref name="AScope" />, otherwise false. This Method also returns false if the Control specified in
        /// <paramref name="AControl" /> isn't linked to a DB Table Field.</returns>
        public static bool GenerateAutoValidationCodeForControl(TControlDef AControl, bool AHasDataField, bool AMasterOrDetailTable,
                                                                bool AIncludeMasterOrDetailTableControl, TAutomDataValidationScope AScope, out string AReasonForAutomValidation)
        {
            TTableField DBField = null;
            bool        IsDetailNotMaster;

            AReasonForAutomValidation = String.Empty;

            if (AHasDataField)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.GetAttribute("DataField"), out IsDetailNotMaster, true);
            }
            else if (AMasterOrDetailTable && AIncludeMasterOrDetailTableControl)
            {
                DBField = TDataBinding.GetTableField(AControl, AControl.controlName.Substring(
                                                         AControl.controlTypePrefix.Length), out IsDetailNotMaster, false);
            }

            if (DBField != null)
            {
                return(GenerateAutoValidationCodeForDBTableField(DBField, AScope, null, out AReasonForAutomValidation));
            }
            else
            {
                return(false);
            }
        }