Three layer has learned some time, began to think that they can use C # to hit the code, the C # to write a realization landing, and really used in the engine room. Still think it's very exhausting, so. decided to knock with the vb.net. Here is the landing I realized with vb.net. can give you some references.
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1bxv4awewotix/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
This is the three-story structure.
Table T_user_dal:useri in the database. Level,password,head,computer
First Look at
Entity layer:
Public Class userinfoentity#region "define variable" private _userid as String private _level as String private _head as Str ing Private _password as string#end region Public Property UserID () as String to pass each entity in the T_user_dal table, the entity is Built on a table, not function Get Return _userid End get Set (value as String) _userid = value End Set End property, level () as String get Return _level End get Set (ByVal value As String) _level = value End Set End Property Public Property Head () As String Get Return _head End Get Set (value as String) _head = value End Set En D Property Password () as String Get Return _password End get Set (value As String) _password = value End Set End Propertyend Class
DAL layer:
in order to reduce the coupling, be sure to take the connection string out. Don't write one side of each dal.
Imports system.dataimports System.Data.SqlClientPublic Class sqlutil public Shared Function connstring () as string< c4/> ' connstring = "server=192.168.24.183;database=reconsitutioncharge_sys; User Id=sa; password=123456 " ' will appear unrecognized userid error connstring =" SERVER=MX; Database=reconsitutioncharge_sys; User Id=sa; password=123456 " ' string connected to SQL End functionend Class
T_user_dal table DAL Layer code:
Imports System.Data.SqlClientImports system.datapublic Class userdal public Function selectuser (ByVal user as entity.us Erinfoentity) as Entity.userinfoentity Dim conn As New SqlConnection ' definition connection Open database Dim cmd as New SqlCommand ' define DATABASE Command conn = new SqlConnection (sqlutil.connstring ()) ' Instantiates the string cmd returned in Sqluntil. Connection = conn cmd. CommandText = "Select * from T_user_dal Where [email protected] and [email protected]" stored procedure CMD.P Arameters. ADD (New SqlParameter ("@UserID", user. UserID)) ' Assignment, cmd. Parameters.Add (New SqlParameter ("@Password", user. Password)) cmd. CommandType = CommandType.Text ' CommandText property is set to the name of the stored procedure. When one of the Execute methods is called, the command runs this stored procedure conn. Open () ' Turn on the connection Dim reader as Sqlclient.sqldat Areader ' Read the table in the database, reader = cmd. ExecuteReader () Dim users as New entity.userinfoentity ' materialized entity W Hile (reader. Read ()) ' If users are nothing and then ' user = New entity.userinfoentity ' End If Users. UserID = reader. GetString (reader. GetOrdinal ("UserID")) users. Password = reader. GetString (reader. GetOrdinal ("Password")) END while Conn. Close () Return users End functionend Class
BLL Layer:
Public Class LOGINBLL Function userlogin (ByVal user as entity.userinfoentity) as Entity.userinfoentity Dim Udal As New DAL. Userdal ' instantiated the Userdal Dim in the Dal users as New entity.userinfoentity ' instantiated the Entity Layer Information table users = Udal.selectuser (user) ' Selectuser is returning an entity class, assigning it a value of user return users ' return to the users entity End FunctionEnd Class
UI layer:
Interface design:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwl1bxv4awewotix/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
Private Sub Btnlogin_click (sender as Object, e as EventArgs) Handles Btnlogin.click Dim Mgr as New BLL. LOGINBLL ' Instance business layer Dim user As New entity.userinfoentity ' instance entity Dim users As Entity.userinfoentity ' Receive entity, which is used to receive the data type returned by Userlogin (), assuming that no new is an instantiation of the user. UserID = TxtUserID.Text.Trim () ' passes the value user to the entity layer. Password = TxtPassword.Text.Trim () If Txtuserid.text = "Then ' infers whether the input is correct MsgBox (" username cannot be Empty! ") Return End if txtPassword.Text =" then MsgBox ("Password cannot be empty! ") Return End If Try ' users receive entity users = Mgr. Userlogin (user) If (users. UserID is nothing and users. Password is nothing) Then ' assumes that the users are not empty. The landing was successful! MsgBox ("Login failed, username and password do not match") Return Else MsgBox ("Login succeeded. Login User: "+ user. UserID) End If Catch ex as Exception MsgBox (ex. Message ()) End Try End SubEnd Class
Vb. NET version + three-tier implementation login