First Contact three layers
- Layer three refers to the display layer, the business logic layer, the data access layer, is for "high cohesion, low coupling" service
- In addition to the above three layers, a program must have a physical layer, I understand that entities in the entity layer is relative to the table in the database, and the entity's properties are relative to the fields in the data table, you can also join the appearance layer, data interface, abstract factory layer, which are something, to be added according to the needs of the program. Just like we're going to do today. This does not need the appearance, data interface, abstract factory, in fact, even the business logic layer can also be omitted, because there is no logical operation.
- The display layer references the business logic layer, the business logic layer references the data access layer, and layer three can reference the entity layer as needed.
- At first the small example of knocking on the landing, made a small mistake, is
- It took me a whole night, and it took me half an hour next to the great God, but it was fruitless. Just as I was going to be discouraged and tongue to commit suicide, I suddenly noticed:
- Q: What is the relationship between these four projects in Solution Manager? The answer is: they are four different assemblies that belong to the solution, but they can also be added by adding existing projects by other solutions. (Invb.net, whether it is a solution, an assembly, a class, a form, is not added before it is called a project)
- an existing project that is added by right-clicking a solution is an assembly.
- An existing project added by right-clicking an assembly is a class or form.
- Click on the menu bar file- >- New project or open project is solution
- do you know I made a mistake? I knew you didn't see it, and the mistake I made was that I changed the name of the four assemblies to LogIn, so the above error occurred.
- Now look at my code, we must understand the beginning of the "First Contact" written three words, write such code is very good, we do not abandon.
Display Layer
Imports login.bllimports login.modelpublic Class frmlogin public Sub Btnlogin_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btnlogin.click Dim admininfo As Admininfoentity Dim manager As New Adminbll
dim _name As String Dim _password As String _name = txtadminname.text _password = Txtadminpwd.text Admininfo = Manager.selectadmin_info (_name, _password) ' calls the logical layer, the returned admininfo may be empty, or it may not be empty If admininfo is anything then MessageBox.Show ("Login Failed") Else MessageBox.Show ("Login user" + Admininfo. Name) End If End Sub Private Sub btncancel_click (ByVal sender as System.Object, ByVal e as System.eventarg s) Handles Btncancel.click me.close () End subend Class
Business Logic Layer
Imports login.modelimports login.dalpublic Class adminbll Dim admininfo As Admininfoentity Dim admindal As New Ad Mindal ' Verify that the user logon information is correct public Function selectadmin_info (ByVal name as String, ByVal password as String) as Admininf oentity admininfo = admindal.getadmininfo (name, password) ' calls the data access layer, the returned admininfo may be empty, or it may not be empty return Admininfo End FunctionEnd Class
Data Access Layer
Imports System.Data.SqlClientImports system.dataimports System.Data.OleDbImports systempublic Class Connectiontodb Public Function Connectiontodb () as SqlConnection Dim con as New SqlConnection ("Data source= Liu Ying-pc;initial catalog=room_charge_system; User id=sa;password=123456 ") ' Connection to database con. Open () Return con End functionend Class
Imports systemimports system.dataimports System.Data.OleDbImports System.Data.SqlClientImports login.modelpublic Class Admindal Dim admininfo As Admininfoentity Dim con As New connectiontodb ' Get user information public Function getadmin Info (ByVal name as String, ByVal password as String) as Admininfoentity ' records in table Dim cmd as New SqlCommand ("s Elect*from t_admin_info where name= "&" "& Name &" "&" and password= "&" "& Password &" ' ", con. Connectiontodb ()) Dim reader as SqlDataReader reader = cmd. ExecuteReader () while (reader. Read ()) ' If the data table has a record of the user name and password that correspond to the text box, use the NEW keyword to call the Admininfoentity constructor, make Admininfo not empty, and assign a value to its property Admininfo = New Admininf Oentity admininfo.id = reader. GetString (0) admininfo.name = reader. GetString (1) admininfo.level = reader. GetString (2) Admininfo.password = reader. GetString (3) End while Return admininfo End functionend ClassPhysical Layer
' User classes, which provide public properties that other classes can invoke, as well as fields that are called by members of the class, and other classes can restrict the unconditional operation of the field through attributes such as read-only, write-only, and scoped assignments. Public Class admininfoentity Dim _name As String public property name () As String Get Return _name End Get Set (ByVal value as String) _name = value End Set End Property Dim _id as St Ring Public Property ID () As String get Return _id End Get Set (ByVal value As String) _id = value End Set End Property Dim _level As String public property level () As String G ET Return _level end Get Set (ByVal value as String) _level = value End Set E nd property Dim _password As String public property password () As String Get Return _password End Get Set (ByVal value as String) _password = value End Set End Propertyend Class