예제 #1
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
        internal static JsonResult ConvertToTreeJson(JsonTreeResponse response, JQGrid grid, DataTable dt)
        {
            JsonResult jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.DenyGet;
            jsonResult.Data = Util.PrepareJsonTreeResponse(response, grid, dt);
            return(jsonResult);
        }
예제 #2
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
        internal static JsonResult ConvertToTreeJson <TEntity>(JsonTreeResponse response, JQGrid grid, IQueryable <TEntity> Data) where TEntity : class
        {
            JsonResult jsonResult = new JsonResult();

            jsonResult.JsonRequestBehavior = JsonRequestBehavior.DenyGet;
            jsonResult.Data = Util.PrepareJsonTreeResponse(response, grid, Data);
            return(jsonResult);
        }
예제 #3
0
        public JsonResult DataBind(IQueryable <T> dataSource)
        {
            AjaxCallBackMode ajaxCallBackMode = this.AjaxCallBackMode;

            if (ajaxCallBackMode != AjaxCallBackMode.RequestData)
            {
                return(null);
            }

            HttpRequest request = HttpContext.Current.Request;

            if (request == null)
            {
                throw new Exception("Cannot Get Request Variable");
            }
            NameValueCollection queryString = request.HttpMethod == "POST" ? request.Form : request.QueryString;

            IQueryable <T> iqueryable = dataSource;

            Guard.IsNotNull(iqueryable, "DataSource", "should implement the IQueryable interface.");
            int    pageIndex     = this.GetPageIndex(queryString["page"]);
            int    num           = this.GetNum(queryString["rows"]);
            string text          = queryString["sidx"];
            string sortDirection = queryString["sord"];
            string parentRowID   = queryString["parentRowID"];
            bool   search        = (!string.IsNullOrEmpty(queryString["_search"]) && queryString["_search"] != "false");
            string filters       = queryString["filters"];
            string searchField   = queryString["searchField"];
            string searchString  = queryString["searchString"];
            string searchOper    = queryString["searchOper"];

            this.PagerSettings.CurrentPage = pageIndex;
            this.PagerSettings.PageSize    = num;
            if (search)
            {
                try
                {
                    if (string.IsNullOrEmpty(filters) && !string.IsNullOrEmpty(searchField))
                    {
                        iqueryable = iqueryable.Where(Util.GetWhereClause(this, searchField, searchString, searchOper));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(filters))
                        {
                            iqueryable = iqueryable.Where(Util.GetWhereClause(this, filters));
                        }
                        else
                        {
                            if (this.ToolBarSettings.ShowSearchToolBar || search)
                            {
                                iqueryable = iqueryable.Where(Util.GetWhereClause(this, queryString));
                            }
                        }
                    }
                }
                catch (DataTypeNotSetException ex)
                {
                    throw ex;
                }
                catch (Exception)
                {
                    JsonResult jsonResult = new JsonResult();
                    jsonResult.JsonRequestBehavior = JsonRequestBehavior.DenyGet;
                    jsonResult.Data = new object();
                    return(jsonResult);
                }
            }
            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);
                sortDirection = "asc";
            }
            if (!string.IsNullOrEmpty(text))
            {
                iqueryable = iqueryable.OrderBy(this.GetSortExpression(text, sortDirection));
            }
            iqueryable = iqueryable.Skip((pageIndex - 1) * num).Take(num);
            this.OnDataResolved(new JQGridDataResolvedEventArgs(this, iqueryable, this.DataSource as IQueryable));
            if (this.TreeGridSettings.Enabled)
            {
                JsonTreeResponse response = new JsonTreeResponse(pageIndex, totalPagesCount, num2, num, iqueryable.Count(), Util.GetFooterInfo(this));
                return(Util.ConvertToTreeJson(response, this, iqueryable));
            }
            JsonResponse response2 = new JsonResponse(pageIndex, totalPagesCount, num2, num, iqueryable.Count(), Util.GetFooterInfo(this));

            return(Util.ConvertToJson(response2, this, iqueryable));
        }
예제 #4
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
 internal static JsonTreeResponse PrepareJsonTreeResponse(JsonTreeResponse response, JQGrid grid, DataTable dt, IQueryable data = null)
 {
     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
         {
             object obj = dt.Rows[i]["tree_parent"];
             string value2;
             if (obj is DBNull)
             {
                 value2 = "null";
             }
             else
             {
                 value2 = Convert.ToString(dt.Rows[i]["tree_parent"]);
             }
             response.rows[i].Add("tree_parent", value2);
         }
         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);
 }
예제 #5
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
        internal static JsonTreeResponse PrepareJsonTreeResponse <TEntity>(JsonTreeResponse response, JQGrid grid, IQueryable <TEntity> data = null) where TEntity : class
        {
            PropertyInfo[] properties = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            int            i          = 0;

            foreach (object c in data)
            {
                List <string> ar = new List <string>();
                foreach (JQGridColumn t in grid.Columns)
                {
                    foreach (PropertyInfo prop in properties)
                    {
                        if (t.DataField.ToLower().Equals(prop.Name.ToLower()))
                        {
                            response.rows[i].Add(t.DataField, prop.GetValue(c, null).ToString());
                            break;
                        }
                    }
                    response.rows[i].Add(t.DataField, "");
                }
                bool   tree_levelExist    = false;
                bool   tree_parentExist   = false;
                bool   tree_leafExist     = false;
                bool   tree_expandedExist = false;
                bool   tree_loadedExist   = false;
                bool   tree_iconExist     = false;
                int    tree_level         = 0;
                string tree_parent        = "null";
                bool   tree_leaf          = false;
                bool   tree_expanded      = false;
                bool   tree_loaded        = false;
                string tree_icon          = "";
                foreach (PropertyInfo prop in properties)
                {
                    if (prop.Name.ToLower() == "tree_level")
                    {
                        tree_levelExist = true;
                        try
                        {
                            tree_level = int.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_level", tree_level);
                    }
                    if (prop.Name.ToLower() == "tree_parent")
                    {
                        tree_parentExist = true;
                        try
                        {
                            tree_parent = prop.GetValue(c, null).ToString();
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_parent", tree_parent);
                    }
                    if (prop.Name.ToLower() == "tree_leaf")
                    {
                        tree_leafExist = true;
                        try
                        {
                            tree_leaf = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_leaf", tree_leaf);
                    }
                    if (prop.Name.ToLower() == "tree_expanded")
                    {
                        tree_expandedExist = true;
                        try
                        {
                            tree_expanded = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_expanded", tree_expanded);
                    }
                    if (prop.Name.ToLower() == "tree_loaded")
                    {
                        tree_loadedExist = true;
                        try
                        {
                            tree_loaded = bool.Parse(prop.GetValue(c, null).ToString());
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_loaded", tree_loaded);
                    }
                    if (prop.Name.ToLower() == "tree_icon")
                    {
                        tree_iconExist = true;
                        try
                        {
                            tree_icon = prop.GetValue(c, null).ToString();
                        }
                        catch (Exception)
                        {
                        }
                        response.rows[i].Add("tree_icon", tree_icon);
                    }
                }
                if (!tree_levelExist)
                {
                    response.rows[i].Add("tree_level", tree_level);
                }
                if (!tree_parentExist)
                {
                    response.rows[i].Add("tree_parent", tree_parent);
                }
                if (!tree_leafExist)
                {
                    response.rows[i].Add("tree_leaf", tree_leaf);
                }
                if (!tree_expandedExist)
                {
                    response.rows[i].Add("tree_expanded", tree_expanded);
                }
                if (!tree_loadedExist)
                {
                    response.rows[i].Add("tree_loaded", tree_loaded);
                }
                if (!tree_iconExist)
                {
                    response.rows[i].Add("tree_icon", tree_icon);
                }
                i++;
            }
            return(response);
        }