//初始化树
private void InitTreeView()
{
RoleInfo tmpRoleInfo = raBL.GetRoleInfo(RoleID);
if (tmpRoleInfo != null)
this.lbRoleName.Text = tmpRoleInfo.RoleName;
//获取查找该角色对应的权限列表
List<RoleAuthorityRefer> roleAuthorityList = raBL.GetRoleAuthorityReferList(RoleID);
List<AuthorityInfo> authorityInfoList = raBL.GetAuthorityInfoList();
//获取根,即父节点为0的类型权限列表
if(authorityInfoList.Count>0)
{
List<AuthorityInfo> aInfoParentList = authorityInfoList.Where(c => c.ParentID == null).ToList();
foreach (AuthorityInfo tmp in aInfoParentList)
{
TreeNode node = new TreeNode();
node.Text = tmp.AuthorityName;
node.Value = tmp.AuthorityID;
node.Expanded = false;
if (roleAuthorityList.Count > 0)
{
if (roleAuthorityList.Where(c => c.AuthorityID == tmp.AuthorityID).ToList().Count > 0)
{
node.Checked = true;
}
}
this.roleTree.Nodes.Add(node);
GetChildNode(roleAuthorityList,authorityInfoList, node);
}
}
}
//递归方法获取子类型
private void GetChildNode(List<RoleAuthorityRefer> roleAuthorityList, List<AuthorityInfo> authorityInfoList, TreeNode node)
{
List<AuthorityInfo> aInfoChildList = authorityInfoList.Where(c => c.ParentID == node.Value).ToList();
foreach (AuthorityInfo tmp in aInfoChildList)
{
TreeNode childNode = new TreeNode();
childNode.Text = tmp.AuthorityName;
childNode.Value = tmp.AuthorityID;
childNode.Expanded = false;
if (roleAuthorityList.Count > 0)
{
if (roleAuthorityList.Where(c => c.AuthorityID == tmp.AuthorityID).ToList().Count > 0)
{
childNode.Checked = true;
}
}
node.ChildNodes.Add(childNode);
GetChildNode(roleAuthorityList,authorityInfoList, childNode);
}
}