Esempio n. 1
0
        /// <summary>
        /// 初始化树形菜单
        /// </summary>
        /// <param name="context"></param>
        private void MenuInit(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            DataSet ds = new DataSet();

            strWhere = " and ParentID=0 and IsInUse=1 ";
            int uid = int.Parse(context.Session["uId"].ToString());

            ds = bll.GetMenuListByUser(uid, strWhere);
            DataTable dt = ds.Tables[0];

            parentJson = "[";
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string menuname = dt.Rows[i]["MenuName"].ToString();
                    int    pid      = int.Parse(dt.Rows[i]["ID"].ToString());
                    parentJson += "{\"name\": \"" + menuname + "\", \"open\": false, \"children\": [";
                    childWhere  = " and ParentID=" + pid + " and IsInUse=1 ";
                    DataTable dt_child = bll.GetMenuListByUser(uid, childWhere).Tables[0];
                    if (dt_child.Rows.Count > 0)
                    {
                        for (int j = 0; j < dt_child.Rows.Count; j++)
                        {
                            string menuchildname = dt_child.Rows[j]["MenuName"].ToString();
                            string childurl      = dt_child.Rows[j]["MenuUrl"].ToString();
                            parentJson += "{\"name\": \"" + menuchildname + "\", \"url\": \"" + childurl + "\", \"target\": \"main\" },";
                        }
                        if (parentJson.EndsWith(","))
                        {
                            parentJson = parentJson.Remove(parentJson.Length - 1, 1);
                        }
                    }
                    parentJson += "]},";
                }
                if (parentJson.EndsWith(","))
                {
                    parentJson = parentJson.Remove(parentJson.Length - 1, 1);
                }
            }
            parentJson += "]";
            string strJson = parentJson;

            context.Response.Write(parentJson);
            context.Response.End();
        }
Esempio n. 2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public DataSet GetInfoDS()
        {
            BLL.Sys_MenuBLL bll_menu = new BLL.Sys_MenuBLL();
            strWhere = " and ParentID=0 ";
            int     uid = int.Parse(Session["uId"].ToString());
            DataSet ds  = bll_menu.GetMenuListByUser(uid, strWhere);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(ds);
            }
            else
            {
                return(null);
            }
        }