Exemplo n.º 1
0
        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));
        }