当前位置: 首页>>代码示例>>C#>>正文


C# Column.GetValidations方法代码示例

本文整理汇总了C#中Column.GetValidations方法的典型用法代码示例。如果您正苦于以下问题:C# Column.GetValidations方法的具体用法?C# Column.GetValidations怎么用?C# Column.GetValidations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Column的用法示例。


在下文中一共展示了Column.GetValidations方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateColumn

        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;
                }
            }
        }
开发者ID:RameshGD,项目名称:CMS,代码行数:90,代码来源:TextContentBinder.cs


注:本文中的Column.GetValidations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。