当前位置:网站首页>房费制——登录优化
房费制——登录优化
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
边栏推荐
- Unity uses maskablegraphic to draw a line with an arrow
- Oracle connection pool is not used for a long time, and the connection fails
- 代码调试core-踩内存
- Code debugging core step memory
- Qt蓝牙:QBluetoothDeviceInfo
- 杰理之开 BLE 退出蓝牙模式卡机问题【篇】
- The 8 element positioning methods of selenium that you have to know are simple and practical
- 杰理之播内置 flash 提示音控制播放暂停【篇】
- Classify the features of pictures with full connection +softmax
- Cryptography series: detailed explanation of online certificate status protocol OCSP
猜你喜欢

Es6中Promise的使用

【Socket】①Socket技术概述

如何分析粉丝兴趣?

Nuggets quantification: obtain data through the history method, and use the same proportional compound weight factor as Sina Finance and snowball. Different from flush

A complete tutorial for getting started with redis: AOF persistence

杰理之播内置 flash 提示音控制播放暂停【篇】

你知道电子招标最突出的5大好处有哪些吗?

巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...

Dotconnect for DB2 Data Provider

Software testing -- common assertions of JMeter interface testing
随机推荐
Redis入门完整教程:AOF持久化
杰理之FM 模式单声道或立体声选择设置【篇】
PSINS中19维组合导航模块sinsgps详解(滤波部分)
uniapp适配问题
Unity custom webgl packaging template
New benchmark! Intelligent social governance
杰理之RTC 时钟开发【篇】
Redis入门完整教程:客户端管理
【Socket】①Socket技术概述
Shell 编程基础
How to design interface test cases? Teach you a few tips to draft easily
Redis入门完整教程:RDB持久化
Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (filtering part)
ERROR: Could not find a version that satisfies the requirement xxxxx (from versions: none)解决办法
Matlb| economic scheduling with energy storage, opportunity constraints and robust optimization
[socket] ① overview of socket technology
What are the applications and benefits of MES management system
Derivative, partial derivative, directional derivative
Babbitt | metauniverse daily must read: is IP authorization the way to break the circle of NFT? What are the difficulties? How should holder choose the cooperation platform
Django database (SQLite) basic introductory tutorial