一、建立 SQL Server 数据库模型
1、原始方案
一共设立了五个实体模型:
A、操作员(Operator):存储系统登录用户的名称、密码、启用状态等信息。
B、权限组(RightsGroup):存储系统权限分组(即:权限角色)的名称等信息。
C、权限关系(RightsRelation):用于将A项和B项之间的多对多关系拆解成两个一对多关系。
D、权限列表(RightsList):存储系统菜单项(即:权限项)的标题、内部名称、权限状态等信息。
E、权限组关系(RightGroupRelation):用于将B项和D项之间的多对多关系拆解成两个一对多关系。
通过上面的描述可以清楚看到,C项和E项仅仅是为了拆解多对多关系而设立,实体关系变得相对复杂了点。稍作考虑便知,既然是使用 C# WinForm + SQL Server 来完成这一功能,则可以考虑使用实体类来模拟数据库模型,并将实体类打包成泛型集合后存储到 SQL Server 数据库的 varBinary(max) 字段。这样便可以将原始方案的数据库模型缩减成三个实体模型,降低了关系的复杂程度。将原始方案稍作修改后即可得到如下改进方案。
2、改进方案
如上所述,改进后的方案仅包含如下三个实体模型:
A、操作员(Operator):存储系统登录用户的名称、密码、启用状态、权限集合等信息。
B、权限组(RightsGroup):存储系统权限分组(即:权限角色)的名称、权限集合等信息。
C、权限关系(RightsRelation):用于将A项和B项之间的多对多关系拆解成两个一对多关系。
很容易看出,仅将原始方案的 E 项更改为 A项和 B 项的字段,即可将实体关系复杂度降低 40%。现在我们来看看改进方案的 SQL Server 数据库实现脚本代码:
-- 判断是否存在 操作员信息表(Operator),如果存在,则删除表 Operator
if exists(Select * From SysObjects Where Name = 'Operator')
Drop Table [Operator]
Go
-- 创建 操作员信息表(Operator)
Create Table [Operator]
(
-- 主键列,自动增长 标识种子为 1
[Id] int identity(1,1) Constraint [PK_OperatorId] Primary Key,
-- 操作员姓名
[OperatorName] nVarChar(50) Constraint [UQ_OperatorName] Unique(OperatorName) Not Null,
-- 密码
[Password] nVarChar(50) Constraint [CK_Password] Check(len([Password])>=6) Not Null,
-- 操作员权限列表
[RightsList] varBinary(max) Null,
-- 用户当前状态
[State] bit Constraint [DF_State] Default('true') Constraint [CK_State] Check([State] in ('true','false')) Not Null,
)
Go
-- 判断是否存在 权限组信息表(RightsGroup),如果存在,则删除表 RightsGroup
if exists(Select * From SysObjects Where Name = 'RightsGroup')
Drop Table [RightsGroup]
Go
-- 创建 权限组信息表(RightsGroup)
Create Table [RightsGroup]
(
-- 主键列,自动增长 标识种子为 1
[Id] int Identity(1,1) Constraint [PK_RightsGroupId] Primary Key,
-- 权限组名称
[GroupName] nVarChar(50) Constraint[UQ_GroupName] Unique (GroupName) Not Null,
-- 组权限列表
[GroupRightsList] varBinary(max) Null,
)
Go
-- 判断是否存在权限关系表(RightsRelation),如果存在,则删除表 RightsRelation
if exists(Select * From SysObjects Where Name = 'RightsRelation')
drop table [RightsRelation]
Go
-- 创建 权限关系表(RightsRelation)
Create Table [RightsRelation]
(
-- 主键列,自动增长 标识种子为 1
[Id] int Identity(1, 1) Constraint [PK_RightsRelationId] Primary Key,
-- 操作员 Id
[OperatorId] int Constraint [FK_OperatorId] Foreign Key References Operator([Id]) Not Null,
-- 权限组 Id
[RightsGroupId] int Constraint [FK_RightsGroupId] Foreign Key References RightsGroup([Id]) Not Null
)
Go
二、建立实体类
建立了 SQL Server 数据库模型之后,我们开始建立实体类来作为权限管理的数据传输载体。
1、实体模型基类(ModelBase)
C#源码清单:
using System;
using System.Collections.Generic;
using System.Text;
namespace CodingMouse.CMHotelManager.Model
{
/// <summary>
/// 实体模型基类
/// </summary>
[Serializable]
public class ModelBase
{
#region Private Members
int _id;
string _modelName;
#endregion
#region Public Properties
/// <summary>
/// 实体模型 ID
/// </summary>
public int Id
{
get { return _id; }
set { _id = value; }
}
/// <summary>
/// 实体模型名称
/// </summary>
public string ModelName
{
get { return _modelName; }
set { _modelName = value; }
}
#endregion
#region Public Methods
/// <summary>
/// 无参构造
/// </summary>
public ModelBase() { }
/// <summary>
/// 带参构造
/// </summary>
/// <param name="id">实体模型 ID</param>
/// <param name="modelName">实体模型名称</param>
public ModelBase(int id, string modelName)
{
this.Id = id;
this.ModelName = modelName;
}
#endregion
}
}
2、操作员实体类(Operator)
C#源码清单:
using System;
using System.Collections.Generic;
using System.Text;
namespace CodingMouse.CMHotelManager.Model
{
/// <summary>
/// 操作员实体类
/// </summary>
[Serializable]
public class Operator : ModelBase
{
#region Private Members
string _password;
Dictionary<string, Rights> _rightsCollection;
bool _state;
#endregion
#region Public Properties
/// <summary>
/// 操作员密码
/// </summary>
public string Password
{
get { return _password; }
set { _password = value; }
}
/// <summary>
/// 权限集合(键值用于存储菜单/工具栏项的 Name 属性)
/// </summary>
public Dictionary<string, Rights> RightsCollection
{
get { return _rightsCollection; }
set { _rightsCollection = value; }
}
/// <summary>
/// 操作员状态
/// </summary>
public bool State
{
get { return _state; }
set { _state = value; }
}
#endregion
#region Public Methods
/// <summary>
/// 无参构造(基类属性赋值说明:Id - 操作员 ID / ModelName - 操作员名称)
/// </summary>
public Operator() { }
/// <summary>
/// 带参构造
/// </summary>
/// <param name="operatorId">操作员 ID</param>
/// <param name="name">操作员名称</param>
/// <param name="password">操作员密码</param>
/// <param name="rightsCollection">权限集合(键值用于存储菜单/工具栏项的 Name 属性)</param>
/// <param name="state">操作员状态</param>
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;
}
#endregion
}
}
3、权限组实体类(RightsGroup)
C#源码清单:
using System;
using System.Collections.Generic;
using System.Text;
namespace CodingMouse.CMHotelManager.Model
{
/// <summary>
/// 权限组实体类
/// </summary>
[Serializable]
public class RightsGroup : ModelBase
{
#region Private Members
Dictionary<string, Rights> _groupRightsCollection;
#endregion
#region Public Properties
/// <summary>
/// 组权限集合
/// </summary>
public Dictionary<string, Rights> GroupRightsCollection
{
get { return _groupRightsCollection; }
set { _groupRightsCollection = value; }
}
#endregion
#region Public Methods
/// <summary>
/// 无参构造(基类属性赋值说明:Id - 权限组 ID / ModelName - 权限组名称)
/// </summary>
public RightsGroup() { }
/// <summary>
/// 带参构造
/// </summary>
/// <param name="groupId">权限组 ID</param>
/// <param name="groupName">权限组名称</param>
/// <param name="groupRightsCollection">组权限集合</param>
public RightsGroup(
int groupId,
string groupName,
Dictionary<string, Rights> groupRightsCollection)
: base(groupId, groupName)
{
this.GroupRightsCollection = groupRightsCollection;
}
#endregion
}
}
4、权限关系实体类(RightsRelation)
C#源码清单:
us
没有合适的资源?快使用搜索试试~ 我知道了~
C# WinForm角色的权限菜单-源码.zip
共121个文件
cs:64个
png:26个
resx:11个
需积分: 44 39 下载量 178 浏览量
2019-08-16
11:15:30
上传
评论 1
收藏 383KB ZIP 举报
温馨提示
基于角色的权限菜单功能的实现 C# WinForm中实现基于角色的权限菜单 代码完整 有附数据库结构 下载即可使用
资源推荐
资源详情
资源评论
收起资源包目录
C# WinForm角色的权限菜单-源码.zip (121个子文件)
App.config 380B
frmRightsGroupManager.cs 51KB
frmGroupClientList.Designer.cs 34KB
frmGroupClientList.cs 29KB
frmRightsManager.Designer.cs 27KB
frmRightsManager.cs 27KB
frmRightsGroupManager.Designer.cs 22KB
frmGlobalException.designer.cs 18KB
RightsMenuUIManager.cs 18KB
frmMain.Designer.cs 17KB
frmOperatorManager.cs 13KB
ConsumableService.cs 12KB
OperatorService.cs 12KB
frmMain.cs 12KB
frmLogin.cs 10KB
frmGlobalException.cs 10KB
Resources.Designer.cs 9KB
RightsMenuDataManager.cs 9KB
RightsRelationService.cs 9KB
frmAddRightsRelation.Designer.cs 9KB
frmOperatorManager.Designer.cs 9KB
RightsGroupService.cs 8KB
frmAddRightsRelation.cs 8KB
frmLogin.Designer.cs 8KB
frmSendFeedbackEMail.designer.cs 6KB
RightsRelationManager.cs 5KB
OperatorManager.cs 5KB
OleDBProvider.cs 5KB
SqlDBProvider.cs 5KB
frmSendFeedbackEMail.cs 4KB
frmLockScreen.Designer.cs 4KB
AbstractDBProvider.cs 4KB
frmLockScreen.cs 4KB
RightsGroupManager.cs 4KB
EmailManager.cs 3KB
RightsRelation.cs 2KB
Rights.cs 2KB
Operator.cs 2KB
IRightsRelationManager.cs 2KB
IRightsRelationService.cs 2KB
AbstractDALFactory.cs 2KB
IOperatorManager.cs 2KB
IOperatorService.cs 2KB
IRightsGroupService.cs 1KB
IRightsGroupManager.cs 1KB
IVIPClientService.cs 1KB
RightsGroup.cs 1KB
IVIPClientManager.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
AssemblyInfo.cs 1KB
Program.cs 1KB
DALFactory.cs 1KB
ModelBase.cs 1KB
BLLFactory.cs 1KB
AssemblyInfo.cs 1KB
Settings.Designer.cs 1KB
GlobalExceptionManager.cs 993B
ModelCommonEnum.cs 508B
CMTextBox.cs 208B
CMCSharpSDK.csproj 9KB
BLL.csproj 3KB
DAL.csproj 3KB
DALFactory.csproj 3KB
BLLFactory.csproj 3KB
IBLL.csproj 2KB
IDAL.csproj 2KB
DBUtility.csproj 2KB
Model.csproj 2KB
Thumbs.db 70KB
CMCSharpSDK.ico 2KB
CMCSharpSDK.ico 2KB
LoginUI.png 91KB
RefreshRightsList.png 3KB
Clock.png 3KB
Web.png 3KB
Help.png 3KB
ExitSystem.png 3KB
RightsGroupManager.png 3KB
RightsMode.png 3KB
SaveAllChanged.png 3KB
LogOff.png 3KB
LockScreen.png 3KB
CloseWindow.png 2KB
RefreshOperatorList.png 2KB
ModifyPassword.png 2KB
AddOperator.png 2KB
DeleteOperator.png 2KB
TaskHS.png 819B
RoutingSlipHS.png 773B
PropertiesHS.png 697B
LegendHS.png 650B
HomeHS.png 619B
CheckGrammarHS.png 599B
OptionsHS.png 572B
共 121 条
- 1
- 2
资源评论
qq_31096329
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功