Three-tier architecture in the actual combat chapter

Source: Internet
Author: User

On the blog we have a certain understanding of the three-tier architecture, but the light said not practice fake, like standing on the shore to learn to swim, do not water you will never learn, programming is the same.

We want to do is a small example of system login, the requirement is to enter user name and password, click Login, System prompts login success. The IDE used in this example is VS2012, the database used is SQL Server2008, and the language used is C #.

As an example, you follow the video step-by-step, so people knock wrong where, you also knock wrong where, people change where you also follow to change where, this feeling very uncomfortable, so in summary, think from macroscopic to microscopic order more appropriate, this is the software engineering so-called first outline design, then detailed design ideas.

Since it is the practice of the three-tier architecture, so first build the hierarchy: Click on a new project, build a Windows Forms application, obviously it's something on the U layer, then right-click the solution, add a new project, add three class library types to this solution, respectively, the D-tier, B and E (Entity layer, the data model), after completion, as shown in the following figure:

With the basic structure of layer three, you add classes and references to each layer. Depending on the dependencies, the three tiers are dependent on the entity layer, so the reference Loginmodel is added to each layer's reference, and then the BLL layer is added to the UI layer based on the Ui->bll->dal dependencies, and the BLL layer references the DAL layer. Finally, according to their own design, add the corresponding classes for each layer, as shown in the following figure:

Here a brief description of what each class is doing, from top to bottom, BLL Loginmanager class is responsible for login management, call the DAL layer function, to determine whether login success and related business processing, etc. the Dbutil class of the DAL is a connection string, To get it out alone is to improve reusability, while the Scoredao class is responsible for writing data to the database, and the Userdao class is only responsible for logging in to the connection database, which seems to be the single responsibility of the design pattern. The UserInfo class of the Loginmodel layer is a data entity, in order to facilitate communication between three layers. The final u layer is to write the button click event, the specific code you can write out, I will not repeat.

Below I share the debugging process encountered problems and solutions:

At first you didn't find the error, and you clicked "Get general Help for this exception" below.

Still failed to find, and later, according to the error prompted "near the value of syntax error", think is definitely the key word value of the problem, and found the wrong place

Then, the program runs perfectly, and then I look at other people's connection string in the parameter server values are IP, they also replaced the IP address, however, the run times are wrong as follows:


See the word memory is damaged, feel so serious? So went to find the Niang asked, degrees Niang said: It is a piece of cake.

Run cmd:netsh Winsock reset enter with administrator status. For specific reasons, we can access the relevant information, limited to space, no longer delve into.

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.