internal static JsonResult ConvertToTreeJson(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     return(new JsonResult {
         JsonRequestBehavior = JsonRequestBehavior.AllowGet,
         Data = Util.PrepareJsonTreeResponse(response, grid, dt)
     });
 }
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         response.rows[i] = new Hashtable();
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             JQGridColumn jQGridColumn = grid.Columns[j];
             string       value        = "";
             if (!string.IsNullOrEmpty(jQGridColumn.DataField))
             {
                 int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal;
                 value = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode));
             }
             response.rows[i].Add(jQGridColumn.DataField, value);
         }
         try {
             response.rows[i].Add("tree_level", dt.Rows[i]["tree_level"] as int?);
         } catch {
         }
         try {
             response.rows[i].Add("tree_parent", Convert.ToString(dt.Rows[i]["tree_parent"]));
         } catch {
         }
         try {
             response.rows[i].Add("tree_leaf", dt.Rows[i]["tree_leaf"] as bool?);
         } catch {
         }
         try {
             response.rows[i].Add("tree_expanded", dt.Rows[i]["tree_expanded"] as bool?);
         } catch {
         }
         try {
             response.rows[i].Add("tree_loaded", dt.Rows[i]["tree_loaded"] as bool?);
         } catch {
         }
         try {
             response.rows[i].Add("tree_icon", dt.Rows[i]["tree_icon"] as string);
         } catch {
         }
     }
     return(response);
 }
        private JsonResult FilterDataSource(object dataSource, NameValueCollection queryString, out IQueryable iqueryable)
        {
            iqueryable = (dataSource as IQueryable);
            Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface.");
            int    num          = Convert.ToInt32(queryString["page"]);
            int    num2         = Convert.ToInt32(queryString["rows"]);
            string text         = queryString["sidx"];
            string str          = queryString["sord"];
            string arg_5E_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 = num;
            this.PagerSettings.PageSize    = num2;
            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 (Exception) {
                    return(new JsonResult {
                        Data = new object(),
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet
                    });
                }
            }
            int num3            = iqueryable.Count();
            int totalPagesCount = (int)Math.Ceiling((double)((float)num3 / (float)num2));

            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.Split(new char[]
                    {
                        ' '
                    })[1].Split(new char[]
                    {
                        ','
                    })[0];
                    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 = iqueryable.Skip((num - 1) * num2).Take(num2);
            DataTable dataTable = iqueryable.ToDataTable(this);

            this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable));
            if (this.TreeGridSettings.Enabled)
            {
                JsonTreeResponse response = new JsonTreeResponse(num, totalPagesCount, num3, num2, dataTable.Rows.Count, Util.GetFooterInfo(this));
                return(Util.ConvertToTreeJson(response, this, dataTable));
            }
            JsonResponse response2 = new JsonResponse(num, totalPagesCount, num3, num2, dataTable.Rows.Count, Util.GetFooterInfo(this));

            return(Util.ConvertToJson(response2, this, dataTable));
        }