我正在使用Kendo UI,其中我有数据过滤器,其中有更多过滤器操作员可用,例如'大于' '小于' '大于或等于' '空'并且不是空的' 一切正常,但当我选择' null'并且不是空的'这两个运算符都抛出异常
例外是"此网格尚不支持此运算符" 如果有人有任何想法,请告诉我!
提前谢谢:)
答案 0 :(得分:0)
public static string BuildWhereClause(int index,string logic,GridFilter filter,System.Collections.ArrayList parameters) {
var entityType = (typeof(T));
PropertyInfo property;
if (filter.Field.Contains("."))
property = GetNestedProp<T>(filter.Field);
else
property = entityType.GetProperty(filter.Field, BindingFlags.Instance | BindingFlags.Public |
BindingFlags.NonPublic);
property = entityType.GetRuntimeProperty(filter.Field);
var parameterIndex = parameters.Count;
switch (filter.Operator.ToLower())
{
case "eq":
case "neq":
case "gte":
case "gt":
case "lte":
case "lt":
case "isnull":
case "isnotnull":
if (property != null)
{
if (typeof(DateTime).IsAssignableFrom(property.PropertyType))
{
//if(filter.Operator.ToLower()== "isnull") // check to the all insted of giving values to the case
parameters.Add(DateTime.Parse(filter.Value).Date);
return string.Format("EntityFunctions.TruncateTime({0}){1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
if (typeof(DateTime?).IsAssignableFrom(property.PropertyType))
{
parameters.Add(DateTime.Parse(filter.Value).Date);
return string.Format("EntityFunctions.TruncateTime({0}){1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
if (typeof(int).IsAssignableFrom(property.PropertyType))
{
parameters.Add(int.Parse(filter.Value));
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
if (typeof(int?).IsAssignableFrom(property.PropertyType))
{
parameters.Add(int.Parse(filter.Value));
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
if (typeof(Decimal?).IsAssignableFrom(property.PropertyType))
{
if (filter.Operator.ToLower() == "isnull")
{
parameters.Add(Boolean.Parse(filter.Value));
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
else
{
parameters.Add(Decimal.Parse(filter.Value));
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
}
if (typeof(Decimal).IsAssignableFrom(property.PropertyType))
{
parameters.Add(Decimal.Parse(filter.Value));
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
}
//if(typeof(Boolean?).IsAssignableFrom(property.PropertyType))
//{
// parameters.Add(Boolean.Parse(filter.Value));
//}
//if (typeof(Boolean).IsAssignableFrom(property.PropertyType))
//{
// parameters.Add(Decimal.Parse(filter.Value));
//}
}
parameters.Add(filter.Value);
return string.Format("{0}{1}@{2}", filter.Field, ToLinqOperator(filter.Operator), index);
case "startswith": parameters.Add(filter.Value); return string.Format("{0}.StartsWith(" + "@{1})", filter.Field, index);
case "endswith":
parameters.Add(filter.Value); return string.Format("{0}.EndsWith(" + "@{1})", filter.Field, index);
case "contains": parameters.Add(filter.Value); return string.Format("{0}.Contains(" + "@{1})", filter.Field, index);
default: throw new ArgumentException("This operator is not yet supported for this Grid", filter.Operator);
}
}