Пример #1
0
        private String ConstructFilterExpression(DataView view, GridSearch args)
        {
            String format = ((view.ToTable().Columns[args.SearchColumn].DataType == typeof(String)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime))) ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}";
            String text2 = "[{0}] {1} ({2})";
            String text3 = "[{0}] LIKE '{1}'";
            String text4 = "[{0}] NOT LIKE '{1}'";
            switch (args.SearchOperation)
            {
                case SearchOperation.IsEqualTo:
                    return String.Format(format, args.SearchColumn, "=", args.SearchString);

                case SearchOperation.IsLessThan:
                    return String.Format(format, args.SearchColumn, "<", args.SearchString);

                case SearchOperation.IsLessOrEqualTo:
                    return String.Format(format, args.SearchColumn, "<=", args.SearchString);

                case SearchOperation.IsGreaterThan:
                    return String.Format(format, args.SearchColumn, ">", args.SearchString);

                case SearchOperation.IsGreaterOrEqualTo:
                    return String.Format(format, args.SearchColumn, ">=", args.SearchString);

                case SearchOperation.IsIn:
                    return String.Format(text2, args.SearchColumn, "in", args.SearchString);

                case SearchOperation.IsNotIn:
                    return String.Format(text2, args.SearchColumn, "not in", args.SearchString);

                case SearchOperation.BeginsWith:
                    return String.Format(text3, args.SearchColumn, args.SearchString + "%");

                case SearchOperation.DoesNotBeginWith:
                    return String.Format(text4, args.SearchColumn, args.SearchString + "%");

                case SearchOperation.EndsWith:
                    return String.Format(text3, args.SearchColumn, "%" + args.SearchString);

                case SearchOperation.DoesNotEndWith:
                    return String.Format(text4, args.SearchColumn, "%" + args.SearchString);

                case SearchOperation.Contains:
                    return String.Format(text3, args.SearchColumn, "%" + args.SearchString + "%");

                case SearchOperation.DoesNotContain:
                    return String.Format(text4, args.SearchColumn, "%" + args.SearchString + "%");
            }
            throw new Exception("Invalid search operation.");
        }
Пример #2
0
 public void PerformSearch(DataView view, String search)
 {
     if (!String.IsNullOrEmpty(search) && Convert.ToBoolean(search))
     {
         GridSearch args2 = new GridSearch();
         args2.SearchColumn = this._searchColunm;
         args2.SearchString = this._searchString;
         args2.SearchOperation = this.GetSearchOperationFromString(this._searchOperation);
         GridSearch e = args2;
         try
         {
             view.RowFilter = this.ConstructFilterExpression(view, e);
         }
         catch (Exception)
         {
         }
     }
 }
Пример #3
0
        private String ConstructFilterExpression(DataView view, GridSearch args)
        {
            bool flag = false;
            if (view != null)
            {
                flag = (view.ToTable().Columns[args.SearchColumn].DataType == typeof(String)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime));
            }
            else
            {
                //JQGridColumn column = this._grid.Columns.FromDataField(args.SearchColumn);
                //if (column.SearchDataType == SearchDataType.NotSet)
                //{
                //    throw new ArgumentException("SearchDataType for the respective column must be set in order to get custom search String (where clause)");
                //}
                //flag = (column.SearchDataType == SearchDataType.String) || (column.SearchDataType == SearchDataType.Date);
            }
            String format = flag ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}";
            String text2 = "[{0}] {1} ({2})";
            String text3 = "[{0}] LIKE '{1}'";
            String text4 = "[{0}] NOT LIKE '{1}'";
            switch (args.SearchOperation)
            {
                case SearchOperation.IsEqualTo:
                    return String.Format(format, args.SearchColumn, "=", args.SearchString);

                case SearchOperation.IsLessThan:
                    return String.Format(format, args.SearchColumn, "<", args.SearchString);

                case SearchOperation.IsLessOrEqualTo:
                    return String.Format(format, args.SearchColumn, "<=", args.SearchString);

                case SearchOperation.IsGreaterThan:
                    return String.Format(format, args.SearchColumn, ">", args.SearchString);

                case SearchOperation.IsGreaterOrEqualTo:
                    return String.Format(format, args.SearchColumn, ">=", args.SearchString);

                case SearchOperation.IsIn:
                    return String.Format(text2, args.SearchColumn, "in", args.SearchString);

                case SearchOperation.IsNotIn:
                    return String.Format(text2, args.SearchColumn, "not in", args.SearchString);

                case SearchOperation.BeginsWith:
                    return String.Format(text3, args.SearchColumn, args.SearchString + "%");

                case SearchOperation.DoesNotBeginWith:
                    return String.Format(text4, args.SearchColumn, args.SearchString + "%");

                case SearchOperation.EndsWith:
                    return String.Format(text3, args.SearchColumn, "%" + args.SearchString);

                case SearchOperation.DoesNotEndWith:
                    return String.Format(text4, args.SearchColumn, "%" + args.SearchString);

                case SearchOperation.Contains:
                    return String.Format(text3, args.SearchColumn, "%" + args.SearchString + "%");

                case SearchOperation.DoesNotContain:
                    return String.Format(text4, args.SearchColumn, "%" + args.SearchString + "%");
            }
            throw new Exception("Invalid search operation.");
        }
Пример #4
0
        private String ConstructLinqFilterExpression(DataView view, GridSearch args)
        {
            bool flag = false;
            if (view != null)
            {
                flag = view.ToTable().Columns[args.SearchColumn].DataType == typeof(String);
            }
            else
            {
                //JQGridColumn column = this._grid.Columns.FromDataField(args.SearchColumn);
                //if (column.SearchDataType == SearchDataType.NotSet)
                //{
                //    throw new ArgumentException("SearchDataType for the respective column must be set in order to get custom search String (where clause)");
                //}
                //flag = column.SearchDataType == SearchDataType.String;
            }
            String format = flag ? "{0} {1} \"{2}\"" : "{0} {1} {2}";
            switch (args.SearchOperation)
            {
                case SearchOperation.IsEqualTo:
                    return String.Format(format, args.SearchColumn, "=", args.SearchString);

                case SearchOperation.IsLessThan:
                    return String.Format(format, args.SearchColumn, "<", args.SearchString);

                case SearchOperation.IsLessOrEqualTo:
                    return String.Format(format, args.SearchColumn, "<=", args.SearchString);

                case SearchOperation.IsGreaterThan:
                    return String.Format(format, args.SearchColumn, ">", args.SearchString);

                case SearchOperation.IsGreaterOrEqualTo:
                    return String.Format(format, args.SearchColumn, ">=", args.SearchString);

                case SearchOperation.BeginsWith:
                    return String.Format("{0}.BeginsWith(\"{1}\")", args.SearchColumn, args.SearchString);

                case SearchOperation.DoesNotBeginWith:
                    return String.Format("!{0}.BeginsWith(\"{1}\")", args.SearchColumn, args.SearchString);

                case SearchOperation.EndsWith:
                    return String.Format("{0}.EndsWith(\"{1}\")", args.SearchColumn, args.SearchString);

                case SearchOperation.DoesNotEndWith:
                    return String.Format("!{0}.EndsWith(\"{1}\")", args.SearchColumn, args.SearchString);

                case SearchOperation.Contains:
                    return String.Format("{0}.Contains(\"{1}\")", args.SearchColumn, args.SearchString);

                case SearchOperation.DoesNotContain:
                    return String.Format("!{0}.Contains(\"{1}\")", args.SearchColumn, args.SearchString);
            }
            throw new Exception("Invalid search operation.");
        }
Пример #5
0
        private String ConstructFilterExpression(DataView view, GridSearch args)
        {
            bool flag = false;

            if (view != null)
            {
                flag = (view.ToTable().Columns[args.SearchColumn].DataType == typeof(String)) || (view.ToTable().Columns[args.SearchColumn].DataType == typeof(DateTime));
            }
            else
            {
                //JQGridColumn column = this._grid.Columns.FromDataField(args.SearchColumn);
                //if (column.SearchDataType == SearchDataType.NotSet)
                //{
                //    throw new ArgumentException("SearchDataType for the respective column must be set in order to get custom search String (where clause)");
                //}
                //flag = (column.SearchDataType == SearchDataType.String) || (column.SearchDataType == SearchDataType.Date);
            }
            String format = flag ? "[{0}] {1} '{2}'" : "[{0}] {1} {2}";
            String text2  = "[{0}] {1} ({2})";
            String text3  = "[{0}] LIKE '{1}'";
            String text4  = "[{0}] NOT LIKE '{1}'";

            switch (args.SearchOperation)
            {
            case SearchOperation.IsEqualTo:
                return(String.Format(format, args.SearchColumn, "=", args.SearchString));

            case SearchOperation.IsLessThan:
                return(String.Format(format, args.SearchColumn, "<", args.SearchString));

            case SearchOperation.IsLessOrEqualTo:
                return(String.Format(format, args.SearchColumn, "<=", args.SearchString));

            case SearchOperation.IsGreaterThan:
                return(String.Format(format, args.SearchColumn, ">", args.SearchString));

            case SearchOperation.IsGreaterOrEqualTo:
                return(String.Format(format, args.SearchColumn, ">=", args.SearchString));

            case SearchOperation.IsIn:
                return(String.Format(text2, args.SearchColumn, "in", args.SearchString));

            case SearchOperation.IsNotIn:
                return(String.Format(text2, args.SearchColumn, "not in", args.SearchString));

            case SearchOperation.BeginsWith:
                return(String.Format(text3, args.SearchColumn, args.SearchString + "%"));

            case SearchOperation.DoesNotBeginWith:
                return(String.Format(text4, args.SearchColumn, args.SearchString + "%"));

            case SearchOperation.EndsWith:
                return(String.Format(text3, args.SearchColumn, "%" + args.SearchString));

            case SearchOperation.DoesNotEndWith:
                return(String.Format(text4, args.SearchColumn, "%" + args.SearchString));

            case SearchOperation.Contains:
                return(String.Format(text3, args.SearchColumn, "%" + args.SearchString + "%"));

            case SearchOperation.DoesNotContain:
                return(String.Format(text4, args.SearchColumn, "%" + args.SearchString + "%"));
            }
            throw new Exception("Invalid search operation.");
        }