权限管理----模块管理
权限管理,不但有角色大方面来控制用户所拥有的权限,还是以模块来控制,这样可以让权限分得更细些。
这方法与角色管理表结构与存储过程是一样的,只是一些表名写字段名称不一样而已。
在asp.net后台管理介面如下截图:
数据表[Module]结构如下:
代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Module](
[ModuleId] [smallint] IDENTITY(1,1) NOT NULL,
[ModuleName] [nvarchar](50) NOT NULL,
[Description] [nvarchar](100) NOT NULL,
PRIMARY KEY CLUSTERED
(
[ModuleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UK_Module_UD980sA6] UNIQUE NONCLUSTERED
(
[ModuleName] 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
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Module](
[ModuleId] [smallint] IDENTITY(1,1) NOT NULL,
[ModuleName] [nvarchar](50) NOT NULL,
[Description] [nvarchar](100) NOT NULL,
PRIMARY KEY CLUSTERED
(
[ModuleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [UK_Module_UD980sA6] UNIQUE NONCLUSTERED
(
[ModuleName] 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
插入存储过程usp_Module_Insert:
代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Module_Insert]
(
@ModuleName nvarchar(50),
@Description nvarchar(50)
)
AS
SELECT [ModuleName] FROM [Module] WHERE [ModuleName]=@ModuleName
IF @@ROWCOUNT>0
BEGIN
RAISERROR(N'此模块已经存在,无法添加!',16,1)
RETURN
END
ELSE
BEGIN TRANSACTION
INSERT INTO dbo.Module([ModuleName],[Description]) VALUES (@ModuleName,@Description)
IF @@ERROR<>0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Module_Insert]
(
@ModuleName nvarchar(50),
@Description nvarchar(50)
)
AS
SELECT [ModuleName] FROM [Module] WHERE [ModuleName]=@ModuleName
IF @@ROWCOUNT>0
BEGIN
RAISERROR(N'此模块已经存在,无法添加!',16,1)
RETURN
END
ELSE
BEGIN TRANSACTION
INSERT INTO dbo.Module([ModuleName],[Description]) VALUES (@ModuleName,@Description)
IF @@ERROR<>0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
更新存储过程usp_Module_Update:
代码
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Module_Update]
(
@ID tinyint,
@ModuleName nvarchar(50),
@Description nvarchar(50)
)
AS
SELECT [ModuleName] FROM [Module] WHERE [ModuleName]=@ModuleName AND [ModuleId]<>@ID
IF @@ROWCOUNT>0
BEGIN
RAISERROR(N'此模块已经存在,无法更新!',16,1)
RETURN
END
ELSE
BEGIN TRANSACTION
UPDATE [Module] SET [ModuleName]=@ModuleName,[Description]=@Description WHERE [ModuleId]=@ID
IF @@ERROR<>0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
GO
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_Module_Update]
(
@ID tinyint,
@ModuleName nvarchar(50),
@Description nvarchar(50)
)
AS
SELECT [ModuleName] FROM [Module] WHERE [ModuleName]=@ModuleName AND [ModuleId]<>@ID
IF @@ROWCOUNT>0
BEGIN
RAISERROR(N'此模块已经存在,无法更新!',16,1)
RETURN
END
ELSE
BEGIN TRANSACTION
UPDATE [Module] SET [ModuleName]=@ModuleName,[Description]=@Description WHERE [ModuleId]=@ID
IF @@ERROR<>0
BEGIN
ROLLBACK TRANSACTION
END
COMMIT TRANSACTION
GO