Data room Charging System Reconstruction-User Login

Source: Internet
Author: User
Tags boolean table

The Charging System of the IDC room has started for a while, but I feel that I still don't have a deep understanding of this line, which makes it difficult to log on later. So I will analyze the user login process.

If it is a pure Layer 3, it is similar to understanding, it is nothing more than transfer between the layer and layer, but with the user demand, more and more software functions, then the complexity is growing.


Therefore, we have introduced more layers. We think this is more complicated than the three layers, but we will reflect the advantages of high cohesion and low coupling in the implementation process. It is not hard to find that this has evolved from adding a three-layer design model. The abstract factory model is designed for the convenience of Database Change, the application appearance mode is used to solve the problem of high coupling between the UI Layer and the BLL layer. The UI Layer does not need to know the existence of The bll layer, and the facade knows which classes of The bll layer are responsible for which requests, proxy the request at the UI Layer to the appropriate BLL layer class.

I. abstract classes

As a whole, the next step is the details, from the macro to the micro.

1. abstract object class

The first step is to abstract the entity layer class (Entity). Because the information system operates and processes data, data must first be available. At this time, we need to return the requirement, understand the data requirements of users and design databases based on these requirements. Here we need to abstract the userentity class.

Public Class UserEntity    Private _userName As String    Private _PWD As String    Private _userLevel As String    Private _accounter As String    Public Shared UserHead As String    Public Property userName() As String        Get            Return _userName        End Get        Set(value As String)            _userName = value        End Set    End Property    Public Property PWD() As String        Get            Return _PWD        End Get        Set(value As String)            _PWD = value        End Set    End Property    Public Property userLevel() As String        Get            Return _userLevel        End Get        Set(value As String)            _userLevel = value        End Set    End Property    Public Property accounter() As String        Get            Return _accounter        End Get        Set(value As String)            _accounter = value        End Set    End PropertyEnd Class

2. The U layer of the UI Layer is responsible for data input and output. It first determines the requirements of the input data, and then calls the method of verifying the user and password after the requirements are met.

Imports bllimports entitypublic class frmloginui private sub btok_click (sender as object, e as eventargs) handles btok. click dim enuser as new entity. userentity 'dim loginfa as facade. loginfacade 'instance': enuser. username = txtuser. text. trim' value assignment process enuser. pwd = txtpwd. text. trim 'dim strresult as string' determines whether the user name and password are entered if txtuser. text. trim () = "" Then MessageBox. show ("Enter the user ID", "", messageboxbuttons. OK, messageboxicon. exclamation) txtuser. select () txtuser. focus () Exit sub elseif isnumeric (txtuser. text) = false then msgbox ("enter a number as the user name") txtuser. TEXT = "" txtuser. select () txtuser. focus () Exit sub elseif txtpwd. text. trim () = "" Then MessageBox. show ("Enter Password", "", messageboxbuttons. OK, messageboxicon. exclamation) txtpwd. select () txtpwd. focus () Exit sub end if 'try' defines the object dim facadelogin as new facade of the appearance layer. loginfacade dim strresult1 as Boolean strresult1 = facadelogin. checkuser (enuser) If strresult1 = false then msgbox ("user does not exist") txtuser. TEXT = "" txtuser. select () txtuser. focus () end if Dim table as datatable table = facadelogin. checkpwd (enuser) If trim (txtpwd. text) = trim (table. rows (0 ). item (1) Then msgbox ("Login successful") me. hide () frmmainui. show () else msgbox ("Incorrect password") txtpwd. TEXT = "" txtpwd. select () txtpwd. focus () end if end sub private sub btcancel_click (sender as object, e as eventargs) handles btcancel. click end sub private sub frmloginui_load (sender as object, e as eventargs) handles mybase. load txtuser. select () txtuser. focus () end subend class

3. Appearance Layer

The appearance is actually the encapsulation of the method, but it does not play a significant role in the appearance layer login, but it also calls the B layer method.

Imports bllpublic class loginfacade public function checkuser (byval enuser as entity. userentity) as Boolean 'is used to check whether the user has dim isuserexistsbll as new BLL. isexists dim flag as Boolean flag = isuserexistsbll. isuserexists (enuser) If flag = true then return true else return false end if end function' check whether the user is correct public function checkpwd (byval enuser as entity. userentity) as datatable dim ispwdbll as new BLL. isexists dim table as datatable table = ispwdbll. checkuserpwd (enuser) return table end functionend class

4. the bll layer verifies whether the user exists and the password is correct. The verification method is performed through the factory and idal interfaces. First, the factory is instantiated, the interface variables are defined, and the methods in the factory are called, then perform logical judgment on the returned data

Imports idalimports entitypublic class isexists 'check whether the user has public function isuserexists (byval enuser as entity. userentity) as Boolean 'defines and instantiates a factory dim factory as new factory. dataaccess' defines an interface variable dim iuser as iuser 'by calling the create user's factory method iuser = factory. createuser dim table as datatable dim flag as Boolean table = iuser. checkexistsuser (enuser) If table. rows. count = 0 then flag = false else flag = true end if return flag end function 'check whether the password is correct public function checkuserpwd (byval enuser as userentity) as datatable dim factory as new factory. dataaccess' defines the factory and instantiates the factory variable factory dim iuser as iuser'. It defines the intermediate variable of the interface variable iuser dim table as able. It is used to store the data iuser = factory queried by layer D. createuser' call the createuser method of the factory to create an iuser interface instance table = iuser. checkexistsuser (enuser) 'calls the interface method userisexist and returns the returned value to the flag return table end functionend class

5. Factory

The classic factory layer design uses reflection + configuration files to prevent database replacement.

Imports system. reflectionimports system. configurationimports idal '/************************************ **************************************** 'Class Name: sqlserverfactory 'namespace: factory 'content: Read the configuration file to assign values to the DB string. In the configuration file, specify whether it is sqlserver or access, you only need to change the configuration file for the data library. The premise is that the Dal layer class with the SQL Server prefix writes the code for accessing the SQL Server database. The 'Access prefix' Dal layer class writes the code for accessing the ACCESS database. 'Function: Use reflection + configuration file + abstract factory to easily replace the database' Creation Time: 10:40:59 'Author: Wang jinbo' modification time: 'modifier: 'version No: v1.0.0 '************************************** * ***********************************/Public class dataaccess' uses reflection + configuration file + Abstract Factory private shared readonly assemblyname as string = "Dal" 'to define Assembly name variables, the name of the D-layer namespace is private shared readonly dB as string = configurationmanager. appsettings ("DB") 'indicates reading the configuration file. If the configuration file is sqlserver, access the sqlserver database. If You can access other resources without changing the code in the program. 'Factory public function createuser () as iuser dim classname as string = assemblyname + ". "+ dB +" userdal "'assemblyname is the Assembly name, and DB +" userdal "is sqlserveruserdal In the Dal layer. If you do not need an sqlserver database, I will create another class in 'factory. For example, if you access the ACCESS database, the class name is accessuserdal. Change the value in the configuration file to 'access. This is the extension, not modification. Dim iuser as iuser = ctype (assembly. load (assemblyname ). createinstance (classname), iuser) 'converts the instantiated layer d to an interface class through the upward transformation, then, call the function in the interface class to call the function return iuser end functionend class that implements the interface in layer D.

6. Interface Layer

Define an interface for decoupling layer B and layer d

Public interface iuser' check whether the user exists and the password is correct function checkexistsuser (byval enuser as entity. userentity) as datatableend Interface

7. Dal Layer

Used to connect to the database and implement interfaces

Imports entityimports idalimports system. data. sqlclientpublic class sqlserveruserdal: Implements iuser public function selectexistsuser (enuser as userentity) as datatable implements iuser. checkexistsuser dim SQL as string 'defines the string variable SQL, which is used to store the SQL statement dim table as able' to define the table variable table, stores execution results and returns dim paras as sqlparameter () = {New sqlparameter ("@ username", enuser. username), new sqlparameter ("@ PWD", enuser. PWD)} SQL = "select * From t_user where [email protected] and [email protected]" 'storage SQL statement table = sqlhelper. sqlhelper. getdatatable (SQL, commandtype. text, paras) 'executes the SQL statement and assigns the result to table return table end functionend class
In short, we try our best to comply with the single responsibility principle. A Class completes a function with high cohesion and low coupling, making the connections between each layer very small, the use of the design model makes our ideas clearer and makes the system better scalable and maintained.

Data room Charging System Reconstruction-User Login

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.