/// <summary> /// 获取角色和菜单关联关系 /// </summary> /// <returns>角色和菜单关联关系列表</returns> private List<RoleMenuInfo> GetRoleMenuModel() { List<RoleMenuInfo> roleMenuInfoList = new List<RoleMenuInfo>(); MenuBll menuBll = new MenuBll(); List<MenuInfo> menuList = menuBll.GetMenuListByParentId(0); if (menuList != null) { foreach (MenuInfo menu in menuList) { CheckBoxList cbList = (CheckBoxList)trMenuList.FindControl("menuInfo_" + menu.MenuId); if (cbList != null) { foreach (ListItem li in cbList.Items) { if (li.Selected == true) { RoleMenuInfo roleMenuInfo = new RoleMenuInfo(); roleMenuInfo.MenuId = Convert.ToInt32(li.Value); roleMenuInfo.RoleId = RoleId; roleMenuInfoList.Add(roleMenuInfo); } } } } } return roleMenuInfoList; }
private void InitMenuList() { MenuBll menuBll = new MenuBll(); List<MenuInfo> menuList = menuBll.GetMenuListByParentId(0); RoleMenuBll roleMenuBll = new RoleMenuBll(); List<RoleMenuInfo> roleMenuList = roleMenuBll.GetRoleMenuListByRoleId(RoleId); if (menuList != null) { RoleBll roleBll = new RoleBll(); RoleInfo roleInfo = roleBll.GetRoleById(RoleId); if (roleInfo == null) { return; } foreach (MenuInfo menuInfo in menuList) { Label lbl = new Label(); lbl.Text = menuInfo.MenuName; trMenuList.Controls.Add(lbl); List<MenuInfo> subMenuList = menuBll.GetMenuListByParentId(menuInfo.MenuId); CheckBoxList cbList = new CheckBoxList(); cbList.ID = "menuInfo_" + menuInfo.MenuId; cbList.RepeatDirection = RepeatDirection.Horizontal; cbList.RepeatColumns = 4; cbList.DataSource = subMenuList; cbList.DataTextField = "MenuName"; cbList.DataValueField = "MenuId"; cbList.DataBind(); foreach (ListItem li in cbList.Items) { if (roleMenuList != null) { foreach (RoleMenuInfo roleMenu in roleMenuList) { if (li.Value == roleMenu.MenuId.ToString()) { li.Selected = true; } } } } trMenuList.Controls.Add(cbList); } } }