What did you learn about VB. NET (2)

Source: Internet
Author: User


Next, I will describe the UML diagram in the previous article. Today, let's take a look at the three-tier architecture I learned in VB. NET <personal restructuring of the IDC billing system>.


1. UML diagram 2, three-layer structure 3, sqlhelper 4, Configuration File 5, interface 6, design mode


In fact, the learning of the three-tier structure takes a long time. The reason is not the content of my three-tier architecture, but that I will not function. Familiar with mathematical functions, such as Y = f (x), Y = SiN x, and y = cos X, some functions can be directly used as defined by humans. But I can't figure out the functions on the computer, so I started from the keywords, modifiers, parameters, return values, and so on and began to know the basic structure of the functions, how to write and call functions, returned value .... after figuring out the function, I started to study the three-tier login example. After the three-tier login example is completed, I started to write the registration example on this basis. All in all, the delay is long and tangled. I don't know anything from the beginning. In the state of chaos, we can gradually clarify what each layer puts, what each layer needs, and which layer to adjust. The basic process of writing code is to write the code from the u layer first, and then write the code to the B layer when calling the B layer function. The B layer has not been written yet, layer B needs to call the things of layer D, So it turns to layer D again until all the content of layer D is perfect, and then it returns back to supplement the content of layer B, return to the U layer to improve the content of the U layer. In short, the write process is a process of inverse turning. That is to say, the understanding of the previous functions and the understanding of the three layers can be a good way to find out the data center charging system under the three-layer structure. When you knock on it, you will find that the logic can be clarified, know what each layer needs and what each layer returns.

This is a layer-3 code -- u Layer

Public class formui' OK button private sub btnok_click (byval sender as system. object, byval e as system. eventargs) handles btnok. click' defines an object class object and assigns the content in the text box to the object class Object dim user as model. classmodel 'defines an object class Object User = new model. classmodel 'instantiate this object user. user_name = txtuserid. text. tostring () user. user_pwd = txtuserpwd. text. tostring () 'defines a business logic layer object, and notifies the user of the information dim UB as BLL based on the results returned by the business logic layer. classbll = new BLL. classbll dim res Ult as boolean result = ub. query_user (User) If result then 'if true is returned, the message box. Show ("congratulations, login successful! "," Message prompt ", messageboxbuttons. OK, messageboxicon. Information) else '; otherwise, MessageBox. Show (" sorry, login failed! Please verify and re-log on to 1 "," message prompt ", messageboxbuttons. OK, messageboxicon. warning) 'clear the TXT userid in the text box. TEXT = "" txtuserpwd. TEXT = "" end if end Sub "cancel the private sub btncancel_click (byval sender as system. object, byval e as system. eventargs) handles btncancel. click end subend class

Layer B

Public class classbll 'This function is used to return the execution result of layer D public function query_user (byval thisuser as model. classmodel) as Boolean 'defines a D-layer object dim dB as Dal. classdal = new Dal. classdal dim A as Boolean 'Call the D-layer function a = dB. query_user (thisuser) return a end functionend class

Layer d

Imports system. data. sqlclientpublic class classdal database connection statement dim conn as sqlclient. sqlconnection dim STR as string = "Server = .; database = sancengtest; Integrated Security = sspi "'you do not need a user name or password to log on to my database. The following statement logs on to the database using the user name and password 'dim STR as string = "Data Source = localhost; initial catalog = sancengtest; persist Security info = true; user id = sa; password = 123456 "'data source is the server name, and Data Source = localhost indicates that the server is the local machine. 'initial catalog is the database name, 'persist Security info = true simple understanding is that ADO saves the password information after the database connection is successful, true is saved, false is not saved public sub new () 'constructor, establish a connection, open Database conn = new sqlclient. sqlconnection Conn. connectionstring = STR Conn. open () end sub 'queries whether the user in the database has the public function query_user (byval thisuser as model. classmodel) as Boolean 'database query statement dim sqlstr as string sqlstr = "select * From usertable where user_id = '" & thisuser. user_name & "'and user_pwd ='" & thisuser. user_pwd & "'"' queries dim sqlcmd as sqlclient. sqlcommand = new sqlclient. sqlcommand (sqlstr, Conn) dim reader as sqldatareader 'defines a reader to read data reader = sqlcmd. executereader () 'runs your query and returns the reader if reader. read () then' returns true else return falseif the queried data return true'; otherwise, false end if end functionend class is returned.

Because the code was first typed at the beginning of the exercise, the naming is not standard, and sqlhelper is not used, there are many problems, just come out and learn from everyone, because there is such a learning process, from completely ignorant to getting started, so the Code does not have the meaning of standard reference and solution, I hope you will understand. I also hope to see what I used to do and help you with personal restructuring.

In the next article, I want to introduce sqlhelper learned in VB. NET <IDC charging system personal reconstruction edition>.

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.