Ejemplo n.º 1
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            //Custom implementation of string filter type. Case insensitive compartion.

            filterType = GetValidType(filterType);
            object typedValue = GetTypedValue(value);
            if (typedValue == null)
                return null; //incorrent filter value;

            Expression valueExpr = Expression.Constant(typedValue);
            Expression binaryExpression;
            switch (filterType)
            {
                case GridFilterType.Equals:
                    binaryExpression = GetCaseInsensitiveСompartion(string.Empty, leftExpr, valueExpr);
                    break;
                case GridFilterType.Contains:
                    binaryExpression = GetCaseInsensitiveСompartion("Contains", leftExpr, valueExpr);
                    break;
                case GridFilterType.StartsWith:
                    binaryExpression = GetCaseInsensitiveСompartion("StartsWith", leftExpr, valueExpr);
                    break;
                case GridFilterType.EndsWidth:
                    binaryExpression = GetCaseInsensitiveСompartion("EndsWith", leftExpr, valueExpr);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return binaryExpression;
        }
Ejemplo n.º 2
0
 public override GridFilterType GetValidType(GridFilterType type)
 {
     switch (type)
     {
         case GridFilterType.Equals:
         case GridFilterType.Contains:
         case GridFilterType.StartsWith:
         case GridFilterType.EndsWidth:
             return type;
         default:
             return GridFilterType.Equals;
     }
 }
Ejemplo n.º 3
0
 public override GridFilterType GetValidType(GridFilterType type)
 {
     switch (type)
     {
         case GridFilterType.Equals:
         case GridFilterType.GreaterThan:
         case GridFilterType.LessThan:
         case GridFilterType.GreaterThanOrEquals:
         case GridFilterType.LessThanOrEquals:
             return type;
         default:
             return GridFilterType.Equals;
     }
 }
Ejemplo n.º 4
0
        public override GridFilterType GetValidType(GridFilterType type)
        {
            switch (type)
            {
            case GridFilterType.Equals:
            case GridFilterType.NotEquals:
            case GridFilterType.GreaterThan:
            case GridFilterType.LessThan:
            case GridFilterType.GreaterThanOrEquals:
            case GridFilterType.LessThanOrEquals:
                return(type);

            default:
                return(GridFilterType.Equals);
            }
        }
Ejemplo n.º 5
0
        public static IHtmlGrid <T> Filterable <T>(this IHtmlGrid <T> html, GridFilterType type)
        {
            foreach (IGridColumn column in html.Grid.Columns)
            {
                if (column.Filter.IsEnabled == null)
                {
                    column.Filter.IsEnabled = true;
                }

                if (column.Filter.Type == null)
                {
                    column.Filter.Type = type;
                }
            }

            return(html);
        }
Ejemplo n.º 6
0
        public override GridFilterType GetValidType(GridFilterType type)
        {
            switch (type)
            {
            case GridFilterType.Equals:
            case GridFilterType.NotEquals:
            case GridFilterType.Contains:
            case GridFilterType.StartsWith:
            case GridFilterType.EndsWidth:
            case GridFilterType.IsNull:
            case GridFilterType.IsNotNull:
                return(type);

            default:
                return(GridFilterType.Equals);
            }
        }
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            if (filterType == GridFilterType.Equals)
            {
                GetValidType(filterType);
                object typedValue = GetTypedValue(value);
                if (typedValue == null)
                    return null; //incorrent filter value;

                Expression valueExpr = Expression.Constant(typedValue);
                var newLeftExp = Expression.GreaterThanOrEqual(leftExpr, valueExpr);
                DateTime nextDay = DateTime.Parse(value).AddDays(1);
                var dayAfterExp = Expression.Constant(nextDay);
                var newRightExp = Expression.LessThan(leftExpr, dayAfterExp);
                return Expression.And(newLeftExp, newRightExp);
            }

            return base.GetFilterExpression(leftExpr, value, filterType);
        }
Ejemplo n.º 8
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            //var dateExpr = Expression.Property(leftExpr, leftExpr.Type, "Date");

            //if (filterType == GridFilterType.Equals)
            //{
            //    var dateObj = GetTypedValue(value);
            //    if (dateObj == null) return null;//not valid

            //    var startDate = Expression.Constant(dateObj);
            //    var endDate = Expression.Constant(((DateTime)dateObj).AddDays(1));

            //    var left = Expression.GreaterThanOrEqual(leftExpr, startDate);
            //    var right = Expression.LessThan(leftExpr, endDate);

            //    return Expression.And(left, right);
            //}

            return base.GetFilterExpression(leftExpr, value, filterType);
        }
Ejemplo n.º 9
0
        public virtual string GetFilterExpression(string columnName, string value, GridFilterType filterType)
        {
            value = GetStringValue(value);

            //base implementation of building filter expressions
            filterType = GetValidType(filterType);

            switch (filterType)
            {
            case GridFilterType.Equals:
                return(columnName + " eq " + value);

            case GridFilterType.NotEquals:
                return(columnName + " ne " + value);

            case GridFilterType.Contains:
                return("contains(" + columnName + ", " + value + ")");

            case GridFilterType.StartsWith:
                return("startswith(" + columnName + ", " + value + ")");

            case GridFilterType.EndsWidth:
                return("endswith(" + columnName + ", " + value + ")");

            case GridFilterType.LessThan:
                return(columnName + " lt " + value);

            case GridFilterType.LessThanOrEquals:
                return(columnName + " le " + value);

            case GridFilterType.GreaterThan:
                return(columnName + " gt " + value);

            case GridFilterType.GreaterThanOrEquals:
                return(columnName + " ge " + value);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 10
0
        public virtual Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            //base implementation of building filter expressions
            filterType = GetValidType(filterType);

            object typedValue = GetTypedValue(value);
            if (typedValue == null)
                return null; //incorrent filter value;

            Type targetType = TargetType;

            Expression valueExpr = Expression.Constant(typedValue);

            switch (filterType)
            {
                case GridFilterType.Equals:
                    return Expression.Equal(leftExpr, valueExpr);
                case GridFilterType.Contains:
                    MethodInfo miContains = TargetType.GetMethod("Contains", new[] {typeof (string)});
                    return Expression.Call(leftExpr, miContains, valueExpr);
                case GridFilterType.StartsWith:
                    MethodInfo miStartsWith = targetType.GetMethod("StartsWith", new[] {typeof (string)});
                    return Expression.Call(leftExpr, miStartsWith, valueExpr);
                case GridFilterType.EndsWidth:
                    MethodInfo miEndssWith = targetType.GetMethod("EndsWith", new[] {typeof (string)});
                    return Expression.Call(leftExpr, miEndssWith, valueExpr);
                case GridFilterType.LessThan:
                    return Expression.LessThan(leftExpr, valueExpr);
                case GridFilterType.LessThanOrEquals:
                    return Expression.LessThanOrEqual(leftExpr, valueExpr);
                case GridFilterType.GreaterThan:
                    return Expression.GreaterThan(leftExpr, valueExpr);
                case GridFilterType.GreaterThanOrEquals:
                    return Expression.GreaterThanOrEqual(leftExpr, valueExpr);
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 ///     Sanitize filter type for specific column data type
 /// </summary>
 /// <param name="type">Filter type (equals, contains etc)</param>
 /// <returns>Sanitized filter type</returns>
 public abstract GridFilterType GetValidType(GridFilterType type);
Ejemplo n.º 12
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType,
                                                       MethodInfo removeDiacritics)
        {
            //var dateExpr = Expression.Property(leftExpr, leftExpr.Type, "Date");

            //if (filterType == GridFilterType.Equals)
            //{
            //    var dateObj = GetTypedValue(value);
            //    if (dateObj == null) return null;//not valid

            //    var startDate = Expression.Constant(dateObj);
            //    var endDate = Expression.Constant(((DateTime)dateObj).AddDays(1));

            //    var left = Expression.GreaterThanOrEqual(leftExpr, startDate);
            //    var right = Expression.LessThan(leftExpr, endDate);

            //    return Expression.And(left, right);
            //}

            return(base.GetFilterExpression(leftExpr, value, filterType, removeDiacritics));
        }
Ejemplo n.º 13
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            //Custom implementation of string filter type. Case insensitive comparison.

            filterType = GetValidType(filterType);

            object typedValue = GetTypedValue(value);

            if (typedValue == null)
            {
                return(null); // incorrect filter value;
            }
            Expression valueExpr = Expression.Constant(typedValue);
            Expression binaryExpression;

            switch (filterType)
            {
            case GridFilterType.Equals:
                binaryExpression = GetEqualsСompartion(string.Empty, leftExpr, valueExpr);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(binaryExpression);
        }
Ejemplo n.º 14
0
 public override GridFilterType GetValidType(GridFilterType type)
 {
     //in any case Boolean types must compare by Equals filter type
     //We can't compare: contains(true) and etc.
     return(GridFilterType.Equals);
 }
 private ColumnFilterValue MockFilterSetting(string columnName, string filterValue, GridFilterType type)
 {
     return(new ColumnFilterValue
     {
         ColumnName = columnName,
         FilterValue = filterValue,
         FilterType = type
     });
 }
Ejemplo n.º 16
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            if (filterType == GridFilterType.Equals)
            {
                GetValidType(filterType);
                object typedValue = GetTypedValue(value);
                if (typedValue == null)
                {
                    return(null); //incorrent filter value;
                }
                Expression valueExpr   = Expression.Constant(typedValue);
                var        newLeftExp  = Expression.GreaterThanOrEqual(leftExpr, valueExpr);
                DateTime   nextDay     = DateTime.Parse(value).AddDays(1);
                var        dayAfterExp = Expression.Constant(nextDay);
                var        newRightExp = Expression.LessThan(leftExpr, dayAfterExp);
                return(Expression.And(newLeftExp, newRightExp));
            }

            return(base.GetFilterExpression(leftExpr, value, filterType));
        }
Ejemplo n.º 17
0
 /// <summary>
 ///     Sanitize filter type for specific column data type
 /// </summary>
 /// <param name="type">Filter type (equals, contains etc)</param>
 /// <returns>Sanitized filter type</returns>
 public abstract GridFilterType GetValidType(GridFilterType type);
 public void Add(string name, GridFilterType type, string value)
 {
     Add(new ColumnFilterValue(name, type, value));
 }
 public DefaultFilterColumnCollection(string name, GridFilterType type, string value) : this()
 {
     Add(new ColumnFilterValue(name, type, value));
 }
Ejemplo n.º 20
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType,
                                                       MethodInfo removeDiacritics)
        {
            //base implementation of building filter expressions
            filterType = GetValidType(filterType);

            object typedValue = GetTypedValue(value);

            if (typedValue == null)
            {
                return(null); //incorrent filter value;
            }
            Expression valueExpr = Expression.Constant(typedValue);

            Type                 targetType       = TargetType;
            MethodInfo           toString         = targetType.GetMethod("ToString", new Type[] { });
            MethodCallExpression toStringLeftExpr = Expression.Call(leftExpr, toString);

            Expression binaryExpression;

            switch (filterType)
            {
            case GridFilterType.Equals:
                binaryExpression = GetCaseInsensitiveСomparation(string.Empty, toStringLeftExpr, valueExpr);
                break;

            case GridFilterType.NotEquals:
                binaryExpression = GetCaseInsensitiveСomparation("NotEquals", toStringLeftExpr, valueExpr);
                break;

            case GridFilterType.Contains:
                binaryExpression = GetCaseInsensitiveСomparation("Contains", toStringLeftExpr, valueExpr);
                break;

            case GridFilterType.StartsWith:
                binaryExpression = GetCaseInsensitiveСomparation("StartsWith", toStringLeftExpr, valueExpr);
                break;

            case GridFilterType.EndsWidth:
                binaryExpression = GetCaseInsensitiveСomparation("EndsWith", toStringLeftExpr, valueExpr);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(binaryExpression);
        }
Ejemplo n.º 21
0
        public static IGridColumn <T, TValue> Filterable <T, TValue>(this IGridColumn <T, TValue> column, GridFilterType type)
        {
            column.Filter.IsEnabled ??= true;
            column.Filter.Type = type;

            return(column);
        }
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            var ci      = new CultureInfo("en-US");
            var formats = new[] { "M-d-yyyy", "dd-MM-yyyy", "MM-dd-yyyy", "M.d.yyyy", "dd.MM.yyyy", "MM.dd.yyyy", "M/d/yyyy", "dd/MM/yyyy", "MM/dd/yyyy" }
            .Union(ci.DateTimeFormat.GetAllDateTimePatterns()).ToArray();

            if (filterType == GridFilterType.Equals)
            {
                GetValidType(filterType);
                object typedValue = GetTypedValue(value);
                if (typedValue == null)
                {
                    return(null); //incorrent filter value;
                }
                Expression valueExpr   = Expression.Constant(typedValue);
                var        newLeftExp  = Expression.GreaterThanOrEqual(leftExpr, valueExpr);
                DateTime   nextDay     = DateTime.ParseExact(value, formats, ci, DateTimeStyles.AssumeLocal).AddDays(1);
                var        dayAfterExp = Expression.Constant(nextDay);
                var        newRightExp = Expression.LessThan(leftExpr, dayAfterExp);
                return(Expression.And(newLeftExp, newRightExp));
            }

            return(base.GetFilterExpression(leftExpr, value, filterType));
        }
Ejemplo n.º 23
0
 public ColumnFilterValue(string name, GridFilterType type, string value)
 {
     ColumnName  = name;
     FilterType  = type;
     FilterValue = value;
 }
Ejemplo n.º 24
0
        public virtual Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType)
        {
            //base implementation of building filter expressions
            filterType = GetValidType(filterType);

            object typedValue = GetTypedValue(value);

            if (typedValue == null)
            {
                return(null); //incorrent filter value;
            }
            Type targetType = TargetType;

            Expression valueExpr = Expression.Constant(typedValue);

            switch (filterType)
            {
            case GridFilterType.Equals:
                return(Expression.Equal(leftExpr, valueExpr));

            case GridFilterType.NotEquals:
                return(Expression.NotEqual(leftExpr, valueExpr));

            case GridFilterType.Contains:
                MethodInfo miContains = TargetType.GetMethod("Contains", new[] { typeof(string) });
                return(Expression.Call(leftExpr, miContains, valueExpr));

            case GridFilterType.StartsWith:
                MethodInfo miStartsWith = targetType.GetMethod("StartsWith", new[] { typeof(string) });
                return(Expression.Call(leftExpr, miStartsWith, valueExpr));

            case GridFilterType.EndsWidth:
                MethodInfo miEndssWith = targetType.GetMethod("EndsWith", new[] { typeof(string) });
                return(Expression.Call(leftExpr, miEndssWith, valueExpr));

            case GridFilterType.LessThan:
                return(Expression.LessThan(leftExpr, valueExpr));

            case GridFilterType.LessThanOrEquals:
                return(Expression.LessThanOrEqual(leftExpr, valueExpr));

            case GridFilterType.GreaterThan:
                return(Expression.GreaterThan(leftExpr, valueExpr));

            case GridFilterType.GreaterThanOrEquals:
                return(Expression.GreaterThanOrEqual(leftExpr, valueExpr));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 25
0
        public override Expression GetFilterExpression(Expression leftExpr, string value, GridFilterType filterType,
                                                       MethodInfo removeDiacritics)
        {
            //Custom implementation of string filter type. Case insensitive compartion.

            filterType = GetValidType(filterType);
            object typedValue = GetTypedValue(value);

            if (typedValue == null)
            {
                return(null); //incorrent filter value;
            }
            Expression valueExpr = Expression.Constant(typedValue);
            Expression binaryExpression;

            switch (filterType)
            {
            case GridFilterType.Equals:
            case GridFilterType.IsNull:
                binaryExpression = GetCaseInsensitiveСomparation(string.Empty, leftExpr, valueExpr, removeDiacritics);
                break;

            case GridFilterType.NotEquals:
            case GridFilterType.IsNotNull:
                binaryExpression = GetCaseInsensitiveСomparation("NotEquals", leftExpr, valueExpr, removeDiacritics);
                break;

            case GridFilterType.Contains:
                binaryExpression = GetCaseInsensitiveСomparation("Contains", leftExpr, valueExpr, removeDiacritics);
                break;

            case GridFilterType.StartsWith:
                binaryExpression = GetCaseInsensitiveСomparation("StartsWith", leftExpr, valueExpr, removeDiacritics);
                break;

            case GridFilterType.EndsWidth:
                binaryExpression = GetCaseInsensitiveСomparation("EndsWith", leftExpr, valueExpr, removeDiacritics);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(binaryExpression);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Set the filter for the property descriptor.
 /// </summary>
 /// <param name="type"></param>
 internal static void SetGridFilter(GridFilterType type)
 {
     GridFilter = type;
 }
Ejemplo n.º 27
0
 public override GridFilterType GetValidType(GridFilterType type)
 {
     //in any case Boolean types must compare by Equals filter type
     //We can't compare: contains(true) and etc.
     return GridFilterType.Equals;
 }