当前位置:网站首页>房费制——登录优化
房费制——登录优化
2022-07-06 19:36:00 【全栈程序员站长】
大家好,又见面了,我是全栈君
《客房收费系统个人版》基本完成,矿U层的代码是非常非常混乱。基本上D层有几个函数,B层就相应有几个函数,U层使用相应B层中的每个函数。比方说在登录中,U层首次要使用一个函数检查username和用户password是否正确,然后再使用“加入用户上机记录”的函数。以下是登录的时序图:
登录业务比較简单,可是对于复杂的上机过程呢?U层要检查卡是否注冊。剩余金额是否充足,卡的状态是否在使用中。该卡是否如今不在线,通过这一系列检验后,还要查询学生表显示学生信息等等。
这样就造成U层有好多函数,和B层的耦合度太大。如今我们来回想一下三层中各层的功能:
表现层(UI):採集用户的输入信息和操作,向用户展现特定业务数据。通俗讲就是用户界面,即用户在使用一个系统的时候他的所见所得。
业务逻辑层(BLL):针对详细问题的操作。也能够说是对数据层的操作。对数据业务逻辑处理。主要有三种方式:从UI中获取用户指令和数据,运行业务逻辑;从DAL中获取数据,以供UI显示;从UI中获取用户指令和数据,通过DAL写入数据源。
数据訪问层(DAL):该层所做事务直接操作数据库,针对数据的增添、删除、改动、查找等。
在师傅的指点下,进行了改动:
U层:
'登录
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
'查空
If PublicFunction.IsEmptyText(Me) = True Then
Exit Sub
End If
'实例化实体User,引用B层
Dim euser As New Entity.User
Dim euserRecord As New Entity.UserRecord
Dim blogin As New BLL.LoginBLL
Try
'将用户输入的信息传给实体
euser.ProuserID = txtUserID.Text.Trim
euser.ProuserPwd = txtUserPwd.Text
'用户验证后反馈信息
If blogin.Check(euser, euserRecord) Then '登录成功
''UserID和UserLevel为全局变量,其它功能要用到
UserID = euser.ProuserID.Trim '去空格
UserLevel = euser.ProuserLevel.Trim '去空格
'主窗口显示
Me.Hide()
frmMain.Show()
Else
MsgBox("登录失败!username或password有误。", vbExclamation, "系统提示") txtUserID.Focus() Exit Sub End If Catch ex As Exception MsgBox("错误!", vbExclamation, "系统提示") End Try End SubB层:
Public Function Check(ByVal euser As Entity.User, ByVal euserRecord As Entity.UserRecord) As Boolean
Dim dt As DataTable
dt = iuser.QueryUser(euser)
Try
If dt.Rows.Count = 0 Then
Return False
Else 'username和password输入正确
euser.ProuserID = dt.Rows(0).Item(0) '用户ID
euser.ProuserLevel = dt.Rows(0).Item(2) '用户级别
'输入用户上机记录信息
euserRecord.ProuserID = euser.ProuserID
euserRecord.ProuserLevel = euser.ProuserLevel
euserRecord.ProloginTime = Now
euserRecord.PrologoutTime = Now
euserRecord.ProisOnline = 1 '1表示在线。0表示不在线
euserRecord.Procomputer = My.Computer.Name '获得当前电脑的username
'加入用户上机记录
Dim result As Integer
result = iuser.AddUserRecord(euserRecord)
If result <> 0 Then '加入用户记录成功
Return True
End If
End If
Catch ex As Exception
Throw New Exception
End Try
End FunctionD层:
'查找用户的方法
Public Function QueryUser(euser As Entity.User) As DataTable Implements IUser.QueryUser
Try
Dim strSQL As String = "select * from T_User where [email protected] and [email protected] "
Dim params() As SqlParameter = {New SqlParameter("@userID", euser.ProuserID), New SqlParameter("@userPwd", euser.ProuserPwd)}
Dim helper As New SqlHelper.sqlHelper
Dim table = helper.GetDataTable(strSQL, CommandType.Text, params)
Return table
Catch ex As Exception
Throw New Exception
End Try
End Function
'用户登录成功加入记录到UserRecord
Public Function AddUserRecord(euserRecord As Entity.UserRecord) As Integer Implements IUser.AddUserRecord
'每个字段都填写时,可省略前面括号里的内容
'Dim strSQL As String = "insert into T_UserRecord values(@userID,@level,@loginTime,@logoutTime,@computer,@isOnline)"
Try
Dim strSQL As String = "insert into T_UserRecord (userID,userLevel,loginTime,logoutTime,computer,isOnline)values(@userID,@level,@loginTime,@logoutTime,@computer,@isOnline)"
Dim params() As SqlParameter = {New SqlParameter("@userID", euserRecord.ProuserID),
New SqlParameter("@level", euserRecord.ProuserLevel),
New SqlParameter("@loginTime", euserRecord.ProloginTime),
New SqlParameter("@logoutTime", euserRecord.PrologoutTime),
New SqlParameter("@computer", euserRecord.Procomputer),
New SqlParameter("@isOnline", euserRecord.ProisOnline)}
Dim helper As New SqlHelper.sqlHelper
Dim intResult = helper.ExecuteNoQuery(strSQL, CommandType.Text, params)
Return intResult
Catch ex As Exception
Throw New Exception
End Try
End Function改动后的登录时序图:
两幅登录时序图形成鲜明的对照,这样用户点击“登录”button后,U层负责採集用户输入的username和password,然后仅仅需调用一个Check()函数进行验证。B层处理业务逻辑。先推断用户信息,若输入正确则进行下一步加入用户上机记录。D层和数据库打交道。进行增删改查。U层根本不知道详细的验证用户细节。这样就解耦了,各司其职。
小结:从去年的第一次机房收费系统。到如今的个人版重构。以及接下来的合作重构,每一步都是跨越。最初我们是纯面向过程的,如今学习了三层架构,使用了设计模式,但距离面向对象仍然非常遥远。我们正在一步一步向前走,这个过程非常重要。好比是唐僧西天取经,假设让孙悟空翻个跟头就能取到经。那就不会有经典的《西游记》了。
版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116772.html原文链接:https://javaforall.cn
边栏推荐
- Redis入门完整教程:客户端案例分析
- The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing
- Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush
- 首届“量子计算+金融科技应用”研讨会在京成功举办
- wireshark安装
- Construction of knowledge map of mall commodities
- 又一百万量子比特!以色列光量子初创公司完成1500万美元融资
- Number theory --- fast power, fast power inverse element
- How to verify accesstoken in oauth2 protocol
- How to find file accessed / created just feed minutes ago
猜你喜欢

Dotconnect for DB2 Data Provider
MySQL提升大量数据查询效率的优化神器

Utilisation de la promesse dans es6

从零安装Redis

Es6中Promise的使用

Es6中Promise的使用

The first symposium on "quantum computing + application of financial technology" was successfully held in Beijing

【2022国赛模拟】多边形——计算几何、二分答案、倍增

首届“量子计算+金融科技应用”研讨会在京成功举办

tensorboard的使用
随机推荐
Simple bubble sort
Unity uses maskablegraphic to draw a line with an arrow
QT Bluetooth: qbluetooth DeviceInfo
C language exercises_ one
[2022 national tournament simulation] polygon - computational geometry, binary answer, multiplication
你知道电子招标最突出的5大好处有哪些吗?
Remember the problem analysis of oom caused by a Jap query
【2022国赛模拟】多边形——计算几何、二分答案、倍增
What are the applications and benefits of MES management system
Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush
2022 spring recruitment begins, and a collection of 10000 word interview questions will help you
Redis getting started complete tutorial: replication configuration
Planning and design of double click hot standby layer 2 network based on ENSP firewall
New benchmark! Intelligent social governance
Construction of knowledge map of mall commodities
哈希表及完整注释
centerX: 用中国特色社会主义的方式打开centernet
代码调试core-踩内存
又一百万量子比特!以色列光量子初创公司完成1500万美元融资
Redis入门完整教程:问题定位与优化