Exemplo n.º 1
0
        private string GetFieldValue(TextContent content, string fieldName)
        {
            string value = string.Empty;

            if (content.ContainsKey(fieldName))
            {
                value = content[fieldName] == null ? "" : content[fieldName].ToString();
            }
            return(value);
        }
Exemplo n.º 2
0
        private string GetFieldValue(TextContent content, string fieldName)
        {
            string value = string.Empty;

            if (content.ContainsKey(fieldName))
            {
                value = content[fieldName] == null ? "" : content[fieldName].ToString();
            }
            else
            {
                value = Page_Context.Current.PageRequestContext.AllQueryString[fieldName];
            }
            return(value);
        }
Exemplo n.º 3
0
        private static void ValidateColumn(Schema schema, TextContent textContent, ref List<RuleViolation> violations, Column column, bool update = false)
        {
            var controlType = Kooboo.CMS.Form.Html.ControlHelper.Resolve(column.ControlType);
            if (controlType != null && controlType.IsFile == true)//ignore the file control type validations.
            {
                return;
            }
            var validations = column.GetValidations();
            foreach (var validation in validations)
            {
                switch (validation.ValidationType)
                {
                    case ValidationType.Required:
                        if (textContent[column.Name] == null || string.IsNullOrEmpty(textContent[column.Name].ToString()))
                        {
                            violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                        }
                        break;
                    case ValidationType.Unique:
                        var value = textContent[column.Name];

                        int hasitems = 0;
                        if ((value == null) || string.IsNullOrEmpty(value.ToString()))
                            hasitems = 1;
                        else
                        {
                            //判断数据是否已经存在
                            if (update == true)
                            {
                                hasitems = schema.CreateQuery().WhereEquals(column.Name, value)
                                                               .WhereNotEquals(Column.UUID.Name, textContent[Column.UUID.Name]).Count();
                            }
                            else
                            {
                                hasitems = schema.CreateQuery().WhereEquals(column.Name, value).Count();
                            }
                        }
                        if (hasitems > 0)
                            violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                        break;
                    case ValidationType.StringLength:
                        var stringLength = (StringLengthValidation)validation;
                        if (column.DataType == DataType.String && textContent[column.Name] != null)
                        {
                            var length = textContent[column.Name].ToString().Length;
                            if (length < stringLength.Min || length > stringLength.Max)
                            {
                                violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                            }

                        }
                        break;
                    case ValidationType.Range:
                        var rangeValidation = (RangeValidation)validation;
                        if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                        {
                            if ((column.DataType == DataType.Int || column.DataType == DataType.Decimal))
                            {
                                decimal decimalValue = Convert.ToDecimal(textContent[column.Name]);

                                decimal start = Convert.ToDecimal(rangeValidation.Start);
                                decimal end = Convert.ToDecimal(rangeValidation.End);

                                if (start > decimalValue || end < decimalValue)
                                {
                                    violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                }

                            }
                        }
                        break;
                    case ValidationType.Regex:
                        var regexValidation = (RegexValidation)validation;
                        if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                        {
                            string pattern = regexValidation.Pattern;
                            if (!string.IsNullOrEmpty(pattern))
                            {
                                if (!Regex.IsMatch(textContent[column.Name].ToString(), pattern))
                                {
                                    violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                }
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
        }
Exemplo n.º 4
0
        private static void ValidateColumn(TextContent textContent, ref List <RuleViolation> violations, Column column)
        {
            if (column.Validations != null)
            {
                foreach (var validation in column.Validations)
                {
                    switch (validation.ValidationType)
                    {
                    case ValidationType.Required:
                        if (textContent[column.Name] == null || string.IsNullOrEmpty(textContent[column.Name].ToString()))
                        {
                            violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                        }
                        break;

                    case ValidationType.StringLength:
                        var stringLength = (StringLengthValidation)validation;
                        if (column.DataType == DataType.String && textContent[column.Name] != null)
                        {
                            var length = textContent[column.Name].ToString().Length;
                            if (length < stringLength.Min || length > stringLength.Max)
                            {
                                violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                            }
                        }
                        break;

                    case ValidationType.Range:
                        var rangeValidation = (RangeValidation)validation;
                        if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                        {
                            if ((column.DataType == DataType.Int || column.DataType == DataType.Decimal))
                            {
                                decimal decimalValue = Convert.ToDecimal(textContent[column.Name]);

                                decimal start = Convert.ToDecimal(rangeValidation.Start);
                                decimal end   = Convert.ToDecimal(rangeValidation.End);

                                if (start > decimalValue || end < decimalValue)
                                {
                                    violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                }
                            }
                        }
                        break;

                    case ValidationType.Regex:
                        var regexValidation = (RegexValidation)validation;
                        if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                        {
                            string pattern = regexValidation.Pattern;
                            if (!string.IsNullOrEmpty(pattern))
                            {
                                if (!Regex.IsMatch(textContent[column.Name].ToString(), pattern))
                                {
                                    violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static void ValidateColumn(Schema schema, TextContent textContent, ref List <RuleViolation> violations, Column column, bool update = false)
        {
            var controlType = Kooboo.CMS.Form.Html.ControlHelper.Resolve(column.ControlType);

            if (controlType != null && controlType.IsFile == true)//ignore the file control type validations.
            {
                return;
            }
            var validations = column.GetValidations();

            foreach (var validation in validations)
            {
                switch (validation.ValidationType)
                {
                case ValidationType.Required:
                    if (textContent[column.Name] == null || string.IsNullOrEmpty(textContent[column.Name].ToString()))
                    {
                        violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                    }
                    break;

                case ValidationType.Unique:
                    var value = textContent[column.Name];

                    int hasitems = 0;
                    if ((value == null) || string.IsNullOrEmpty(value.ToString()))
                    {
                        hasitems = 1;
                    }
                    else
                    {
                        //判断数据是否已经存在
                        if (update == true)
                        {
                            hasitems = schema.CreateQuery().WhereEquals(column.Name, value)
                                       .WhereNotEquals(Column.UUID.Name, textContent[Column.UUID.Name]).Count();
                        }
                        else
                        {
                            hasitems = schema.CreateQuery().WhereEquals(column.Name, value).Count();
                        }
                    }
                    if (hasitems > 0)
                    {
                        violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                    }
                    break;

                case ValidationType.StringLength:
                    var stringLength = (StringLengthValidation)validation;
                    if (column.DataType == DataType.String && textContent[column.Name] != null)
                    {
                        var length = textContent[column.Name].ToString().Length;
                        if (length < stringLength.Min || length > stringLength.Max)
                        {
                            violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                        }
                    }
                    break;

                case ValidationType.Range:
                    var rangeValidation = (RangeValidation)validation;
                    if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                    {
                        if ((column.DataType == DataType.Int || column.DataType == DataType.Decimal))
                        {
                            decimal decimalValue = Convert.ToDecimal(textContent[column.Name]);

                            decimal start = Convert.ToDecimal(rangeValidation.Start);
                            decimal end   = Convert.ToDecimal(rangeValidation.End);

                            if (start > decimalValue || end < decimalValue)
                            {
                                violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                            }
                        }
                    }
                    break;

                case ValidationType.Regex:
                    var regexValidation = (RegexValidation)validation;
                    if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null && textContent[column.Name].ToString() != "")
                    {
                        string pattern = regexValidation.Pattern;
                        if (!string.IsNullOrEmpty(pattern))
                        {
                            if (!Regex.IsMatch(textContent[column.Name].ToString(), pattern))
                            {
                                violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 6
0
        private static void ValidateColumn(TextContent textContent, ref List<RuleViolation> violations, Column column)
        {
            if (column.Validations != null)
            {
                foreach (var validation in column.Validations)
                {
                    switch (validation.ValidationType)
                    {
                        case ValidationType.Required:
                            if (textContent[column.Name] == null || string.IsNullOrEmpty(textContent[column.Name].ToString()))
                            {
                                violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                            }
                            break;
                        case ValidationType.StringLength:
                            var stringLength = (StringLengthValidation)validation;
                            if (column.DataType == DataType.String && textContent[column.Name] != null)
                            {
                                var length = textContent[column.Name].ToString().Length;
                                if (length < stringLength.Min || length > stringLength.Max)
                                {
                                    violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                }

                            }
                            break;
                        case ValidationType.Range:
                            var rangeValidation = (RangeValidation)validation;
                            if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                            {
                                if ((column.DataType == DataType.Int || column.DataType == DataType.Decimal))
                                {
                                    decimal decimalValue = Convert.ToDecimal(textContent[column.Name]);

                                    decimal start = Convert.ToDecimal(rangeValidation.Start);
                                    decimal end = Convert.ToDecimal(rangeValidation.End);

                                    if (start > decimalValue || end < decimalValue)
                                    {
                                        violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                    }

                                }
                            }
                            break;
                        case ValidationType.Regex:
                            var regexValidation = (RegexValidation)validation;
                            if (textContent.ContainsKey(column.Name) && textContent[column.Name] != null)
                            {
                                string pattern = regexValidation.Pattern;
                                if (!string.IsNullOrEmpty(pattern))
                                {
                                    if (!Regex.IsMatch(textContent[column.Name].ToString(), pattern))
                                    {
                                        violations.Add(new RuleViolation(column.Name, null, string.Format(validation.ErrorMessage, column.Name)));
                                    }
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
            }
        }