コード例 #1
0
        public static string GetWhereClause(JQGrid grid, string searchField, string searchString, string searchOper)
        {
            string text  = " && ";
            string text2 = "";

            new Hashtable();
            Util.SearchArguments args = new Util.SearchArguments {
                SearchColumn    = searchField,
                SearchString    = searchString,
                SearchOperation = Util.GetSearchOperationFromString(searchOper)
            };
            string str  = (text2.Length > 0) ? text : "";
            string str2 = Util.ConstructLinqFilterExpression(grid, args);

            return(text2 + str + str2);
        }
コード例 #2
0
        public static string GetWhereClause(JQGrid grid, string filters)
        {
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            JsonMultipleSearch   jsonMultipleSearch   = javaScriptSerializer.Deserialize <JsonMultipleSearch>(filters);
            string text = "";

            foreach (MultipleSearchRule current in jsonMultipleSearch.rules)
            {
                Util.SearchArguments args = new Util.SearchArguments {
                    SearchColumn    = current.field,
                    SearchString    = current.data,
                    SearchOperation = Util.GetSearchOperationFromString(current.op)
                };
                string str = (text.Length > 0) ? (" " + jsonMultipleSearch.groupOp + " ") : "";
                text = text + str + Util.ConstructLinqFilterExpression(grid, args);
            }
            return(text);
        }
コード例 #3
0
        private static string ConstructLinqFilterExpression(JQGrid grid, Util.SearchArguments args)
        {
            JQGridColumn jQGridColumn = grid.Columns.Find((JQGridColumn c) => c.DataField == args.SearchColumn);

            if (jQGridColumn.DataType == null)
            {
                throw new DataTypeNotSetException("JQGridColumn.DataType must be set in order to perform search operations.");
            }
            string filterExpressionCompare = (jQGridColumn.DataType == typeof(string)) ? "{0} {1} \"{2}\"" : "{0} {1} {2}";

            if (jQGridColumn.DataType == typeof(DateTime))
            {
                DateTime dateTime = DateTime.Parse(args.SearchString);
                string   str      = string.Format("({0},{1},{2})", dateTime.Year, dateTime.Month, dateTime.Day);
                filterExpressionCompare = "{0} {1} DateTime" + str;
            }
            string str2 = string.Format("{0} != null AND ", args.SearchColumn);

            return(str2 + Util.GetLinqExpression(filterExpressionCompare, args, jQGridColumn.SearchCaseSensitive, jQGridColumn.DataType));
        }
コード例 #4
0
        public static string GetWhereClause(JQGrid grid, NameValueCollection queryString)
        {
            string text  = " && ";
            string text2 = "";

            new Hashtable();
            foreach (JQGridColumn current in grid.Columns)
            {
                string text3 = queryString[current.DataField];
                if (!string.IsNullOrEmpty(text3))
                {
                    Util.SearchArguments args = new Util.SearchArguments {
                        SearchColumn    = current.DataField,
                        SearchString    = text3,
                        SearchOperation = current.SearchToolBarOperation
                    };
                    string str  = (text2.Length > 0) ? text : "";
                    string str2 = Util.ConstructLinqFilterExpression(grid, args);
                    text2 = text2 + str + str2;
                }
            }
            return(text2);
        }
コード例 #5
0
        private static string GetLinqExpression(string filterExpressionCompare, Util.SearchArguments args, bool caseSensitive, Type dataType)
        {
            string text = caseSensitive ? args.SearchString : args.SearchString.ToLower();
            string arg  = args.SearchColumn;

            if (dataType != null && dataType == typeof(string) && !caseSensitive)
            {
                arg = string.Format("{0}.ToLower()", args.SearchColumn);
            }
            switch (args.SearchOperation)
            {
            case SearchOperation.IsEqualTo: {
                return(string.Format(filterExpressionCompare, arg, "=", text));
            }

            case SearchOperation.IsNotEqualTo: {
                return(string.Format(filterExpressionCompare, arg, "<>", text));
            }

            case SearchOperation.IsLessThan: {
                return(string.Format(filterExpressionCompare, arg, "<", text));
            }

            case SearchOperation.IsLessOrEqualTo: {
                return(string.Format(filterExpressionCompare, arg, "<=", text));
            }

            case SearchOperation.IsGreaterThan: {
                return(string.Format(filterExpressionCompare, arg, ">", text));
            }

            case SearchOperation.IsGreaterOrEqualTo: {
                return(string.Format(filterExpressionCompare, arg, ">=", text));
            }

            case SearchOperation.BeginsWith: {
                return(string.Format("{0}.StartsWith(\"{1}\")", arg, text));
            }

            case SearchOperation.DoesNotBeginWith: {
                return(string.Format("!{0}.StartsWith(\"{1}\")", arg, text));
            }

            case SearchOperation.EndsWith: {
                return(string.Format("{0}.EndsWith(\"{1}\")", arg, text));
            }

            case SearchOperation.DoesNotEndWith: {
                return(string.Format("!{0}.EndsWith(\"{1}\")", arg, text));
            }

            case SearchOperation.Contains: {
                return(string.Format("{0}.Contains(\"{1}\")", arg, text));
            }

            case SearchOperation.DoesNotContain: {
                return(string.Format("!{0}.Contains(\"{1}\")", arg, text));
            }
            }
            throw new Exception("Invalid search operation.");
        }
コード例 #6
0
        internal static string ConstructLinqFilterExpression(JQAutoComplete autoComplete, Util.SearchArguments args)
        {
            Guard.IsNotNull(autoComplete.DataField, "DataField", "must be set in order to perform search operations. If you get this error from search/export method, make sure you setup(initialize) the grid again prior to filtering/exporting.");
            string filterExpressionCompare = "{0} {1} \"{2}\"";

            return(Util.GetLinqExpression(filterExpressionCompare, args, false, typeof(string)));
        }