三、Business层
Business层主要完成一些对于业务逻辑的处理,以及参数传递的工作。
对于每一个功能,通常是一个FORM 要对应一个Business下的子层,例如处理用户登录的功能,就在Business下,添加一个Login文件夹,文件夹中包括两个文件,UserLimits和UserParameter,UserLimits主要用来业务逻辑处理,以及调用EntityClass层中相应对数据库操作的函数;UserParameter主要完成参数传递。
UserParameter的代码如下:
Namespace business.login
Public Class UserParameter
Private _ID As String
Private _UserName As String
Private _Password As String
'_ID 的set和get方法
Public Function set_ID(ByVal m_id As String) As String
Me._ID = m_id
End Function
Public Function get_ID() As String
Return (Me._ID)
End Function
'_UserName的set和get 方法
Public Function set_UserName(ByVal m_UserName As String) As String
Me._UserName = m_UserName
End Function
Public Function get_UserName() As String
Return (Me._UserName)
End Function
'_Password的set和get 方法
Public Function set_Password(ByVal m_Password As String) As String
Me._Password = m_Password
End Function
Public Function get_Password() As String
Return (Me._Password)
End Function
'Public Function chackLogin(ByVal user As Integer, ByVal pass As Integer) As Integer
' Dim up As Integer = 0
' If up.Equals(0) Then
' If user.Equals(pass) Then
' Return 1
' Else
' Return 0
' End If
' End If
'End Function
End Class
End Namespace
可以看到,只是包括对应数据库中表的字段的属性,以及对其的set和get方法。
UserLimits的代码如下:
Imports System
Imports System.Data
Imports System.Web
Namespace business.login
Public Class UserLimits
Private user As New EntityClass.S_User
Public Sub New()
' TODO: 在此处添加构造函数逻辑
Me.user = New EntityClass.S_User
End Sub
Public Function GetUserObj(ByVal username As String, ByVal password As String) As UserParameter
'MsgBox(1)
If (Me.user.GetUser(username, password) > 0) Then
'MsgBox(2)
Dim up As UserParameter = New UserParameter
up.set_ID(Me.user.Id_I)
up.set_UserName(Me.user.UserName_S)
up.set_Password(Me.user.Password_S)
Return up
Else
'Dim up1 As New UserParameter
'Return up1
Return Nothing
End If
End Function
'按id得到纪录
Public Function GetUserById(ByVal myid As String) As UserParameter
Me.user.Id_I = myid
If (Me.user.Load() > 0) Then
'MsgBox(2)
Dim up As UserParameter = New UserParameter
up.set_ID(Me.user.Id_I)
up.set_UserName(Me.user.UserName_S)
up.set_Password(Me.user.Password_S)
Return up
Else
'Dim up1 As New UserParameter
'Return up1
Return Nothing
End If
End Function
'增加用户
Public Function AddUserObj(ByVal adduser As UserParameter)
'Me.user.UserName_S = adduser.get_UserName
'Me.user.Password_S = adduser.get_Password
Me.user.setEntity(adduser)
'Me.user.SetDynamicColoum()
Try
Me.user.CreatUser()
Catch ex As Exception
End Try
End Function
'更新用户
Public Function UpdateUserObj(ByVal adduser As UserParameter)
'Me.user.UserName_S = adduser.get_UserName
'Me.user.Password_S = adduser.get_Password
Me.user.setEntity(adduser)
Try
Me.user.Updata()
Catch ex As Exception
End Try
End Function
'删除用户
Public Function DelUserObj(ByVal adduser As UserParameter)
Me.user.UserName_S = adduser.get_UserName
Me.user.Password_S = adduser.get_Password
Try
Me.user.Delete()
Catch ex As Exception
End Try
End Function
'得到所有用户列表
Public Function GetAllUser(ByRef dataset As DataSet)
Me.user.loadusers(dataset)
End Function
'根据sql查询语句查询
Public Function GetObjByQry(ByVal str As String) As UserParameter()
Dim objlen As Integer
Dim m_i As Integer
Dim mp(objlen - 1) As UserParameter
objlen = Me.user.GetObjByQry(str, mp)
Return mp
End Function
End Class
End Namespace
可以看到,主要是做业务逻辑的处理。