Some time ago, the form login function was implemented with a simple layer-3 interface, and I felt a little sense of accomplishment in my mind. However, the system was soon flooded with cold water, and it was impossible to use only three layers for Data Center charges. If you use three layers, that is to say, all functions of the following data room charges must be implemented using three layers. So we started a layer-7 study a week ago. After reading the blog, summing up, and debugging the code for a week, I finally realized the form login, information entry, and simple recharge query functions.
Let's talk about my summary of this layer-7 Tour.
1. without a doubt, to study a form function, I first determine which tables in the database are needed (this is my own programming habit and not applicable to all ), then, the fields in the table are displayed in the Object layer, and the object classes will only be larger than the number of tables! A table maps an object class. Fields in the table are attributes of the object class! Here is a part of your code!
Public class loginmodel private _ userid as string private _ level as string private _ password as string private _ username as string private _ computer as string public shared userhead as string 'sets the global variable public shared userlevel. as string public property userid () as string get return _ userid end get set (value as string) _ userid = value end set end property public property password () as string get return _ password end get set (value as string) _ password = value end set end property public property level () as string get return _ level end get set (value as string) _ Level = value end set end property public property username () as string get return _ username end get set (value as string) _ username = value end set end property public property computer () as string get return _ computer end get set (value as string) _ computer = value end set end propertyend class
2. Next we will introduce the factory + reflection + Interface + Dal.
This process involves a lot of things. Let me give a general description of what I have used in this part!
(1) Use reflection + Abstract Factory Data Access Programs
I thought it was a new knowledge, but you can look at our design patterns. In the abstract factory chapter, we talked about reflection using strings to instantiate objects, and variables can be changed!
Remember a simple piece of code:
Assmbly. Load ("assembly name"). creadteinstance ("namespace. Class Name") I understand this section as the process of creating interfaces.
There will be a special blog on this part!
This error often occurs during factory knock:
This error occurs and I checked my blog. Now I only want to show my own method. Change the output path generated in the Dal file to the output path generated by the UI. For this error, there are many detailed blog introductions. I won't say much about it.
(2) Next I began to understand the relationship between the factory, the interface and the Dal. Factory reflection is to prevent the database from being replaced, and then the factory is actually the production interface, generate an interface for the classes in the Dal, and then call the interface in the Dal to implement the interface.
The addition, deletion, modification, and query of databases in dal are repeated. Here we abstract a class of sqlhelper. What we learn is object-oriented, that is, learning to use object-oriented thinking, for more information about sqlhelper, see the blog.
I wrote the sqlhelper class below the Dal, and the subsequent code will become simple, that is, declaration, instantiation, and application of the return value. A small part of code is attached:
<strong><span style="font-size:18px;"> Public Function RechargeQuery(cardno As Model.RechargeModel) As Model.RechargeModel Implements IDAL.IRecharge.RechargeQuery Dim sqlparams As SqlParameter() = {New SqlParameter("@CardNo", cardno.StuInfoQuery)} Dim strText As String = "select * from T_StuInfo where CardNo [email protected]" Dim helper As New SqlHelper Dim cmdtype As CommandType = New CommandType() cmdtype = CommandType.Text Dim table As DataTable Dim Ucardno As New Model.RechargeModel table = helper.ExecuteQuery(strText, cmdtype, sqlparams) If table.Rows.Count <> 0 Then Ucardno.StuInfoQuery = table.Rows(0).Item("CardNo") End If Return Ucardno End Function</span></strong>
In fact, there will be an introduction to stored procedures in this part, but we will not introduce the impact of space.
This article is purely my personal understanding. If you have any wrong understanding, you are welcome to take a look!
Next, I will introduce you to BLL and the appearance layer.