C# 权限管理

本文介绍了一个操作员权限管理系统的设计方案,包括操作员信息表、权限组信息表及权限关系表的创建,并定义了相应的实体类,如操作员实体类、权限组实体类等。
-- 创建 操作员信息表(Operator)
Id
OperatorName    -- 操作员姓名
Password
RightsList      -- 操作员权限列表
State -- 用户当前状态


-- 创建 权限组信息表(RightsGroup)
Id
GroupName -- 权限组名称
GroupRightsList -- 组权限列表


-- 创建 权限关系表(RightsRelation)
Id
OperatorId -- 操作员 Id
RightsGroupId -- 权限组 Id




1、实体模型基类(ModelBase)
int _id;
string _modelName;


public ModelBase() { }
  public ModelBase(int id, string modelName)
{
this.Id = id;
this.ModelName = modelName;



2、操作员实体类(Operator)
string _password;
Dictionary<string, Rights> _rightsCollection;  权限集合(键值用于存储菜单/工具栏项的 Name 属性)
bool _state;


public Operator() { }
public Operator(
int operatorId,
string name,
string password,
Dictionary<string, Rights> rightsCollection,
bool state): base(operatorId, name)

{
this.Password = password;
this.RightsCollection = rightsCollection;
this.State = state;



3、权限组实体类(RightsGroup)
Dictionary<string, Rights> _groupRightsCollection;


public RightsGroup() { }
public RightsGroup(
int groupId,
string groupName,
Dictionary<string, Rights> groupRightsCollection): base(groupId, groupName)

{
this.GroupRightsCollection = groupRightsCollection;
}


4、权限关系实体类(RightsRelation)
int _id;
int _operatorId;
string _operatorName;
int _rightsGroupId;
string rightsGroupName;


public RightsRelation() { }
public RightsRelation(
int id, 
int operatorId, 
string operatorName,
int rightsGroupId,
string rightsGroupName)
{
this.Id = id;
this.OperatorId = operatorId;
this.OperatorName = operatorName;
this.RightsGroupId = rightsGroupId;
this.RightsGroupName = rightsGroupName;
}





// 读取权限集合
System.Data.SqlTypes.SqlBytes bytes = myReader.GetSqlBytes(3); // 只能指定列序号
// 将流反序列化为权限集合对象
BinaryFormatter bf = new BinaryFormatter();


throw new Exception("用户密码长度不能小于六位!");


// 转换操作员权限集合为数据库可存取的 Byte[] 数组
MemoryStream ms = new MemoryStream();




internal
currentChildTreeNode.Tag.ToString()
// 递归添加到当前节点及其所有子节点
currentChildTreeNode.Nodes.Add(LoadAllChildTreeNode(newChildTreeNode, rightsCollection));


this._dgvOperatorList.Columns["ModelName"].ToolTipText = "[只读列]";
this._dgvOperatorList.Columns["Password"].DisplayIndex = 2;         索引列   
this._dgvOperatorList.Columns["RightsCollection"].ReadOnly = true;  提示工具































评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值