private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable) { iqueryable = dataSource as IQueryable; Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface."); int currentPage = 0; int count = 0; string primaryKeyField = ""; string str2 = ""; string text1 = ""; string str3 = ""; string str4 = ""; string str5 = ""; string searchString = ""; string searchOper = ""; currentPage = Convert.ToInt32(queryString["page"]); count = Convert.ToInt32(queryString["rows"]); primaryKeyField = queryString["sidx"]; str2 = queryString["sord"]; text1 = queryString["parentRowID"]; str3 = queryString["_search"]; str4 = queryString["filters"]; str5 = queryString["searchField"]; searchString = queryString["searchString"]; searchOper = queryString["searchOper"]; this.PagerSettings.CurrentPage = currentPage; this.PagerSettings.PageSize = count; if (!string.IsNullOrEmpty(str3) && (str3 != "false"))//ËÑË÷ { try { if (string.IsNullOrEmpty(str4) && !string.IsNullOrEmpty(str5)) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str5, searchString, searchOper), new object[0]); } else if (!string.IsNullOrEmpty(str4)) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str4), new object[0]); } else if (this.ToolBarSettings.ShowSearchToolBar || (str3 == "true")) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, queryString), new object[0]); } } catch (DataTypeNotSetException exception) { throw exception; } catch (Exception) { JsonResult result = new JsonResult(); result.Data = new object(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return(result); } } int totalRowCount = 0; int totalPagesCount = 0; totalRowCount = iqueryable.Count(); totalPagesCount = (int)Math.Ceiling((double)(((float)totalRowCount) / ((float)count))); if (string.IsNullOrEmpty(primaryKeyField)) { if (this.Columns.Count == 0) { throw new Exception("JQGrid must have at least one column defined."); } primaryKeyField = Trirand.Web.Mvc.Util.GetPrimaryKeyField(this); str2 = "asc"; } if (!string.IsNullOrEmpty(primaryKeyField)) { string ordering = ""; if (this.GroupSettings.GroupFields.Count > 0) { string str9 = primaryKeyField.Split(new char[] { ' ' })[0]; string str10 = primaryKeyField.Split(new char[] { ' ' })[1].Split(new char[] { ',' })[0]; primaryKeyField = primaryKeyField.Split(new char[] { ',' })[1]; ordering = str9 + " " + str10; } if ((primaryKeyField != null) && (primaryKeyField == " ")) { primaryKeyField = ""; } if (!string.IsNullOrEmpty(primaryKeyField)) { if ((this.GroupSettings.GroupFields.Count > 0) && !ordering.EndsWith(",")) { ordering = ordering + ","; } ordering = ordering + primaryKeyField + " " + str2; } iqueryable = iqueryable.OrderBy(ordering, new object[0]); } iqueryable = iqueryable.Skip(((currentPage - 1) * count)).Take(count); DataTable dt = iqueryable.ToDataTable(this); this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable)); JsonResponse response = new JsonResponse(currentPage, totalPagesCount, totalRowCount, count, dt.Rows.Count, Trirand.Web.Mvc.Util.GetFooterInfo(this)); return(Trirand.Web.Mvc.Util.ConvertToJson(response, this, dt)); }
private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable) { iqueryable = dataSource as IQueryable; Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface."); int pageIndex = this.GetPageIndex(queryString["page"]); int count = Convert.ToInt32(queryString["rows"]); string primaryKeyField = queryString["sidx"]; string sortDirection = queryString["sord"]; string text1 = queryString["parentRowID"]; string str3 = queryString["_search"]; string str4 = queryString["filters"]; string str5 = queryString["searchField"]; string searchString = queryString["searchString"]; string searchOper = queryString["searchOper"]; this.PagerSettings.CurrentPage = pageIndex; this.PagerSettings.PageSize = count; if (!string.IsNullOrEmpty(str3) && (str3 != "false")) { try { if (string.IsNullOrEmpty(str4) && !string.IsNullOrEmpty(str5)) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str5, searchString, searchOper), new object[0]); } else if (!string.IsNullOrEmpty(str4)) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, str4), new object[0]); } else if (this.ToolBarSettings.ShowSearchToolBar || (str3 == "true")) { iqueryable = iqueryable.Where(Trirand.Web.Mvc.Util.GetWhereClause(this, queryString), new object[0]); } } catch (DataTypeNotSetException exception) { throw exception; } catch (Exception) { return new JsonResult { Data = new object(), JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } } int totalRowCount = iqueryable.Count(); int totalPagesCount = (int) Math.Ceiling((double) (((float) totalRowCount) / ((float) count))); if (string.IsNullOrEmpty(primaryKeyField) && this.SortSettings.AutoSortByPrimaryKey) { if (this.Columns.Count == 0) { throw new Exception("JQGrid must have at least one column defined."); } primaryKeyField = Trirand.Web.Mvc.Util.GetPrimaryKeyField(this); sortDirection = "asc"; } if (!string.IsNullOrEmpty(primaryKeyField)) { iqueryable = iqueryable.OrderBy(this.GetSortExpression(primaryKeyField, sortDirection), new object[0]); } iqueryable = iqueryable.Skip(((pageIndex - 1) * count)).Take(count); DataTable dt = iqueryable.ToDataTable(this); this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable)); if (this.TreeGridSettings.Enabled) { JsonTreeResponse response = new JsonTreeResponse(pageIndex, totalPagesCount, totalRowCount, count, dt.Rows.Count, Trirand.Web.Mvc.Util.GetFooterInfo(this)); return Trirand.Web.Mvc.Util.ConvertToTreeJson(response, this, dt); } JsonResponse response2 = new JsonResponse(pageIndex, totalPagesCount, totalRowCount, count, dt.Rows.Count, Trirand.Web.Mvc.Util.GetFooterInfo(this)); return Trirand.Web.Mvc.Util.ConvertToJson(response2, this, dt); }
internal static string ConvertToJsonString(JsonResponse response, JQGrid grid, DataTable dt) { return(new JavaScriptSerializer().Serialize(PrepareJsonResponse(response, grid, dt))); }
internal static JsonResponse PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt) { for (int i = 0; i < dt.Rows.Count; i++) { string[] strArray = new string[grid.Columns.Count]; for (int j = 0; j < grid.Columns.Count; j++) { JQGridColumn column = grid.Columns[j]; string str = ""; if (!string.IsNullOrEmpty(column.DataField)) { int ordinal = dt.Columns[column.DataField].Ordinal; str = string.IsNullOrEmpty(column.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : column.FormatDataValue(dt.Rows[i].ItemArray[ordinal], column.HtmlEncode); } strArray[j] = str; } string str2 = strArray[GetPrimaryKeyIndex(grid)]; JsonRow row = new JsonRow { id = str2, cell = strArray }; response.rows[i] = row; } return response; }
internal static JsonResult ConvertToJson(JsonResponse response, JQGrid grid, DataTable dt) { JsonResult result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet }; if (response.records == 0) { if (grid.AppearanceSettings.ShowFooter) { result.Data = PrepareJsonResponse(response, grid, dt); return result; } result.Data = new object[0]; return result; } result.Data = PrepareJsonResponse(response, grid, dt); return result; }
//public ActionResult ShowEditValidationMessage(string errorMessage) //{ // HttpContext.Current.Response.Clear(); // HttpContext.Current.Response.StatusCode = 500; // HttpContext.Current.Response.TrySkipIisCustomErrors = true; // return new ContentResult // { // Content = errorMessage, // }; //} //private IQueryable FilterDataSource2(object dataSource, NameValueCollection queryString) //{ // IQueryable iqueryable = (dataSource as IQueryable); // Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface."); // int pageIndex = this.GetPageIndex(queryString["page"]); // int num = Convert.ToInt32(queryString["rows"]); // string text = queryString["sidx"]; // string str = queryString["sord"]; // string arg_5F_0 = queryString["parentRowID"]; // string text2 = queryString["_search"]; // string text3 = queryString["filters"]; // string text4 = queryString["searchField"]; // string searchString = queryString["searchString"]; // string searchOper = queryString["searchOper"]; // this.PagerSettings.CurrentPage = pageIndex; // this.PagerSettings.PageSize = num; // if (!string.IsNullOrEmpty(text2) && text2 != "false") // { // try // { // if (string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text4)) // { // iqueryable = iqueryable.Where(Util.GetWhereClause(this, text4, searchString, searchOper), new object[0]); // } // else // { // if (!string.IsNullOrEmpty(text3)) // { // iqueryable = iqueryable.Where(Util.GetWhereClause(this, text3), new object[0]); // } // else // { // if (this.ToolBarSettings.ShowSearchToolBar || text2 == "true") // { // iqueryable = iqueryable.Where(Util.GetWhereClause(this, queryString), new object[0]); // } // } // } // } // catch (DataTypeNotSetException ex) // { // throw ex; // } // catch (ParseException pex) // { // throw pex; // } // catch (Exception ex) // { // throw ex; // } // } // int num2 = iqueryable.Count(); // int totalPagesCount = (int)Math.Ceiling((double)((float)num2 / (float)num)); // if (string.IsNullOrEmpty(text) && this.SortSettings.AutoSortByPrimaryKey) // { // if (this.Columns.Count == 0) // { // throw new Exception("JQGrid must have at least one column defined."); // } // text = Util.GetPrimaryKeyField(this); // str = "asc"; // } // if (!string.IsNullOrEmpty(text)) // { // string text5 = ""; // if (this.GroupSettings.GroupFields.Count > 0) // { // string str2 = text.Split(new char[] // { // ' ' // })[0]; // string str3 = text.Contains(" ") ? text.Split(new char[] // { // ' ' // })[1].Split(new char[] // { // ',' // })[0] : "asc"; // if (text.Contains(",")) // { // text = text.Split(new char[] // { // ',' // })[1]; // } // text5 = str2 + " " + str3; // } // if (text != null && text == " ") // { // text = ""; // } // if (!string.IsNullOrEmpty(text)) // { // if (this.GroupSettings.GroupFields.Count > 0 && !text5.EndsWith(",")) // { // text5 += ","; // } // text5 = text5 + text + " " + str; // } // iqueryable = iqueryable.OrderBy(text5, new object[0]); // } // return iqueryable; //} private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable) { iqueryable = (dataSource as IQueryable); IQueryable ignoreFilterFieldData = iqueryable; Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface."); int pageIndex = this.GetPageIndex(queryString["page"]); int num = Convert.ToInt32(queryString["rows"]); string text = queryString["sidx"]; string str = queryString["sord"]; string arg_5F_0 = queryString["parentRowID"]; bool isSearch = false; string search = queryString["_search"]; if (!string.IsNullOrEmpty(search)) { isSearch = search.ToLower() == "true"; } //if(!string.IsNullOrEmpty(this.ClientSideEvents.SerializeGridData)) //{ // text2 = "true"; //} //if (!string.IsNullOrEmpty(this.ExcelExportSettings.Url)) //{ // text2 = "true"; //} string filters = queryString["filters"]; string searchFiled = queryString["searchField"]; string searchString = queryString["searchString"]; string searchOper = queryString["searchOper"]; this.PagerSettings.CurrentPage = pageIndex; this.PagerSettings.PageSize = num; if (isSearch) { try { //search if (!string.IsNullOrEmpty(searchFiled)) { ignoreFilterFieldData = ignoreFilterFieldData.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]); iqueryable = iqueryable.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]); } //else //{ //filters if (!string.IsNullOrEmpty(filters)) { ignoreFilterFieldData = ignoreFilterFieldData.Where(Util.GetWhereClause(this, filters, this.IgnoreFilterField), new object[0]); iqueryable = iqueryable.Where(Util.GetWhereClause(this, filters), new object[0]); } //else if (!string.IsNullOrEmpty(filters) && !string.IsNullOrEmpty(searchFiled)) //{ // //filters+search // iqueryable = iqueryable.Where(Util.GetWhereClause(this, searchFiled, searchString, searchOper), new object[0]); // iqueryable = iqueryable.Where(Util.GetWhereClause(this, filters), new object[0]); //} //else //{ //if (this.ToolBarSettings.ShowSearchToolBar || isSearch) //{ string whereStr = Util.GetWhereClause(this, queryString); if (!string.IsNullOrEmpty(whereStr)) { ignoreFilterFieldData = ignoreFilterFieldData.Where(whereStr, new object[0]); iqueryable = iqueryable.Where(whereStr, new object[0]); } //} //} //} } catch (DataTypeNotSetException ex) { throw ex; } catch (ParseException) { return(new JsonResult { Data = new { Error = "表达式错误" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } catch (Exception) { return(new JsonResult { Data = new object(), JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } } int num2 = iqueryable.Count(); int totalPagesCount = (int)Math.Ceiling((double)((float)num2 / (float)num)); if (string.IsNullOrEmpty(text) && this.SortSettings.AutoSortByPrimaryKey) { if (this.Columns.Count == 0) { throw new Exception("JQGrid must have at least one column defined."); } text = Util.GetPrimaryKeyField(this); str = "asc"; } if (!string.IsNullOrEmpty(text)) { string text5 = ""; if (this.GroupSettings.GroupFields.Count > 0) { string str2 = text.Split(new char[] { ' ' })[0]; string str3 = text.Contains(" ") ? text.Split(new char[] { ' ' })[1].Split(new char[] { ',' })[0] : "asc"; if (text.Contains(",")) { text = text.Split(new char[] { ',' })[1]; } text5 = str2 + " " + str3; } if (text != null && text == " ") { text = ""; } if (!string.IsNullOrEmpty(text)) { if (this.GroupSettings.GroupFields.Count > 0 && !text5.EndsWith(",")) { text5 += ","; } text5 = text5 + text + " " + str; } iqueryable = iqueryable.OrderBy(text5, new object[0]); } IQueryable filterData = iqueryable; iqueryable = iqueryable.Skip((pageIndex - 1) * num).Take(num); DataTable dataTable = iqueryable.ToDataTable(this); this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable, filterData, ignoreFilterFieldData)); if (this.TreeGridSettings.Enabled) { JsonTreeResponse response = new JsonTreeResponse(pageIndex, totalPagesCount, num2, num, dataTable.Rows.Count, Util.GetFooterInfo(this)); return(Util.ConvertToTreeJson(response, this, dataTable)); } JsonResponse response2 = new JsonResponse(pageIndex, totalPagesCount, num2, num, dataTable.Rows.Count, Util.GetFooterInfo(this)); return(Util.ConvertToJson(response2, this, dataTable)); }