- ASP.NET Mobile Controls
- Three-tier architecture with ASP.NET
- Role Based Security
个人感觉上它把DAL和中间的商务层是放在一起的。不能算是Three-tier,决定自己对 ASP.NET Portal starter Kit动动小手术,把DAL和中间层分出来,把原来的SQL数据库转换成Access的数据库。
把SQL数据库转换成Acceess的数据库不知大家有没有注意一个问题。SQL数据库数据表Portal_Roles中的主键自动编号的标示种子是0,但是转换成Access的标示种子就是1开始,所以转换后的数据库需要手工修改一下,要么转换后的用户角色就会和原来的不匹配。
数据库转换完毕剩下的就是在DAL把原有的SQL的存储过程转换成相关的SQL语句,在DAL你可以老老实实的自己写一个DAL的基类然后再此基础上进行数据操作,或者可以用DAAB也行。我在这里用听棠的SPL把数据库中的所有数据表映射成数据实体然后进行操作。因为我用的是VB.NET,smartrobot生成的数据实体类代码是基于C#的所以需要在原来的解决方案的基础上添加一个C#的项目命名为DALLib作为整个Portal的DAL。
并把相关的配置文件放置在Config目录下面,剩下操作都不难了,就只有数据表Portal_Discussion的存储过程转换的过程稍微繁杂一点。
例如
CREATE PROCEDURE Portal_AddMessage
(
@ItemID int OUTPUT,
@Title nvarchar(100),
@Body nvarchar(3000),
@ParentID int,
@UserName nvarchar(100),
@ModuleID int
)
AS
/* Find DisplayOrder of parent item */
DECLARE @ParentDisplayOrder as nvarchar(750)
SET @ParentDisplayOrder = ""
SELECT
@ParentDisplayOrder = DisplayOrder
FROM Portal_Discussion
WHERE
ItemID = @ParentID
INSERT INTO Portal_Discussion
(
Title,
Body,
DisplayOrder,
CreatedDate,
CreatedByUser,
ModuleID
)
VALUES
(
@Title,
@Body,
@ParentDisplayOrder + CONVERT( nvarchar(24), GetDate(), 21 ),
GetDate(),
@UserName,
@ModuleID
)
SELECT
@ItemID = @@Identity
GO
(
@ItemID int OUTPUT,
@Title nvarchar(100),
@Body nvarchar(3000),
@ParentID int,
@UserName nvarchar(100),
@ModuleID int
)
AS
/* Find DisplayOrder of parent item */
DECLARE @ParentDisplayOrder as nvarchar(750)
SET @ParentDisplayOrder = ""
SELECT
@ParentDisplayOrder = DisplayOrder
FROM Portal_Discussion
WHERE
ItemID = @ParentID
INSERT INTO Portal_Discussion
(
Title,
Body,
DisplayOrder,
CreatedDate,
CreatedByUser,
ModuleID
)
VALUES
(
@Title,
@Body,
@ParentDisplayOrder + CONVERT( nvarchar(24), GetDate(), 21 ),
GetDate(),
@UserName,
@ModuleID
)
SELECT
@ItemID = @@Identity
GO
把原来的SQLConnection和Command换成以下的操作方法
Public Function AddMessage(ByVal moduleId As Integer, ByVal parentId As Integer, ByVal userName As String, ByVal title As String, ByVal body As String) As Integer
If userName.Length < 1 Then
userName = "unknown"
End If
Dim Disc As New Portal_DiscussionEntity
If parentId = 0 Then
'新插入
With Disc
.Title = title
.Body = body
.DisplayOrder = String.Format("{0:yyyy/MM/dd HH:mm:ss.fff}", DateTime.Now())
.CreatedDate = DateTime.Now
.CreatedByUser = userName
.ModuleID = moduleId
End With
Disc.Save()
Else
'回复
With Disc
.Title = title
.Body = body
.DisplayOrder = GetDisplayOrder(parentId) + String.Format("{0:yyyy/MM/dd HH:mm:ss.fff}", DateTime.Now())
.CreatedDate = DateTime.Now
.CreatedByUser = userName
.ModuleID = moduleId
End With
Disc.Save()
End If
Return Disc.ItemID
End Function
Public Function GetDisplayOrder(ByVal ItemID As Integer) As String
Dim Disc As New Portal_DiscussionEntity
Disc.ItemID = ItemID
Disc.Retrieve()
If Disc.IsPersistent Then
Return Disc.DisplayOrder
End If
End Function
If userName.Length < 1 Then
userName = "unknown"
End If
Dim Disc As New Portal_DiscussionEntity
If parentId = 0 Then
'新插入
With Disc
.Title = title
.Body = body
.DisplayOrder = String.Format("{0:yyyy/MM/dd HH:mm:ss.fff}", DateTime.Now())
.CreatedDate = DateTime.Now
.CreatedByUser = userName
.ModuleID = moduleId
End With
Disc.Save()
Else
'回复
With Disc
.Title = title
.Body = body
.DisplayOrder = GetDisplayOrder(parentId) + String.Format("{0:yyyy/MM/dd HH:mm:ss.fff}", DateTime.Now())
.CreatedDate = DateTime.Now
.CreatedByUser = userName
.ModuleID = moduleId
End With
Disc.Save()
End If
Return Disc.ItemID
End Function
Public Function GetDisplayOrder(ByVal ItemID As Integer) As String
Dim Disc As New Portal_DiscussionEntity
Disc.ItemID = ItemID
Disc.Retrieve()
If Disc.IsPersistent Then
Return Disc.DisplayOrder
End If
End Function
<add key="ConnectionString" value="server=localhost;Trusted_Connection=true;database=Portal" />
因为现在的连接字符串已经是在另外的配置文件DataBaseMap.XML中了.
个人觉得修改后的3层结构要更明晰一点。
首先项目DALLib作为整个解决方案的数据读取层,Portal项目中的Components文件夹中的类作为中间商务层,剩下的就是和实体映射相关配置文件和UI了。
上面的都是我个人的观点,错误的地方恳请大家指正。
相关链接:
ASP.NET Portal starter Kit ----页面配置文件之我见
asp.net Portal Starter kit----改造Portal的Html文本编辑器