子系统的配置管理参考界面,通用权限管理系统组件可以同时集中管理控制多个子系统,提高同时开发多个项目的效率。每个系统都可以独立,互相不干涉,灵活性高,部署开发方便,管理规范。
数据库里每个独立的子系统的参考效果图
创建子系统的相关代码,批量执行sql脚本,执行数据库事务的参考代码
////// 调用批量执行脚本的语句 /// 批量执行脚本 /// private void ExecuteScript(string[] lines) { using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { String sqlQuery = String.Empty; String sqlLine = String.Empty; try { // 打开数据库连接 dbHelper.Open(BaseSystemInfo.UserCenterDbConnection); dbHelper.BeginTransaction(); // 循环读取文本文件 for (int i = 0; i < lines.Length; i++) { sqlLine = lines[i]; if (sqlLine != null && !string.IsNullOrEmpty(sqlLine)) { if (sqlLine.ToUpper().Equals("GO")) { // 执行数据库查询语句 dbHelper.ExecuteNonQuery(sqlQuery); sqlQuery = string.Empty; } else { sqlQuery += sqlLine + System.Environment.NewLine; } } } dbHelper.CommitTransaction(); // 成功的提示信息 MessageBox.Show(AppMessage.MSG3010, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { dbHelper.RollbackTransaction(); // 在本地文件中记录系统异常信息 this.WriteException(ex); throw; } finally { // 关闭数据库库连接 dbHelper.Close(); } } } #region public bool CheckInputCreateSystem() 检查输入的有效性 /// /// 检查输入的有效性 /// public bool CheckInputCreateSystem() { // 是否没有输入系统编号 if (string.IsNullOrEmpty(this.txtSystemCode.Text)) { MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9977), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUser.Focus(); return false; } // 是否没有输入系统名称 if (string.IsNullOrEmpty(this.txtSystemName.Text)) { MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9978), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUser.Focus(); return false; } return true; } #endregion private void btnCreateSystem_Click(object sender, EventArgs e) { if (this.CheckInputCreateSystem()) { // 按系统的配置信息动态获取数据库连接 string file = Application.StartupPath + "//Resources/System.sql"; if (System.IO.File.Exists(file)) { // 读取指定的脚本文件 string[] lines = File.ReadAllLines(file); for (int i = 0; i < lines.Length; i++) { lines[i] = lines[i].Replace("{SystemCode}", this.txtSystemCode.Text).Replace("{SystemName}", this.txtSystemName.Text); } this.ExecuteScript(lines); } } }
创建子系统的脚本参考
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[{SystemCode}Items](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[ParentId] [
int
] NULL,
[Code] [nvarchar](50) NULL,
[FullName] [nvarchar](100) NULL,
[TargetTable] [nvarchar](50) NULL,
[IsTree] [
int
] NOT NULL,
[UseItemCode] [nvarchar](50) NOT NULL,
[UseItemName] [nvarchar](50) NOT NULL,
[UseItemValue] [nvarchar](50) NOT NULL,
[Enabled] [
int
] NOT NULL,
[AllowEdit] [
int
] NOT NULL,
[AllowDelete] [
int
] NOT NULL,
[DeletionStateCode] [
int
] NOT NULL,
[SortCode] [
int
] NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}Items] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsIsTree] DEFAULT ((0)) FOR [IsTree]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsUseItemCode] DEFAULT (N
'编号'
) FOR [UseItemCode]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsUseItemName] DEFAULT (N
'名称'
) FOR [UseItemName]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsUseItemValue] DEFAULT (N
'值'
) FOR [UseItemValue]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsAllowEdit] DEFAULT ((1)) FOR [AllowEdit]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsAllowDelete] DEFAULT ((1)) FOR [AllowDelete]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}Items] ADD CONSTRAINT [DF_{SystemCode}ItemsModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
CREATE TABLE [dbo].[{SystemCode}Module](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[ParentId] [
int
] NULL,
[Code] [nvarchar](100) NULL,
[FullName] [nvarchar](100) NULL,
[Category] [nvarchar](50) NULL,
[ImageIndex] [nvarchar](50) NULL,
[SelectedImageIndex] [nvarchar](50) NULL,
[NavigateUrl] [nvarchar](200) NULL,
[Target] [nvarchar](100) NULL,
[FormName] [nvarchar](100) NULL,
[AssemblyName] [nvarchar](100) NULL,
[PermissionItemCode] [nvarchar](50) NULL,
[PermissionScopeTables] [nvarchar](500) NULL,
[SortCode] [
int
] NULL,
[Enabled] [
int
] NOT NULL,
[DeletionStateCode] [
int
] NOT NULL,
[IsMenu] [
int
] NULL,
[IsPublic] [
int
] NOT NULL,
[Expand] [
int
] NOT NULL,
[AllowEdit] [
int
] NOT NULL,
[AllowDelete] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}Module] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModulePermissionItemCode] DEFAULT (N
'Resource.AccessPermission'
) FOR [PermissionItemCode]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleIsMenu] DEFAULT ((1)) FOR [IsMenu]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleIsPublic] DEFAULT ((0)) FOR [IsPublic]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleExpand] DEFAULT ((0)) FOR [Expand]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleAllowEdit] DEFAULT ((1)) FOR [AllowEdit]
GO
ALTER TABLE [dbo].[{SystemCode}Module] ADD CONSTRAINT [DF_{SystemCode}ModuleAllowDelete] DEFAULT ((1)) FOR [AllowDelete]
GO
CREATE TABLE [dbo].[{SystemCode}Permission](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[ResourceCategory] [nvarchar](50) NULL,
[ResourceId] [nvarchar](50) NULL,
[PermissionId] [nvarchar](50) NULL,
[PermissionConstraint] [nvarchar](200) NULL,
[Enabled] [
int
] NULL,
[DeletionStateCode] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}Permission] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}Permission] ADD CONSTRAINT [DF_{SystemCode}PermissionDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}Permission] ADD CONSTRAINT [DF_{SystemCode}PermissionCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}Permission] ADD CONSTRAINT [DF_{SystemCode}PermissionModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
CREATE TABLE [dbo].[{SystemCode}PermissionItem](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[ParentId] [
int
] NULL,
[Code] [nvarchar](100) NULL,
[FullName] [nvarchar](200) NULL,
[CategoryCode] [nvarchar](50) NOT NULL,
[IsScope] [
int
] NOT NULL,
[IsPublic] [
int
] NOT NULL,
[IsVisible] [
int
] NOT NULL,
[AllowEdit] [
int
] NOT NULL,
[AllowDelete] [
int
] NOT NULL,
[LastCall] [smalldatetime] NULL,
[SortCode] [
int
] NULL,
[Enabled] [
int
] NOT NULL,
[DeletionStateCode] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}PermissionItem] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemCategoryCode] DEFAULT (N
'Application'
) FOR [CategoryCode]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemIsScope] DEFAULT ((0)) FOR [IsScope]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemIsPublic] DEFAULT ((0)) FOR [IsPublic]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemIsVisible] DEFAULT ((1)) FOR [IsVisible]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemAllowEdit] DEFAULT ((1)) FOR [AllowEdit]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemAllowDelete] DEFAULT ((1)) FOR [AllowDelete]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionItem] ADD CONSTRAINT [DF_{SystemCode}PermissionItemModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
CREATE TABLE [dbo].[{SystemCode}PermissionScope](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[ResourceCategory] [nvarchar](50) NULL,
[ResourceId] [nvarchar](50) NULL,
[TargetCategory] [nvarchar](50) NULL,
[TargetId] [nvarchar](50) NULL,
[PermissionId] [
int
] NULL,
[PermissionConstraint] [nvarchar](200) NULL,
[StartDate] [smalldatetime] NULL,
[EndDate] [smalldatetime] NULL,
[Enabled] [
int
] NOT NULL,
[DeletionStateCode] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}PermissionScope] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionScope] ADD CONSTRAINT [DF_{SystemCode}PermissionScopeEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionScope] ADD CONSTRAINT [DF_{SystemCode}PermissionScopeDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionScope] ADD CONSTRAINT [DF_{SystemCode}PermissionScopeCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}PermissionScope] ADD CONSTRAINT [DF_{SystemCode}PermissionScopeModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
CREATE TABLE [dbo].[{SystemCode}Role](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[SystemId] [nvarchar](50) NULL,
[OrganizeId] [
int
] NULL,
[CategoryCode] [nvarchar](50) NULL,
[Code] [nvarchar](50) NULL,
[Realname] [nvarchar](200) NULL,
[AllowEdit] [
int
] NOT NULL,
[AllowDelete] [
int
] NOT NULL,
[IsVisible] [
int
] NOT NULL,
[SortCode] [
int
] NULL,
[DeletionStateCode] [
int
] NOT NULL,
[Enabled] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}Role] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleAllowEdit] DEFAULT ((1)) FOR [AllowEdit]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleAllowDelete] DEFAULT ((1)) FOR [AllowDelete]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleIsVisible] DEFAULT ((1)) FOR [IsVisible]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleSortCode] DEFAULT ((0)) FOR [SortCode]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}Role] ADD CONSTRAINT [DF_{SystemCode}RoleModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
CREATE TABLE [dbo].[{SystemCode}UserRole](
[Id] [
int
] IDENTITY(1,1) NOT NULL,
[UserId] [
int
] NULL,
[RoleId] [
int
] NOT NULL,
[SortCode] [
int
] NULL,
[Enabled] [
int
] NOT NULL,
[DeletionStateCode] [
int
] NOT NULL,
[Description] [nvarchar](200) NULL,
[CreateOn] [smalldatetime] NULL,
[CreateUserId] [nvarchar](20) NULL,
[CreateBy] [nvarchar](20) NULL,
[ModifiedOn] [smalldatetime] NULL,
[ModifiedUserId] [nvarchar](20) NULL,
[ModifiedBy] [nvarchar](20) NULL,
CONSTRAINT [PK_{SystemCode}UserRole] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[{SystemCode}UserRole] ADD CONSTRAINT [DF_{SystemCode}UserRoleEnabled] DEFAULT ((1)) FOR [Enabled]
GO
ALTER TABLE [dbo].[{SystemCode}UserRole] ADD CONSTRAINT [DF_{SystemCode}UserRoleDeletionStateCode] DEFAULT ((0)) FOR [DeletionStateCode]
GO
ALTER TABLE [dbo].[{SystemCode}UserRole] ADD CONSTRAINT [DF_{SystemCode}UserRoleCreateOn] DEFAULT (getdate()) FOR [CreateOn]
GO
ALTER TABLE [dbo].[{SystemCode}UserRole] ADD CONSTRAINT [DF_{SystemCode}UserRoleModifiedOn] DEFAULT (getdate()) FOR [ModifiedOn]
GO
INSERT INTO [dbo].[{SystemCode}PermissionItem] ([Code],[FullName],[IsVisible]) VALUES(
'Resource.ManagePermission'
,
'资源管理权限[系统内置]'
, 0)
GO
INSERT INTO [dbo].[{SystemCode}PermissionItem] ([Code],[FullName],[IsVisible]) VALUES(
'Resource.AccessPermission'
,
'资源访问权限[系统内置]'
, 0)
GO
INSERT INTO [dbo].[{SystemCode}PermissionItem] ([Code],[FullName],[IsVisible]) VALUES(
'Column.Access'
,
'访问列权限[系统内置]'
, 0)
GO
INSERT INTO [dbo].[{SystemCode}PermissionItem] ([Code],[FullName],[IsVisible]) VALUES(
'Column.Edit'
,
'编辑列访问[系统内置]'
, 0)
GO
INSERT INTO [dbo].[{SystemCode}PermissionItem] ([Code],[FullName],[IsVisible]) VALUES(
'Column.Deney'
,
'拒绝访问列[系统内置]'
, 0)
GO
INSERT INTO [dbo].[ItemsSystem] ([ItemCode],[ItemName],[ItemValue]) VALUES(
'{SystemCode}'
,
'{SystemName}'
,
'{SystemCode}'
)
GO