private static string ConstructLinqFilterExpression(JQGrid grid, Util.SearchArguments args) { JQGridColumn jQGridColumn = grid.Columns.Find((JQGridColumn c) => c.DataField == args.SearchColumn); if (jQGridColumn == null) { throw new Exception("JqGridColumn ûÓÐÉèÖÃ"); } 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)) { if (!string.IsNullOrEmpty(args.SearchString)) { DateTime dateTime = DateTime.Parse(args.SearchString); string str = string.Format("({0},{1},{2},{3},{4},{5})", dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second); filterExpressionCompare = "{0} {1} DateTime" + str; } } //string str2 = string.Format("{0} != null AND ", args.SearchColumn); string str2 = ""; if (jQGridColumn.DataType == typeof(Guid)) { filterExpressionCompare = "{0} {1} Guid(\"{2}\")"; //str2 = "";//string.Format("{0} != Guid.Empty AND ", args.SearchColumn); } return(str2 + Util.GetLinqExpression(filterExpressionCompare, args, jQGridColumn.SearchCaseSensitive, jQGridColumn.DataType)); }
public static string GetWhereClause(JQGrid grid, string filters, string ignoreFilterField) { JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); JsonMultipleSearch jsonMultipleSearch = javaScriptSerializer.Deserialize <JsonMultipleSearch>(filters); string text = ""; foreach (MultipleSearchRule current in jsonMultipleSearch.rules) { if (string.IsNullOrEmpty(current.op)) { continue; } if (!string.IsNullOrWhiteSpace(ignoreFilterField) && current.field == ignoreFilterField) { continue; } 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); }
private JsonResult GetJsonResponse() { Guard.IsNotNull(this.DataSource, "DataSource"); IQueryable dataSource = this.DataSource as IQueryable; Guard.IsNotNull(dataSource, "DataSource", "should implement the IQueryable interface."); Guard.IsNotNullOrEmpty(this.DataField, "DataField", "should be set to the datafield (column) of the datasource to search in."); SearchOperation isEqualTo = SearchOperation.IsEqualTo; if (this.AutoCompleteMode == Trirand.Web.Mvc.AutoCompleteMode.BeginsWith) { isEqualTo = SearchOperation.BeginsWith; } else { isEqualTo = SearchOperation.Contains; } string str = HttpContext.Current.Request.QueryString["term"]; if (!string.IsNullOrEmpty(str)) { Util.SearchArguments args = new Util.SearchArguments(); args.SearchColumn = this.DataField; args.SearchOperation = isEqualTo; args.SearchString = str; dataSource = dataSource.Where(Util.ConstructLinqFilterExpression(this, args), new object[0]); } JsonResult result2 = new JsonResult(); result2.JsonRequestBehavior = JsonRequestBehavior.AllowGet; result2.Data = dataSource.ToListOfString(this); return(result2); }
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: if (string.IsNullOrEmpty(text)) { return("1=1"); } 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."); }
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); }
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); }
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))); }
private JsonResult GetJsonResponse() { Guard.IsNotNull(this.DataSource, "DataSource"); IQueryable dataSource = this.DataSource as IQueryable; Guard.IsNotNull(dataSource, "DataSource", "should implement the IQueryable interface."); Guard.IsNotNullOrEmpty(this.DataField, "DataField", "should be set to the datafield (column) of the datasource to search in."); SearchOperation isEqualTo = SearchOperation.IsEqualTo; if (this.AutoCompleteMode == Trirand.Web.Mvc.AutoCompleteMode.BeginsWith) { isEqualTo = SearchOperation.BeginsWith; } else { isEqualTo = SearchOperation.Contains; } string str = HttpContext.Current.Request.QueryString["term"]; if (!string.IsNullOrEmpty(str)) { Util.SearchArguments args = new Util.SearchArguments { SearchColumn = this.DataField, SearchOperation = isEqualTo, SearchString = str }; dataSource = dataSource.Where(Util.ConstructLinqFilterExpression(this, args), new object[0]); } return new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = dataSource.ToListOfString(this) }; }