这是第二遍做机房收费系统时的登录模块的代码记录,和后面发布的第三遍做收费系统的代码相比,自己觉得这遍写的真的很不好,不过这里还是要记录一下自己的学习脚印。
UI层:
Imports BLL
Imports Entity''' <summary>
''' 登陆
''' </summary>
''' <remarks>黄爱岗</remarks>
Public Class FrmLogin''' <summary>
''' 登陆系统验证以及添加记录
''' </summary>
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.ClickIf Trim(TxtUserID.Text = "") Then
MsgBox("用户名不能为空!", vbOKOnly, "警告")
Exit Sub
Else
If Trim(TxtPwd.Text = "") Then
MsgBox("密码不能为空!", vbOKOnly, "警告")
Exit Sub
End If
End IfDim EntityUserInfo As New Entity.user_Info
Dim EntityWorkLogInfo As New worklog_Info
Dim WorkLog As New bll_Login
Dim BllUserInfo As New BLL.bll_Login
Dim UserInfo As user_Info
Dim UserID As String '定义用户ID变量UserID = Trim(TxtUserID.Text)
UserInfo = BllUserInfo.GetObject(UserID)
If Not IsNothing(UserInfo) Then
'判断密码和级别是否一致
If Trim(TxtPwd.Text) = Trim(UserInfo.Password) And Trim(CboRank.Text) = Trim(UserInfo.Level) ThenEntityWorkLogInfo.UserID = Trim(UserInfo.UserID)
EntityWorkLogInfo.Level = Trim(UserInfo.Level)
EntityWorkLogInfo.LoginDate = Trim(Date.Today)
EntityWorkLogInfo.LoginTime = Trim(TimeOfDay)
EntityWorkLogInfo.LogoutDate = Trim(Date.Today)
EntityWorkLogInfo.LogoutTime = Trim(TimeOfDay)
EntityWorkLogInfo.Computer = Trim("0")
EntityWorkLogInfo.Status = Trim("正在工作")If WorkLog.Insert(EntityWorkLogInfo) Then
FrmMain.Show()
Me.Hide()
Else
MsgBox("登陆失败,请重新登陆!", vbOKOnly, "警告")
Exit Sub
End If
Else
MsgBox("用户名或密码错误, 请重新输入!", vbOKOnly, "警告")
TxtUserID.Text = ""
TxtPwd.Text = ""
CboRank.Focus()
Exit Sub
End If
End IfEnd Sub
BLL层:
Imports DAL
Public Class bll_Login
Private daUser As New da_User
Private daWorkLog As New da_WorkLog''' <summary>
''' 获得一个用户信息
''' </summary>
''' <param name="UserID">用户ID</param>
''' <returns>一个用户对象</returns>
''' <remarks>2011/3/23 13:15 By NOVAGang</remarks>
Public Function GetObject(ByVal UserID As String) As Entity.user_Info
Return daUser.GetObject(UserID)
End Function''' <summary>
''' 插入一条用户工作信息
''' </summary>
''' <param name="EntityWorkLogInfo">用户工作记录实体类</param>
''' <returns>是否插入成功</returns>
''' <remarks>2011/3/23 13:15 By NOVAGang</remarks>
Public Function Insert(ByVal EntityWorkLogInfo As Entity.worklog_Info) As Boolean
Return daWorkLog.Insert(EntityWorkLogInfo)
End FunctionEnd Class