/// <summary>
    /// Returns true if user control is valid.
    /// </summary>
    public override bool IsValid()
    {
        bool valid = true;

        // Check 'options' validity
        if (lstOptions.SelectedIndex == ListSourceIndex)
        {
            // Some option must be included
            if (String.IsNullOrWhiteSpace(txtValue.Text))
            {
                ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsEmpty") + " ";
                valid            = false;
            }
            else
            {
                // Parse lines
                int      lineIndex;
                string[] lines = txtValue.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                for (lineIndex = 0; lineIndex <= lines.GetUpperBound(0); lineIndex++)
                {
                    // Loop through only not-empty lines
                    string line = lines[lineIndex];
                    if (!String.IsNullOrWhiteSpace(line))
                    {
                        // Get line items
                        string[] items = line.Replace(SpecialFieldsDefinition.SEMICOLON_TO_REPLACE, SpecialFieldsDefinition.REPLACED_SEMICOLON).Split(';');

                        // Every line must have value and item element and optionally visibility macro
                        if (items.Length > 3)
                        {
                            ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidFormat") + " ";
                            valid            = false;
                            break;
                        }

                        // Check for possible macro (with/without visibility condition)
                        if (items.Length <= 2)
                        {
                            string specialMacro = items[0].Trim();

                            // Check if special macro is used
                            if (SpecialFieldsDefinition.IsSpecialFieldMacro(specialMacro))
                            {
                                string macro = (items.Length == 2) ? items[1].Trim() : String.Empty;

                                // If special field macro used and second item isn't macro show error
                                if (!String.IsNullOrEmpty(macro) && !MacroProcessor.ContainsMacro(macro))
                                {
                                    ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidMacroFormat"), lineIndex + 1) + " ";
                                    valid            = false;
                                    break;
                                }
                            }
                        }

                        // Validate input value
                        var checkType = new DataTypeIntegrity(items[0], EditedFieldDataType);

                        var result = checkType.ValidateDataType();
                        if (!String.IsNullOrEmpty(result))
                        {
                            ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidValue"), lineIndex + 1) + " " + result + " ";
                            valid            = false;
                            break;
                        }
                    }
                }
            }
        }
        // Check SQL query validity
        else if ((lstOptions.SelectedIndex == SqlSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text))
        {
            ValidationError += GetString("TemplateDesigner.ErrorDropDownListQueryEmpty") + " ";
            valid            = false;
        }
        else if ((lstOptions.SelectedIndex == MacroSourceIndex) && String.IsNullOrWhiteSpace(txtValue.Text))
        {
            ValidationError += GetString("TemplateDesigner.ErrorDropDownListMacroEmpty") + " ";
            valid            = false;
        }

        return(valid);
    }
Esempio n. 2
0
    /// <summary>
    /// Returns true if user control is valid.
    /// </summary>
    public override bool IsValid()
    {
        bool valid = true;

        // Check 'options' validity
        if (lstOptions.SelectedIndex == ListSourceIndex)
        {
            // Some option must be included
            if (string.IsNullOrEmpty(txtValue.Text.Trim()))
            {
                ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsEmpty") + " ";
                valid            = false;
            }
            else
            {
                // Parse lines
                int      lineIndex = 0;
                string[] lines     = txtValue.Text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

                for (lineIndex = 0; lineIndex <= lines.GetUpperBound(0); lineIndex++)
                {
                    // Loop through only not-empty lines
                    if ((lines[lineIndex] != null) && (lines[lineIndex].Trim() != string.Empty))
                    {
                        // Get line items
                        string[] items = lines[lineIndex].Replace(SpecialFieldsDefinition.SEMICOLON_TO_REPLACE, SpecialFieldsDefinition.REPLACED_SEMICOLON).Split(';');

                        // Every line must have value and item element and optionally visibility macro
                        if (items.Length > 3)
                        {
                            ValidationError += GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidFormat") + " ";
                            valid            = false;
                            break;
                        }
                        else
                        {
                            // Check for possible macro (with/without visibility condition)
                            if (items.Length <= 2)
                            {
                                string specialMacro = items[0].Trim();

                                // Check if special macro is used
                                if (SpecialFieldsDefinition.IsSpecialFieldMacro(specialMacro))
                                {
                                    string macro = (items.Length == 2) ? items[1].Trim() : String.Empty;

                                    // If special field macro used and second item isn't macro show error
                                    if (!String.IsNullOrEmpty(macro) && !MacroProcessor.ContainsMacro(macro))
                                    {
                                        ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidMacroFormat"), lineIndex + 1) + " ";
                                        valid            = false;
                                        break;
                                    }
                                }
                            }

                            // Check valid Double format
                            if (FieldInfo.DataType == FieldDataType.Double)
                            {
                                if (!ValidationHelper.IsDouble(items[0]) && !(FieldInfo.AllowEmpty && string.IsNullOrEmpty(items[0])))
                                {
                                    ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidDoubleFormat"), lineIndex + 1) + " ";
                                    valid            = false;
                                    break;
                                }
                            }
                            // Check valid Integer format
                            else if (FieldInfo.DataType == FieldDataType.Integer)
                            {
                                if (!ValidationHelper.IsInteger(items[0]) && !(FieldInfo.AllowEmpty && string.IsNullOrEmpty(items[0])))
                                {
                                    ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidIntFormat"), lineIndex + 1) + " ";
                                    valid            = false;
                                    break;
                                }
                            }
                            // Check valid Long integer format
                            else if (FieldInfo.DataType == FieldDataType.LongInteger)
                            {
                                if (!ValidationHelper.IsLong(items[0]) && !(FieldInfo.AllowEmpty && string.IsNullOrEmpty(items[0])))
                                {
                                    ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidLongIntFormat"), lineIndex + 1) + " ";
                                    valid            = false;
                                    break;
                                }
                            }
                            // Check valid Date time format
                            else if (FieldInfo.DataType == FieldDataType.DateTime)
                            {
                                if ((ValidationHelper.GetDateTime(items[0], DateTimeHelper.ZERO_TIME) == DateTimeHelper.ZERO_TIME) && !FieldInfo.AllowEmpty)
                                {
                                    ValidationError += string.Format(GetString("TemplateDesigner.ErrorDropDownListOptionsInvalidDateTimeFormat"), lineIndex + 1) + " ";
                                    valid            = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // Check SQL query validity
        else if ((lstOptions.SelectedIndex == SqlSourceIndex) && (string.IsNullOrEmpty(txtValue.Text.Trim())))
        {
            ValidationError += GetString("TemplateDesigner.ErrorDropDownListQueryEmpty") + " ";
            valid            = false;
        }
        else if ((lstOptions.SelectedIndex == MacroSourceIndex) && (string.IsNullOrEmpty(txtValue.Text.Trim())))
        {
            ValidationError += GetString("TemplateDesigner.ErrorDropDownListMacroEmpty") + " ";
            valid            = false;
        }

        return(valid);
    }