/// <summary> /// 绑定树 /// </summary> /// <param name="authorityProvider">模块及权限服务对象</param> /// <param name="mpid">父模块ID</param> /// <param name="authority">查询方式:U-用户;R-角色</param> /// <param name="id">查询方式的ID</param> /// <param name="nodes">本级节点集合</param> private void BindTree(iiAuthority authorityProvider, string mpid, string authority, string id, TreeNodeCollection nodes) { //本级模块 DataTable modules = authorityProvider.GetModuleList(mpid, authority, id); if (modules == null || modules.Rows.Count == 0) { return; //递归结束 } else { foreach (DataRow module in modules.Rows) { #region 创建模块项 string grant = module["Grant"].ToString().Trim(); //获得授权的方式:U-用户;R-角色;(null)-无 string mid = module["ID"].ToString().Trim(); TreeNode node = new TreeNode(); string nodeRemark = string.Empty; if (authority == "U") { switch (grant) { case "U": //权限来自用户,允许维护 node.Checked = true; break; case "R": //权限继承自角色,禁止维护 node.Checked = false; node.ShowCheckBox = false; nodeRemark = this.GetGlobalResourceString("Inherited"); //备注 break; default: //无权限,允许维护 node.Checked = false; break; } } else { node.Checked = (grant.Length != 0); } node.Value = mid; node.Text = module["Name"].ToString() + nodeRemark; node.ToolTip = module["Remark"].ToString(); node.SelectAction = TreeNodeSelectAction.None; nodes.Add(node); #endregion //递归下一级 this.BindTree(authorityProvider, mid, authority, id, node.ChildNodes); } } }
/// <summary> /// 绑定树 /// </summary> /// <param name="authorityProvider">模块及权限服务对象</param> /// <param name="mpid">父模块ID</param> /// <param name="authority">查询方式:U-用户;R-角色</param> /// <param name="id">查询方式的ID</param> /// <param name="nodes">本级节点集合</param> private void BindTree(iiAuthority authorityProvider, string mpid, string authority, string id, TreeNodeCollection nodes) { //本级模块 DataTable modules = authorityProvider.GetModuleList(mpid, authority, id); if (modules == null || modules.Rows.Count == 0) { return; //递归结束 } else { foreach (DataRow module in modules.Rows) { string grant = module["Grant"].ToString().Trim(); //获得授权的方式:U-用户;R-角色;(null)-无 if (grant.Length != 0) //不是空白表示有权限 { #region 创建模块项 string mid = module["ID"].ToString().Trim(); string url = module["URL"].ToString(); TreeNode node = new TreeNode(); node.Value = mid; node.Text = module["Name"].ToString(); node.ToolTip = module["Remark"].ToString(); node.SelectAction = TreeNodeSelectAction.SelectExpand; if (url.Length > 0) { node.NavigateUrl = string.Format("{0}/{1}", iiGlobal.VirtualPath, url ); } else { node.NavigateUrl = "javascript:void(null);"; } nodes.Add(node); #endregion //递归下一级 this.BindTree(authorityProvider, mid, authority, id, node.ChildNodes); } } } }