コード例 #1
0
 /// <summary>
 /// 获取显示数据的json格试
 /// </summary>
 /// <param name="pagination">页面信息</param>
 /// <param name="keyword">搜索关键字</param>
 /// <returns></returns>
 public ActionResult GetGridJson(Pagination pagination, string keyword, string _search, string filters)
 {
     try
     {
         string      str      = "";
         List <role> list     = null;
         List <role> rolelist = null;
         //pagination.records = IdalCommon.IroleEx.getRoleList(keyword).Count;
         Dictionary <string, object> dictionary = new Dictionary <string, object>();
         dictionary.Add("rolename", keyword);
         if (_search == "true")
         {
             str = JqGridHandler.getWhere(filters);
             if (str != "")
             {
                 str  = "select * from role where" + "  " + str;
                 list = IdalCommon.IroleEx.getSearch(str);
                 pagination.records = list.Count();
                 rolelist           = IdalCommon.IroleEx.getPaginationEntityList(pagination.page, pagination.rows, list);
             }
         }
         else
         {
             pagination.records = IdalCommon.IroleEx.getRoleList(keyword).Count();
             rolelist           = IdalCommon.IroleEx.getPaginationEntityList(pagination.page, pagination.rows, dictionary);
         }
         var data = new
         {
             rows    = rolelist,
             total   = pagination.total,
             page    = pagination.page,
             records = pagination.records
         };
         return(Content(data.ToJson()));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        /// <summary>
        /// 获得一个tree型网格数据
        /// </summary>
        /// <param name="pagination">分页栏信息</param>
        /// <param name="keyword">名称(筛选条件)</param>
        /// <returns></returns>
        public ActionResult GetTreeGridJson(Pagination pagination, string keyword, string _search, string filters)
        {
            try
            {
                string          strValue     = "";
                List <resource> data         = IdalCommon.IresourceEx.getEntityList();
                List <resource> resourcelist = null;
                pagination.records = data.Count();
                var             treeList = new List <TreeGridModel>();
                var             p        = (pagination.page - 1) * pagination.rows;
                List <resource> dlist    = new List <resource>();
                if (_search == "true")
                {
                    strValue = JqGridHandler.getWhere(filters);
                    if (strValue != "")
                    {
                        strValue           = "select * from role where" + "  " + strValue;
                        data               = IdalCommon.IresourceEx.getSearch(strValue);
                        pagination.records = data.Count();
                        resourcelist       = IdalCommon.IresourceEx.getPaginationEntityList(pagination.page, pagination.rows, data);
                    }
                }
                else
                {
                    data = IdalCommon.IresourceEx.getResourceList(keyword);
                    pagination.records = data.Count();
                    resourcelist       = data.Skip(p).Take(pagination.rows).ToList();
                }
                /**************判断当前页的数据的父节点都包含在当前页中,不是则把父节点存入当前页*******************/

                foreach (resource re in resourcelist)
                {
                    if (!string.IsNullOrEmpty(re.resourceowner) && re.resourceowner != "0")
                    {
                        int count = resourcelist.Where(d => d.id.ToString() == re.resourceowner).Count();
                        if (count == 0)
                        {
                            resource rr = data.Where(d => d.id.ToString() == re.resourceowner).FirstOrDefault();
                            if (rr != null)
                            {
                                dlist.Add(rr);
                            }
                        }
                    }
                }
                if (dlist.Count() > 0 && dlist != null)
                {
                    dlist = dlist.Where((x, i) => dlist.FindIndex(z => z.id == x.id) == i).ToList();
                    resourcelist.AddRange(dlist);
                }
                /*************获取当前页需要显示的数据********************/
                foreach (resource item in resourcelist)
                {
                    TreeGridModel treeModel   = new TreeGridModel();
                    bool          hasChildren = data.Count(t => t.resourceowner == item.id.ToString()) == 0 ? false : true;
                    treeModel.id     = item.id.ToString();
                    treeModel.isLeaf = hasChildren;
                    if (item.resourceowner == null)
                    {
                        treeModel.parentId = "0";
                    }
                    else
                    {
                        treeModel.parentId = item.resourceowner;
                    }
                    treeModel.expanded   = hasChildren;
                    treeModel.entityJson = item.ToJson();
                    treeList.Add(treeModel);
                }
                string str = treeList.TreeGridJson().Substring(0, treeList.TreeGridJson().Length - 1) + ",\"total\":" + pagination.total + ",\"page\":" + pagination.page + ",\"records\":" + pagination.records + "}";
                return(Content(str));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }