当前位置:网站首页>Room rate system - login optimization
Room rate system - login optimization
2022-07-07 03:11:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack
《 Personal edition of room charging system 》 Basically completed , mine U The code of layer is very, very messy . Basically D There are several functions in the layer ,B There are several functions in the layer ,U Layer use corresponding B Every function in the layer . For example, in login ,U Layer first uses a function check username And the user password Whether it is right , And then use “ Add user login record ” Function of . The following is the sequence diagram of login :
Login business is relatively simple , But for the complicated process of getting on the computer ?U The layer should check whether the card is registered . Whether the remaining amount is sufficient , Whether the status of the card is in use . Whether the card is not online now , After passing this series of tests , Also check the student table to display student information and so on .
This results in U Layer has many functions , and B The coupling degree of the layer is too large . Now let's think back and forth about the functions of each of the three layers :
The presentation layer (UI): Collect user input information and operations , Present specific business data to users . Generally speaking, it is user interface , That is, what a user sees and gets when using a system .
Business logic layer (BLL): Actions for detailed problems . It can also be said to be the operation of the data layer . Logical processing of data business . There are three main ways : from UI Get user instructions and data from , Run business logic ; from DAL Get data in , In order to offer UI Show ; from UI Get user instructions and data from , adopt DAL Write to data source .
Data access layer (DAL): The transactions of this layer directly operate the database , For the addition of data 、 Delete 、 changes 、 Search, etc. .
Under the guidance of the master , Changes have been made :
U layer :
' Sign in
Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
' Check empty
If PublicFunction.IsEmptyText(Me) = True Then
Exit Sub
End If
' Instanced entity User, quote B layer
Dim euser As New Entity.User
Dim euserRecord As New Entity.UserRecord
Dim blogin As New BLL.LoginBLL
Try
' Pass the information entered by the user to the entity
euser.ProuserID = txtUserID.Text.Trim
euser.ProuserPwd = txtUserPwd.Text
' Feedback information after user verification
If blogin.Check(euser, euserRecord) Then ' Login successful
''UserID and UserLevel Is a global variable , Other functions need to be used
UserID = euser.ProuserID.Trim ' Go to space
UserLevel = euser.ProuserLevel.Trim ' Go to space
' The main window shows
Me.Hide()
frmMain.Show()
Else
MsgBox(" Login failed !username or password Mistake .", vbExclamation, " System prompt ") txtUserID.Focus() Exit Sub End If Catch ex As Exception MsgBox(" error !", vbExclamation, " System prompt ") End Try End SubB layer :
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 and password Input correct
euser.ProuserID = dt.Rows(0).Item(0) ' user ID
euser.ProuserLevel = dt.Rows(0).Item(2) ' User level
' Enter the information recorded by the user on the computer
euserRecord.ProuserID = euser.ProuserID
euserRecord.ProuserLevel = euser.ProuserLevel
euserRecord.ProloginTime = Now
euserRecord.PrologoutTime = Now
euserRecord.ProisOnline = 1 '1 It means online .0 Means not online
euserRecord.Procomputer = My.Computer.Name ' Get the current computer username
' Add user login record
Dim result As Integer
result = iuser.AddUserRecord(euserRecord)
If result <> 0 Then ' Successfully joined the user record
Return True
End If
End If
Catch ex As Exception
Throw New Exception
End Try
End FunctionD layer :
' How to find users
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
' The user successfully logged in to UserRecord
Public Function AddUserRecord(euserRecord As Entity.UserRecord) As Integer Implements IUser.AddUserRecord
' When each field is filled , The contents in the preceding brackets can be omitted
'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 FunctionLogin sequence diagram after change :
The two login sequence diagrams form a sharp contrast , So the user clicks “ Sign in ”button after ,U The layer is responsible for collecting user input username and password, Then just call one Check() Function to verify .B Layer handles business logic . First infer user information , If the input is correct, proceed to the next step and add the user's computer record .D Layer and database . Add, delete, modify, etc .U The layer doesn't know the detailed authentication user details . This decouples , Attend to each one's own duties .
Summary : From the first computer room charging system last year . To today's personal version reconstruction . And the next cooperation reconstruction , Every step is a leap . At first we were purely process oriented , Now I have learned the three-tier architecture , Design patterns are used , But it is still very far away from object-oriented . We are moving forward step by step , This process is very important . It's like Tang Monk learning from the West , Suppose you can get the Sutra by turning the monkey king over . Then there will be no classic 《 Journey to the west 》 了 .
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116772.html Link to the original text :https://javaforall.cn
边栏推荐
- [socket] ① overview of socket technology
- 【基于 RT-Thread Studio的CPK-RA6M4 开发板环境搭建】
- Leetcode 77: combination
- Utilisation de la promesse dans es6
- A complete tutorial for getting started with redis: RDB persistence
- 巴比特 | 元宇宙每日必读:IP授权是NFT的破圈之路吗?它的难点在哪里?Holder该如何选择合作平台?...
- [secretly kill little partner pytorch20 days] - [Day1] - [example of structured data modeling process]
- Redis入门完整教程:RDB持久化
- 杰理之播内置 flash 提示音控制播放暂停【篇】
- Use of promise in ES6
猜你喜欢

Redis Getting started tutoriel complet: positionnement et optimisation des problèmes

Detailed explanation of 19 dimensional integrated navigation module sinsgps in psins (time synchronization part)

Centerx: open centernet in the way of socialism with Chinese characteristics

The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?

Qt蓝牙:QBluetoothDeviceInfo

Use of promise in ES6

Development of wireless communication technology, cv5200 long-distance WiFi module, UAV WiFi image transmission application

Redis getting started complete tutorial: replication configuration

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

How to write test cases for test coupons?
随机推荐
cocos3——8. Implementation Guide for beginners
左程云 递归+动态规划
[software test] the most complete interview questions and answers. I'm familiar with the full text. If I don't win the offer, I'll lose
应用程序启动速度的优化
Optimization of application startup speed
首届“量子计算+金融科技应用”研讨会在京成功举办
How does C language (string) delete a specified character in a string?
Starting from 1.5, build a micro Service Framework -- log tracking traceid
Shell 编程基础
opencv环境的搭建,并打开一个本地PC摄像头。
商城商品的知识图谱构建
How to verify accesstoken in oauth2 protocol
Change your posture to do operation and maintenance! GOPs 2022 Shenzhen station highlights first!
Redis入门完整教程:RDB持久化
Analysis of USB network card sending and receiving data
杰理之FM 模式单声道或立体声选择设置【篇】
leetcode-02(链表题)
A complete tutorial for getting started with redis: RDB persistence
杰理之RTC 时钟开发【篇】
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?