#region
|
|
using System;
|
using System.Data;
|
using System.Windows.Forms;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.DataAccess;
|
using CSFrameworkV5.Interfaces;
|
using CSFrameworkV5.Models;
|
using CSFrameworkV5.WebRef.SystemModule;
|
|
#endregion
|
|
namespace CSFrameworkV5.Business.BLL_Permission
|
{
|
/// <summary>
|
/// 角色的权限视图管理
|
/// </summary>
|
public class RoleActionsView
|
{
|
protected DataTable _Actions;
|
protected string _CurrentRoleID; //当前角色编号
|
private bool _IsCreatedTree; //是否创建树结构
|
protected DataTable _MenuData;
|
protected DataTable _ModuleData;
|
protected DataTable _MyFormTagName;
|
protected bool _OnInitTree;
|
protected bool _OnViewMode;
|
|
protected IBridge_Permission _PermissionBridge;
|
protected DataTable _RoleActionData;
|
protected DataTable _RoleData;
|
|
protected TreeView _Tree;
|
|
/// <summary>
|
/// 构造器
|
/// </summary>
|
/// <param name="tree">树视图</param>
|
/// <param name="menuData">菜单数据</param>
|
public RoleActionsView(TreeView tree)
|
{
|
_OnViewMode = false;
|
_Tree = tree;
|
_PermissionBridge = CreateBridge();
|
}
|
|
/// <summary>
|
/// 功能点的自定义名称数据
|
/// </summary>
|
public DataTable ActionCustomNameData
|
{
|
get => _MyFormTagName;
|
set => _MyFormTagName = value;
|
}
|
|
/// <summary>
|
/// 所有功能点数据
|
/// </summary>
|
public DataTable ActionsData
|
{
|
get => _Actions;
|
set => _Actions = value;
|
}
|
|
/// <summary>
|
/// 当前操作的角色编号
|
/// </summary>
|
public string CurrentRoleID
|
{
|
get => _CurrentRoleID;
|
set => _CurrentRoleID = value;
|
}
|
|
/// <summary>
|
/// 是否创建树结构
|
/// </summary>
|
public bool IsCreatedTree
|
{
|
get => _IsCreatedTree;
|
set => _IsCreatedTree = value;
|
}
|
|
/// <summary>
|
/// 所有菜单数据
|
/// </summary>
|
public DataTable MenuData
|
{
|
get => _MenuData;
|
set => _MenuData = value;
|
}
|
|
/// <summary>
|
/// 模块数据
|
/// </summary>
|
public DataTable ModuleData
|
{
|
get => _ModuleData;
|
set => _ModuleData = value;
|
}
|
|
/// <summary>
|
/// 处于初始化树状态
|
/// </summary>
|
public bool OnInitTree => _OnInitTree;
|
|
/// <summary>
|
/// 处于查看模式
|
/// </summary>
|
public bool OnViewMode
|
{
|
get => _OnViewMode;
|
set => _OnViewMode = value;
|
}
|
|
/// <summary>
|
/// 角色的权限数据
|
/// </summary>
|
public DataTable RoleActionData => _RoleActionData;
|
|
/// <summary>
|
/// 角色数据
|
/// </summary>
|
public DataTable RoleData
|
{
|
get => _RoleData;
|
set => _RoleData = value;
|
}
|
|
/// <summary>
|
/// 取消操作
|
/// </summary>
|
public void CancelOperation()
|
{
|
_MenuData.RejectChanges();
|
_ModuleData.RejectChanges();
|
_Actions.RejectChanges();
|
}
|
|
private IBridge_Permission CreateBridge()
|
{
|
if (BridgeFactory.IsADODirect)
|
return new dalPermission(Loginer.CurrentUser);
|
|
if (BridgeFactory.IsWCFBridge) return new WCF_Permission();
|
|
throw new CustomException(BridgeFactory.UNKNOW_BRIDGE_TYPE);
|
}
|
|
/// <summary>
|
/// 由菜单的数据创建树结点
|
/// </summary>
|
/// <param name="row">菜单的数据</param>
|
/// <param name="tree">树视图</param>
|
/// <param name="parentNode">父级结点</param>
|
/// <returns></returns>
|
protected TreeNode DataRow2NodeHandler(DataRow row, TreeView tree,
|
TreeNode parentNode)
|
{
|
var node = new TreeNode();
|
node.Text = ConvertEx.ToString(row[tb_MyMenu.MenuCaption]); //显示菜单标题
|
if (parentNode != null)
|
parentNode.Nodes.Add(node);
|
else
|
tree.Nodes.Add(node);
|
|
return node;
|
}
|
|
/// <summary>
|
/// 根据父级菜单名获取所有子级的资料行.
|
/// </summary>
|
/// <param name="parentValue">父级菜单名</param>
|
/// <returns></returns>
|
protected DataRow[] GetRows(string parentMenuName)
|
{
|
string filter;
|
|
if (string.IsNullOrEmpty(parentMenuName))
|
filter = string.Format("({0} IS NULL) OR ({1} ='')",
|
tb_MyMenu.ParentMenuName,
|
tb_MyMenu.ParentMenuName);
|
else
|
filter = string.Format("{0}='{1}'", tb_MyMenu.ParentMenuName,
|
parentMenuName);
|
|
return _MenuData.Select(filter);
|
}
|
|
//_RoleData, txtRoleID.Text, "RoleID", _UpdateType)
|
public static bool IsExistsInCache(DataTable cache, string keyValue,
|
string keyName, UpdateType updateType)
|
{
|
if (UpdateType.Add == updateType)
|
{
|
var rows = cache.Select(keyName + "='" + keyValue + "'");
|
return rows.Length > 0;
|
}
|
|
//修改状态是禁止修改主键的
|
if (UpdateType.Modify == updateType) return false;
|
|
return false;
|
}
|
|
/// <summary>
|
/// 提交菜单管理功能的数据
|
/// </summary>
|
/// <returns></returns>
|
public bool PostChanges()
|
{
|
var success = false;
|
|
var dtMenu = MenuData.GetChanges();
|
var dtActionCustomName = ActionCustomNameData.GetChanges();
|
if (dtMenu != null)
|
success =
|
new bllMenu().Update(dtMenu,
|
dtActionCustomName); //提交菜单和自定义功能点数据
|
|
if (success)
|
{
|
MenuData.AcceptChanges();
|
ActionCustomNameData.AcceptChanges();
|
}
|
|
//提交模块字典数据
|
var dtModule = ModuleData.GetChanges();
|
if (dtModule != null)
|
success = new bllSystemModule().Update(dtModule);
|
|
if (success) ModuleData.AcceptChanges();
|
|
//提交功能点数据
|
var dtActions = ActionsData.GetChanges();
|
if (dtActions != null) success = new bllActions().Update(dtActions);
|
|
if (success) ActionsData.AcceptChanges();
|
|
return success;
|
}
|
|
/// <summary>
|
/// 重新获取角色依赖的数据
|
/// </summary>
|
public void RefreshRoleRelatedData()
|
{
|
_MyFormTagName = _PermissionBridge.GetFormTagName();
|
}
|
|
#region BeforeCheck/AfterCheck
|
|
private void OnTreeAuthorityBeforeCheck(object sender,
|
TreeViewCancelEventArgs e)
|
{
|
//查看模式支持勾选.
|
if (_OnViewMode) e.Cancel = true;
|
}
|
|
private void OnTreeAuthorityAfterCheck(object sender,
|
TreeViewEventArgs e)
|
{
|
//枚举结点
|
if (e.Action == TreeViewAction.ByKeyboard ||
|
e.Action == TreeViewAction.ByMouse)
|
{
|
if (e.Node.Checked)
|
{
|
TreeNodeSelectedChild(e.Node, true);
|
TreeNodeParentSelected(e.Node, true);
|
}
|
else if (e.Node.Checked == false)
|
{
|
TreeNodeSelectedChild(e.Node, false);
|
//当所有子结点去掉勾选时,父结点也去掉勾选时
|
//TreeNodeChildsUnSelected(e.Node);
|
}
|
}
|
|
//勾选功能结点
|
if (e.Node.Tag is ActionNodeTag)
|
{
|
var action = e.Node.Tag as ActionNodeTag; //功能结点的Tag对象
|
var tag = e.Node.Parent.Tag as RoleActionNodeTag; //数据窗体结点Tag对象
|
|
//初始化角色的权限资料行
|
if (tag.RoleActionData == null)
|
tag.RoleActionData =
|
CreateRoleActionData(_CurrentRoleID, tag.MenuName, 0);
|
|
//汇总数据窗体结点的所有打勾的功能点的值
|
var actionsValue = GetActionsValue(e.Node.Parent);
|
|
//设置权限值
|
tag.RoleActionData[tb_MyRoleActions.Actions] = actionsValue;
|
}
|
|
//勾选数据窗体结点
|
if (e.Node.Tag is RoleActionNodeTag)
|
{
|
var tag = e.Node.Tag as RoleActionNodeTag;
|
if (e.Node.Checked) //打勾
|
{
|
if (tag.RoleActionData == null) //新增角色的权限
|
tag.RoleActionData =
|
CreateRoleActionData(_CurrentRoleID, tag.MenuName,
|
0);
|
|
if (tag.Deleted) tag.Deleted = false;
|
}
|
else //取消勾选
|
{
|
if (tag.RoleActionData != null)
|
{
|
if (tag.RoleActionData.RowState == DataRowState.Added)
|
tag.RoleActionData.Table.Rows.Remove(
|
tag.RoleActionData); //删除"新增状态"的记录
|
else
|
tag.Deleted = true; //给记录打上删除标记
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取角色及角色的权限已修改的数据
|
/// </summary>
|
/// <returns></returns>
|
public DataTable GetChanges()
|
{
|
foreach (TreeNode node in _Tree.Nodes) BuildNodeData(node);
|
|
var changes = _RoleActionData.GetChanges();
|
return changes;
|
}
|
|
/// <summary>
|
/// 将结点(取消勾选)绑定的DataRow设为删除
|
/// </summary>
|
/// <param name="node"></param>
|
private void BuildNodeData(TreeNode node)
|
{
|
if (node == null || node.Tag == null) return;
|
|
//用于测试
|
if (node.Text == "动态交叉报表")
|
{
|
}
|
|
//功能点节点(如:增、删、改)
|
if (node.Tag is ActionNodeTag)
|
{
|
var tag = node.Parent.Tag as RoleActionNodeTag; //数据窗体结点Tag对象
|
|
//勾选了功能点,初始化角色的权限资料行
|
if (tag.RoleActionData == null && node.Parent.Checked)
|
tag.RoleActionData =
|
CreateRoleActionData(_CurrentRoleID, tag.MenuName, 0);
|
|
if (tag.RoleActionData != null)
|
{
|
//汇总数据窗体结点的所有打勾的功能点的值
|
var actionsValue = GetActionsValue(node.Parent);
|
|
if (actionsValue > 0 &&
|
tag.RoleActionData.RowState !=
|
DataRowState.Deleted) //更新权限值
|
tag.RoleActionData[tb_MyRoleActions.Actions] =
|
actionsValue;
|
//else
|
// tag.RoleActionData.Delete();//删除
|
}
|
}
|
|
//窗体结点
|
if (node.Tag is RoleActionNodeTag)
|
{
|
var tag = node.Tag as RoleActionNodeTag;
|
if (node.Checked) //打勾
|
{
|
if (tag.RoleActionData == null) //新增角色的权限
|
tag.RoleActionData =
|
CreateRoleActionData(_CurrentRoleID, tag.MenuName,
|
0);
|
}
|
else //取消勾选
|
{
|
if (tag.RoleActionData != null) //删除
|
{
|
if (tag.RoleActionData.RowState == DataRowState.Added)
|
tag.RoleActionData.Table.Rows.Remove(
|
tag.RoleActionData); //删除"新增状态"的记录
|
else
|
tag.RoleActionData.Delete(); //删除记录
|
}
|
}
|
}
|
|
//若当前节点有子节点,递归处理
|
if (node.Nodes.Count > 0)
|
foreach (TreeNode n in node.Nodes)
|
BuildNodeData(n);
|
}
|
|
/// <summary>
|
/// 汇总数据窗体结点的所有打勾的功能点的值
|
/// </summary>
|
/// <param name="node">数据窗体结点</param>
|
/// <returns></returns>
|
private int GetActionsValue(TreeNode node)
|
{
|
var actions = 0;
|
foreach (TreeNode n in node.Nodes)
|
if (n.Checked && n.Tag != null && n.Tag is ActionNodeTag)
|
actions += (n.Tag as ActionNodeTag).ActionValue;
|
|
return actions;
|
}
|
|
/// <summary>
|
/// 新增角色的权限
|
/// </summary>
|
/// <param name="roleID">角色编号</param>
|
/// <param name="menuName">菜单名称</param>
|
/// <param name="actions">权限值(功能点汇总)</param>
|
/// <returns></returns>
|
private DataRow CreateRoleActionData(string roleID, string menuName,
|
int actions)
|
{
|
var row = _RoleActionData.NewRow();
|
row[tb_MyRoleActions.DataSetID] = Loginer.CurrentUser.DBID;
|
row[tb_MyRoleActions.RoleID] = roleID;
|
row[tb_MyRoleActions.MenuName] = menuName;
|
row[tb_MyRoleActions.Actions] = actions;
|
_RoleActionData.Rows.Add(row);
|
return row;
|
}
|
|
#endregion
|
|
#region 递归选择结点父/子结点
|
|
/// <summary>
|
/// 勾选所有子级结点
|
/// </summary>
|
/// <param name="thChild">当前结点</param>
|
/// <param name="isChecked">是否勾选</param>
|
public void TreeNodeSelectedChild(TreeNode thChild, bool isChecked)
|
{
|
foreach (TreeNode tnChildNext in thChild.Nodes)
|
{
|
tnChildNext.Checked = isChecked;
|
TreeNodeSelectedChild(tnChildNext, isChecked);
|
}
|
}
|
|
/// <summary>
|
/// 勾选父级结点
|
/// </summary>
|
/// <param name="tnChild">当前结点</param>
|
/// <param name="isChecked">是否勾选</param>
|
private void TreeNodeParentSelected(TreeNode tnChild, bool isChecked)
|
{
|
if (tnChild.Parent != null)
|
{
|
tnChild.Parent.Checked = isChecked;
|
TreeNodeParentSelected(tnChild.Parent, isChecked);
|
}
|
}
|
|
/// <summary>
|
/// 当所有子结点去掉勾选时,父结点也去掉勾选时
|
/// </summary>
|
/// <param name="tnChild"></param>
|
private void TreeNodeChildsUnSelected(TreeNode tnChild)
|
{
|
if (tnChild.Parent == null) return;
|
|
foreach (TreeNode n in tnChild.Parent.Nodes)
|
if (n.Checked)
|
return;
|
|
tnChild.Parent.Checked = false;
|
}
|
|
#endregion
|
|
#region 递归生成菜单树
|
|
/// <summary>
|
/// 生成顶级菜单的树结点
|
/// </summary>
|
public virtual void InitTree(string rootValue)
|
{
|
try
|
{
|
_OnInitTree = true; //正在初始化树视图
|
_OnViewMode = false; //允许勾选结点
|
|
_Tree.BeginUpdate();
|
_Tree.AfterCheck -= OnTreeAuthorityAfterCheck;
|
_Tree.BeforeCheck -= OnTreeAuthorityBeforeCheck;
|
|
_Tree.Nodes.Clear();
|
|
//根结点记录
|
var rows = GetRows(rootValue);
|
DataRow[] childs;
|
|
string pValue; //parentValue;
|
string kValue; //key value
|
TreeNode root;
|
|
foreach (var row in rows)
|
{
|
pValue = row[tb_MyMenu.ParentMenuName].ToStringEx();
|
kValue = row[tb_MyMenu.MenuName].ToStringEx();
|
|
root = DataRow2NodeHandler(row, _Tree, null); //创建结点
|
root.ImageIndex = 0;
|
root.SelectedImageIndex = 0;
|
|
var tag = new RoleActionNodeTag(); //创建Tag对象
|
tag.MenuData = row;
|
tag.MenuName = kValue;
|
tag.RoleActionData = null;
|
root.Tag = tag;
|
|
childs = GetRows(kValue);
|
if (childs.Length > 0) InitTreeChild(childs, root);
|
}
|
|
_IsCreatedTree = true;
|
_OnInitTree = false;
|
}
|
finally
|
{
|
_Tree.BeforeCheck += OnTreeAuthorityBeforeCheck;
|
_Tree.AfterCheck += OnTreeAuthorityAfterCheck;
|
|
_Tree.EndUpdate();
|
}
|
}
|
|
/// <summary>
|
/// 生成子菜单的树结构
|
/// </summary>
|
protected virtual void InitTreeChild(DataRow[] childs,
|
TreeNode parentNode)
|
{
|
string menuParentName; //当前菜单的父级菜单;
|
string menuName; //当前菜单
|
TreeNode root;
|
|
foreach (var row in childs)
|
{
|
menuParentName = row[tb_MyMenu.ParentMenuName].ToStringEx();
|
menuName = row[tb_MyMenu.MenuName].ToStringEx();
|
|
root = DataRow2NodeHandler(row, _Tree, parentNode); //创建结点
|
|
var tag = new RoleActionNodeTag(); //创建Tag对象
|
tag.MenuData = row;
|
tag.MenuName = menuName;
|
tag.RoleActionData = null;
|
root.Tag = tag;
|
|
var actions = ConvertEx.ToInt(row[tb_MyMenu.Actions]);
|
if (actions > 0) //窗体有权限功能
|
{
|
root.ImageIndex = 1;
|
root.SelectedImageIndex = 1;
|
|
InitAction(actions, menuName, root); //初始化功能结点
|
}
|
else
|
{
|
root.ImageIndex = 3;
|
root.SelectedImageIndex = 3;
|
}
|
|
childs = GetRows(menuName);
|
|
if (childs.Length > 0) //创建下一级结点
|
InitTreeChild(childs, root);
|
}
|
}
|
|
#endregion
|
|
#region InitAction 初始化功能点
|
|
/// <summary>
|
/// 初始化功能点树结点
|
/// </summary>
|
/// <param name="node"></param>
|
/// <param name="menuItem"></param>
|
protected virtual void InitAction(int actions, string menuName,
|
TreeNode node)
|
{
|
var isAdmin = Loginer.CurrentUser.IsAdmin();
|
|
var userAuths = actions; //当前用户的权限
|
|
foreach (DataRow row in _Actions.Rows) //循环所有功能点.
|
{
|
var value = ConvertEx.ToInt(row[tb_MyActions.ActionValue]);
|
if (value == 0) continue;
|
|
//用每个功能点的值与窗体的最大权限"与"运算, 但不能超出当前用户的权限.
|
if ((value & actions) == value &&
|
(isAdmin || (value & userAuths) == value))
|
{
|
var caption =
|
ConvertEx.ToString(row[tb_MyActions.ActionName]);
|
var tagNameRow =
|
GetCustomTagName(menuName, value); //取按钮的自定义名称
|
if (tagNameRow != null)
|
caption =
|
ConvertEx.ToString(
|
tagNameRow[
|
tb_MyFormTagName
|
.TagName]); //功能点名称
|
|
var actionNode = new TreeNode(caption, 0, 0);
|
actionNode.ImageIndex = 2;
|
actionNode.SelectedImageIndex = 2;
|
|
var tag = new ActionNodeTag(value);
|
tag.TagMenuName = menuName;
|
tag.TagNameDataRow = tagNameRow;
|
tag.TagNameOld = caption; //按钮标题
|
actionNode.Tag = tag;
|
|
node.Nodes.Add(actionNode);
|
}
|
}
|
}
|
|
protected DataRow GetCustomTagName(string menuName, int actionValue)
|
{
|
var rows = _MyFormTagName.Select("MenuName='" + menuName +
|
"' AND TagValue=" +
|
actionValue.ToStringEx());
|
if (rows.Length > 0) return rows[0];
|
|
return null;
|
}
|
|
#endregion
|
|
#region 显示角色的权限
|
|
//显示角色的权限.
|
public void ShowRoleActions()
|
{
|
_OnInitTree = true;
|
_RoleActionData = _PermissionBridge.GetRoleAction(_CurrentRoleID);
|
|
try
|
{
|
_Tree.AfterCheck -= OnTreeAuthorityAfterCheck;
|
|
//一级结点,模块的主菜单
|
foreach (TreeNode node in _Tree.Nodes)
|
{
|
var tag = node.Tag as RoleActionNodeTag;
|
var drRoleAction =
|
GetRoleActionDataRow(_CurrentRoleID, tag.MenuName);
|
tag.RoleActionData = drRoleAction; //设置角色的权限
|
tag.Deleted = false;
|
node.Checked = drRoleAction != null;
|
|
if (node.Nodes.Count > 0) ShowRoleActionsChild(node);
|
}
|
}
|
catch (Exception ex)
|
{
|
Msg.ShowException(ex);
|
}
|
finally
|
{
|
_Tree.AfterCheck += OnTreeAuthorityAfterCheck;
|
_OnInitTree = false;
|
}
|
}
|
|
private DataRow GetRoleActionDataRow(string roleID, string menuName)
|
{
|
var rs = _RoleActionData.Select("RoleID='" + roleID +
|
"' AND MenuName='" + menuName +
|
"'");
|
return rs.Length > 0 ? rs[0] : null;
|
}
|
|
private void ShowRoleActionsChild(TreeNode node)
|
{
|
foreach (TreeNode n in node.Nodes)
|
{
|
var tag = n.Tag as RoleActionNodeTag;
|
var drRoleAction =
|
GetRoleActionDataRow(_CurrentRoleID, tag.MenuName);
|
tag.RoleActionData = drRoleAction; //设置角色的权限
|
tag.Deleted = false;
|
n.Checked = drRoleAction != null;
|
|
if (n.Checked) TreeNodeParentSelected(n, true);
|
|
var actions =
|
ConvertEx.ToInt(tag.MenuData[tb_MyRoleActions.Actions]);
|
if (actions > 0) //当前菜单有功能点(权限值)
|
ShowAction(n, drRoleAction); //显示菜单的功能
|
else if (n.Nodes.Count > 0) ShowRoleActionsChild(n);
|
}
|
}
|
|
private void ShowAction(TreeNode node, DataRow roleAction)
|
{
|
if (node == null) return;
|
|
var auth = 0;
|
if (roleAction != null)
|
auth = int.Parse(roleAction[tb_MyRoleActions.Actions]
|
.ToStringEx()); //角色的权限
|
|
foreach (TreeNode n in node.Nodes)
|
if (auth != 0)
|
{
|
var value = (n.Tag as ActionNodeTag).ActionValue;
|
n.Checked = (value & auth) == value; //逻辑位运算
|
}
|
else
|
{
|
n.Checked = false;
|
}
|
}
|
|
#endregion
|
}
|
|
/// <summary>
|
/// 组的权限视图管理(查看模式)
|
/// </summary>
|
public class GroupActionsView : RoleActionsView
|
{
|
private DataTable _GroupActions;
|
|
public GroupActionsView(TreeView tree)
|
: base(tree)
|
{
|
_OnViewMode = true;
|
}
|
|
private DataRow GetGroupExistedMenu(string menuName)
|
{
|
var rows =
|
_GroupActions.Select(tb_MyMenu.MenuName + "='" + menuName +
|
"'");
|
return rows.Length > 0 ? rows[0] : null;
|
}
|
|
protected override void InitAction(int actions, string menuName,
|
TreeNode node)
|
{
|
var isAdmin = Loginer.CurrentUser.IsAdmin();
|
|
foreach (DataRow row in _Actions.Rows) //循环所有功能点.
|
{
|
var value = ConvertEx.ToInt(row[tb_MyActions.ActionValue]);
|
if (value == 0) continue;
|
|
//用每个功能点的值与窗体的最大权限"与"运算, 但不能超出当前用户的权限.
|
if ((value & actions) == value)
|
{
|
var caption =
|
ConvertEx.ToString(row[tb_MyActions.ActionName]);
|
var tagNameRow =
|
GetCustomTagName(menuName, value); //取按钮的自定义名称
|
if (tagNameRow != null)
|
caption =
|
ConvertEx.ToString(
|
tagNameRow[
|
tb_MyFormTagName
|
.TagName]); //功能点名称
|
|
var actionNode = new TreeNode(caption, 0, 0);
|
actionNode.ImageIndex = 2;
|
actionNode.SelectedImageIndex = 2;
|
|
var tag = new ActionNodeTag(value);
|
tag.TagMenuName = menuName;
|
tag.TagNameDataRow = tagNameRow;
|
tag.TagNameOld = caption; //按钮标题
|
actionNode.Tag = tag;
|
|
node.Nodes.Add(actionNode);
|
}
|
}
|
}
|
|
public void InitTree(string rootValue, string groupCode)
|
{
|
//取当前组所有权限
|
_GroupActions = new bllPermission().GetGroupActions(groupCode);
|
|
InitTree(rootValue);
|
}
|
|
public override void InitTree(string rootValue)
|
{
|
if (_GroupActions == null) throw new Exception("无法获取组的权限!");
|
|
_OnInitTree = true;
|
|
_Tree.Nodes.Clear();
|
_Tree.BeginUpdate();
|
|
//根结点记录
|
var rows = GetRows(rootValue); //取菜单数据
|
DataRow[] childs;
|
|
string menuName; //key value
|
TreeNode root;
|
|
var isAdmin = Loginer.CurrentUser.IsAdmin();
|
|
foreach (var row in rows)
|
{
|
menuName = row[tb_MyMenu.MenuName].ToStringEx();
|
|
//仅加载当前组的角色的权限
|
if (GetGroupExistedMenu(menuName) != null)
|
{
|
root = DataRow2NodeHandler(row, _Tree, null);
|
root.ImageIndex = 0;
|
root.SelectedImageIndex = 0;
|
|
var tag = new RoleActionNodeTag();
|
tag.MenuData = row;
|
tag.MenuName = menuName;
|
tag.RoleActionData = null;
|
root.Tag = tag;
|
|
childs = GetRows(menuName);
|
if (childs.Length > 0) InitTreeChild(childs, root);
|
}
|
}
|
|
if (_Tree.Nodes.Count == 0) _Tree.Nodes.Add("该组未定义权限!");
|
|
_Tree.EndUpdate();
|
_OnInitTree = false;
|
}
|
|
protected override void InitTreeChild(DataRow[] childs,
|
TreeNode parentNode)
|
{
|
string menuParentName; //parentValue;
|
string menuName; //key value
|
TreeNode root;
|
var isAdmin = Loginer.CurrentUser.IsAdmin();
|
foreach (var row in childs)
|
{
|
menuParentName = row[tb_MyMenu.ParentMenuName].ToStringEx();
|
menuName = row[tb_MyMenu.MenuName].ToStringEx();
|
|
var thisMenu = GetGroupExistedMenu(menuName);
|
|
if (thisMenu != null)
|
{
|
root = DataRow2NodeHandler(row, _Tree, parentNode);
|
|
var tag = new RoleActionNodeTag();
|
tag.MenuData = row;
|
tag.MenuName = menuName;
|
tag.RoleActionData = null;
|
root.Tag = tag;
|
|
var actions = thisMenu == null
|
? 0
|
: ConvertEx.ToInt(thisMenu[tb_MyMenu.Actions]); //取角色的权限
|
if (actions > 0)
|
{
|
root.ImageIndex = 1;
|
root.SelectedImageIndex = 1;
|
|
InitAction(actions, menuName, root);
|
}
|
else
|
{
|
root.ImageIndex = 3;
|
root.SelectedImageIndex = 3;
|
}
|
|
childs = GetRows(menuName);
|
|
if (childs.Length > 0) InitTreeChild(childs, root);
|
}
|
}
|
}
|
}
|
}
|