void bingRepearter(string rootID, Repeater rMenu) { TreeNodeInfo<MenuInfo> cList = new BLL.Menu().GetTree(rootID); if (null == cList) { return; } rMenu.DataSource = cList.ChildNodeList; rMenu.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { TreeNodeInfo<MenuInfo> cList = new BLL.Menu().GetTree(ROOT_ID) ; if (null == cList) { return; } rMenu.DataSource = cList.ChildNodeList; rMenu.DataBind(); } } catch (Exception ex) { Log(ex); } }
/// <summary> /// 添加栏目 /// </summary> /// <param name="parentMenuID">父节点ID</param> /// <param name="cInfo">添加的栏目,“栏目代码信息”(MenuCode)属性为系统自动生成。如系统已存在父节点(0103),并且具有2个同级节点,同级节点的最大编号为(010302),则该节点编号为010303</param> /// <returns>新增实体的主键</returns> public string AddChild(string parentMenuID, MenuInfo cInfo) { if (string.IsNullOrEmpty(parentMenuID)) { throw new ArgumentNullException("父节点ID不能为空。"); } // 生成新增栏目的栏目代码 string maxChildCode = new Menu().getMaxChildCode(parentMenuID); MenuInfo pInfo = new Menu().GetByID(parentMenuID); // 末2位+1,为空则为00; if (string.IsNullOrEmpty(maxChildCode)) { cInfo.MenuCode = pInfo.MenuCode + "00"; } else { // 默认编码为00~99 int width = 2; string max = maxChildCode.Substring(maxChildCode.Length - width); int maxNum = int.Parse(max); cInfo.MenuCode = pInfo.MenuCode + String.Format("{0:D2}", maxNum++); ; } cInfo.ParentID = parentMenuID; string menuID = dal.Add(cInfo); //获取副栏目权限组,子节点默认绑定 PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(parentMenuID); if (null != pgInfo && string.IsNullOrEmpty(pgInfo.ID) == true) { AddPermissionGroup(menuID, pgInfo.ID); } return menuID; }
/// <summary> /// /// </summary> private void BindTree() { tMenus.Nodes.Clear(); TreeNodeInfo<MenuInfo> tree = new BLL.Menu().GetTree(MenuInfo.DEFAULT_PARENT_ID); foreach (TreeNodeInfo<MenuInfo> node in tree.SubNodeList) { string name = node.STInstance.Name; string id = node.STInstance.ID; //string url = node.STInstance.URL; //string sortNum = node.STInstance.SortNum.ToString(); TreeNode treeNode = new TreeNode(name, id); tMenus.Nodes.Add(treeNode); if (node.Count != 0) { BindTree(node, treeNode); } } }
protected void gvRoleList_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string permissionGroupID = rblPower.SelectedValue; IList<PermissionInfo> pList = new Permission().GetList(permissionGroupID); CheckBoxList cblPermission = (CheckBoxList)e.Row.FindControl("cblPermission"); cblPermission.DataSource = pList; cblPermission.DataBind(); // 权限组赋值 RoleInfo rInfo = e.Row.DataItem as RoleInfo; string menuPermissionCode = new BLL.Menu().GetPermissionGroupCodeOfMenuByRole(this.NodeID, rInfo.ID); char[] codeArrary = menuPermissionCode.ToCharArray(); for (int i = 0; i < cblPermission.Items.Count; i++) { ListItem item = cblPermission.Items[i]; item.Selected = ("0" == codeArrary[i].ToString()) ? false : true; } } }
/// <summary> /// 选择编辑栏目 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void tMenus_SelectedNodeChanged(object sender, EventArgs e) { try { //选中节点值 string value = tMenus.SelectedNode.Value; this.NodeID = value; MenuInfo mInfo = new BLL.Menu().GetByID(this.NodeID); this.ParentID = mInfo.ParentID; tbName.Text = mInfo.Name; tbRemark.Text = mInfo.Remark; tbSortNum.Text = mInfo.MenuCode; tbURL.Text = mInfo.URL; //rblIsShow.SelectedIndex = (mInfo.IsShow == true) ? 0 : 1; if (string.IsNullOrEmpty(mInfo.Target) == false) { rblExtend.SelectedValue = mInfo.Target; } btnSubmit.Visible = true; btnAdd.Visible = true; btnDel.Visible = true; btnSub.Visible = true; // 加载权限组 rblPower.DataSource = new PermissionGroup().GetList(); rblPower.DataBind(); PermissionGroupInfo pgInfo = new PermissionGroup().GetByMenuID(mInfo.ID); if (pgInfo != null && string.IsNullOrEmpty(pgInfo.ID) == false) { rblPower.SelectedValue = pgInfo.ID; btnRoleBind.Visible = true; } // 加载角色 IList<RoleInfo> rList = new Role().GetList(); cblRole.DataSource = rList; cblRole.DataBind(); IList<RoleInfo> mRoleList = new Role().GetListByMenuID(mInfo.ID); foreach (RoleInfo rInfo in mRoleList) { cblRole.Items.FindByValue(rInfo.ID).Selected = true; } // 为选中的角色绑定权限 gvRoleList.DataSource = mRoleList; gvRoleList.DataBind(); } catch (Exception exc) { ShowMsg(exc.Message); Log(exc); } }
/// <summary> ///将消息记入日志 /// </summary> /// <param name="message">消息</param> protected void Log(string message, EventLogEntryType logType) { try { string userName = this.UserCacheInfo.Name; string menuName = string.Empty; if (string.IsNullOrEmpty(this.MenuID)) { MenuInfo mInfo = new BLL.Menu().GetByID(this.MenuID); if (null == mInfo) { menuName = this.MenuID; } else { menuName = mInfo.Name; } } string fullMsg = string.Format("用户({0})于{1}访问资源(Menu:{2}时发生如下错误:{3}。请联系系统管理员解决。)", userName, DateTime.Now.ToLongDateString(), menuName, message); LogEntry.Log.Write(message, logType, this.MenuID); } catch (Exception ex) { // 日志模块失败,为便于调试直接输出错误信息 // TODO:使用其他持久化介质 Response.Write(ex.ToString()); } }