本文整理汇总了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;
}
}
}