예제 #1
0
        public string GetRolefunction2()
        {
            string roleID = Session["selectedRoleID"] as string;
            IRolefunctionService roleFunction = UnityHelper.UnityResolve <IRolefunctionService>();
            DataSet roleFunctionDS            = roleFunction.GetRolefunctionByQueryList(new QueryEntity {
                IsGetAll = true, sqlWhere = new List <string> {
                    "roleID='" + roleID + "'"
                }
            });

            IFunctiongroupService tmpService = UnityHelper.UnityResolve <IFunctiongroupService>();
            var data = tmpService.GetFunctionGroupByRoleID(Int32.Parse(roleID));

            DataRow[]     drlv1  = data.Tables[0].Select("ParentID=1000");
            StringBuilder sbRole = new StringBuilder();

            for (int i = 0; i < drlv1.Length; i++)
            {
                sbRole.Append("{\"id\":" + drlv1[i]["FunctionID"].ToString() + ",\"text\":\"" + drlv1[i]["UDF01"].ToString() + "\",\"state\":\"closed\",\"children\":[");

                DataRow[] drlv2 = data.Tables[0].Select(string.Format("ParentID='{0}'", drlv1[i]["FunctionID"].ToString()));
                for (int j = 0; j < drlv2.Length; j++)
                {
                    string ischecked = string.Empty;
                    if (!string.IsNullOrEmpty(drlv2[j]["checked_functionID"].ToString()))
                    {
                        ischecked = "true";
                    }
                    else
                    {
                        ischecked = "false";
                    }

                    sbRole.Append("{\"id\":" + drlv2[j]["FunctionID"].ToString() + ",\"text\":\"" + drlv2[j]["UDF01"].ToString() + "\",\"checked\":" + ischecked + "}");
                    if (j != drlv2.Length - 1)
                    {
                        sbRole.Append(",");
                    }
                }
                sbRole.Append("]}");
                if (i != drlv1.Length - 1)
                {
                    sbRole.Append(",");
                }
            }
            var role = "[{\"id\":0,\"text\":\"角色权限\",\"state\":\"open\",\"children\":[" + sbRole.ToString() + "]}]";

            return(role);
        }
예제 #2
0
        /// <summary>
        /// 查询出数据显示在菜单栏目中
        /// </summary>
        /// <returns></returns>
        public ActionResult LoadMenuData()
        {
            /*
             * List<MenuData> mlist = new List<MenuData>();
             *
             * MenuData m = new MenuData();
             * m.GroupID = 101;
             * m.GroupName = "系统管理";
             *
             * IList<MenuItem> itemlist = new List<MenuItem>();
             *
             * MenuItem m1 = new MenuItem();
             * m1.Id = 111;
             * m1.MenuName = "角色管理";
             * m1.Url = "../WebForm1.aspx";
             * itemlist.Add(m1);
             *
             * MenuItem m2 = new MenuItem();
             * m2.Id = 112;
             * m2.MenuName = "角色管理123";
             * m2.Url = "../Inventory/WebForm2.aspx";
             * itemlist.Add(m2);
             *
             * MenuItem m3 = new MenuItem();
             * m3.Id = 113;
             * m3.MenuName = "用户管理";
             * m3.Url = "/UserInfo/Index";
             * itemlist.Add(m3);
             *
             * m.MenuItems = itemlist;
             *
             * mlist.Add(m);
             */

            List <MenuData>       mlist = new List <MenuData>();
            IFunctiongroupService functiongroupService = UnityHelper.UnityResolve <IFunctiongroupService>();
            DataSet functionDS = functiongroupService.GetFunctionGroupByUserID(((UserInfo)Session["UserInfo"]).UserID);

            if (functionDS != null && functionDS.Tables.Count > 0 && functionDS.Tables[0].Rows.Count > 0)
            {
                DataRow[] level1 = functionDS.Tables[0].Select("ParentID='1000'", "FunctionID");
                for (int i = 0; i < level1.Length; i++)
                {
                    MenuData m = new MenuData();
                    m.GroupID   = Int32.Parse(level1[i]["FunctionID"].ToString());
                    m.GroupName = level1[i]["UDF01"].ToString();

                    IList <MenuItem> itemlist = new List <MenuItem>();

                    DataRow[] level2 = functionDS.Tables[0].Select(string.Format("ParentID='{0}'", level1[i]["FunctionID"].ToString()), "FunctionID");
                    for (int j = 0; j < level2.Length; j++)
                    {
                        MenuItem m1 = new MenuItem();
                        m1.Id       = Int32.Parse(level2[j]["FunctionID"].ToString());
                        m1.MenuName = level2[j]["UDF01"].ToString();
                        m1.Url      = level2[j]["Url"].ToString();
                        itemlist.Add(m1);
                    }
                    m.MenuItems = itemlist;
                    mlist.Add(m);
                }
            }

            JsonResult jr = Json(mlist, JsonRequestBehavior.AllowGet);

            return(jr);
        }