Data room charging system-Logon Optimization

Source: Internet
Author: User

The personal version of the data room toll system is basically completed, and my U-Layer Code is messy. Basically, the D layer has several functions, and the B layer should have several functions. The U layer uses each function corresponding to the B layer. For example, during login, the U layer uses a function for the first time to check whether the user name and password are correct, and then uses the function "Add User records on the machine. The following figure shows the logon sequence:

Logon is relatively simple, but what about complicated computer processes? On the U layer, you must check whether the card is registered, whether the balance is sufficient, whether the card is in use, and whether the card is not online. After this series of tests, you must query the student table to display the student information. In this way, the U layer has many functions, and the coupling degree with the B layer is too large. Now let's review the functions of the layers in Layer 3:

 Presentation layer (UI): Collect User input information and operations to show specific business data to users. In general, it is the user interface, that is, what a user sees when using a system.

 Business logic layer (BLL): Operations for specific problems can also be called operations on the data layer and data business logic. There are three main methods: Getting user instructions and data from the UI and executing business logic; getting data from the Dal for UI display; getting user instructions and data from the UI, write Data sources through Dal.

 Data access layer (DAL): The transactions made at this layer directly operate on the database, and add, delete, modify, and search data.

Under the guidance of the master, he made the following changes:

U layer:

'Log On to private sub btnlogin_click (sender as object, e as eventargs) handles btnlogin. click 'to query if publicfunction. isemptytext (me) = true then exit sub end if 'instantiate the Object User and reference layer B dim euser as new entity. user dim euserrecord as new entity. userrecord dim blogin as new BLL. loginbll try 'transmits user input information to the entity euser. prouserid = txtuserid. text. trim euser. prouserpwd = txtuserpwd. text 'user feedback after verification if blogin. check (euser, euser Record) then'logon successful ''' userid and userlevel are global variables. Other functions require userid = euser. prouserid. trim' to space userlevel = euser. prouserlevel. trim' to the space 'main form to display me. hide () frmmain. show () else msgbox ("Logon Failed! The user name or password is incorrect. ", Vbexclamation," system prompt ") txtuserid. Focus () Exit sub end if catch ex as exception msgbox (" error! ", Vbexclamation," system prompt ") end try end sub
Layer B:

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 'user name and password enter the correct euser. prouserid = DT. rows (0 ). item (0) 'user ID euser. prouserlevel = DT. rows (0 ). item (2) 'user level' enter the user's computer record information euserrecord. prouserid = euser. prouserid euserrecord. prouserlevel = euser. prouserlevel euserrecord. prologintime = now euserrecord. prologouttime = now euserrecord. proisonline = 1' 1 indicates online, 0 indicates offline euserrecord. procomputer = My. computer. name 'get username' Add User computer record dim result as integer result = iuser. adduserrecord (euserrecord) If result <> 0 then' added user record success return true end if catch ex as exception throw new exception end try end Function

Layer D:

'Method for searching 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 'user login successful add record to userrecord public function adduserrecord (euserrecord as entity. userrecord) as integer implements iuser. when adduserrecord is entered for each field, the content in the brackets '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
The modified logon sequence diagram is as follows:



The two logon sequence diagrams are in stark contrast. After a user clicks the "Log on" button, the U layer collects the user name and password entered by the user, and then calls a check () function for verification. Layer B processes the business logic and first determines the user information. If the input is correct, the next step is to add the user's host record. Layer D deals with databases for addition, deletion, modification, and query. The U layer does not know the specific verification user details, so it decouples and performs their respective duties.

Summary: from the first data center charging system last year, to the current individual version reconstruction, and the subsequent restructuring of cooperation, each step has crossed. Initially we were purely process-oriented. Now we have learned the three-tier architecture and used the design model, but it is still far away from object-oriented. We are moving forward step by step. This process is very important. For example, if Sun Wukong is able to get the classics by turning around his head, there will be no classic Journey to the West.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.