) Layer-3 cases (and Common Errors)

Source: Internet
Author: User
Tags what sql

Address: http://www.cnblogs.com/zysbk/archive/2012/10/16/2726895.html

 

Layer-3 cases (and Common Errors)

Today, we will lead you to learn the three layers of knowledge, because the three layers of content are widely used in our work. therefore, I will repeat the logon password verification questions. the question does not show whether the user exists.

Let's review the two figures we showed you last time:

Layer 1 and Layer 3 Architecture

2. flowchart of two cases

Today we have created three projects, so that we can see the three layers.

3. Build the Interface Layer

4. Three Layers

Sqlhelper is used to operate databases. It is related to databases at the data access layer. Add a reference.

We put the configuration file in the data access layer first. Modify the information in the configuration file.

Next we will first draw the interface at the interface layer.

5. Draw the Interface Layer

Let's review the following steps:

    1. Analyze SQL statements as needed

Selectcount (*) fromt_seatswherecc_loginid = @ uidandcc_loginpassword = @ pwd

After the logon is successful, the welcome XXX is displayed at the top of the form, and the logon primary key ID must be remembered.

Check the primary key ID and real name.

Selectcc_autoid, cc_usernamefromt_seatswherecc_loginid = @ uidandcc_loginpassword = @ pwd

2. Data access layer

How do I call the first SQL statement?

How does one call the second SQL statement?

Determine the class at the data access layer.

6. verify whether the logon is successfulCode

7. Write a model

8. Write the data access layer code

3. Determine the BLL business logic layer

9. Create classes, add references, and write MD5.

10. Write the business logic layer

11. Add two references and write the classes and code for storing data.

12. Write the code at the interface layer.

DebuggingErrorLet's take a look at what went wrong?

It indicates that an error occurred while reading the string in sqlhelper.

The configuration file may be a problem.

We put the configuration file on the data access layer just now. Why cannot it be placed on the data access layer?

13. System Error Reporting and modification ideas

In addition, if you do not want to make a bunch of logic judgments on the interface layer, encapsulate the logic judgments we just wrote in it into a method.

Determine BLL business logic layer: Determine several methods as required, as well as parameters and return values of each method.

14. display the user name successfully logged on to the upper left corner of the window.

Next, let's change the password, which is similar to the user's logon logic. It also determines the SQL statements, data access layer, business logic layer, and write the interface layer.

15. Password Change Interface Layer 1

16. Password modification Interface Layer 2

17. The password change button is displayed and the second form is displayed.

Now we want to change the password. What SQL statements do we use?

One is: Determine whether the old password is correct.

One is: Change the new password.

// Verify the SQL statement of the old password

Select count (*) from t_seats where cc_autoid = @ autoid and

Cc_loginpassword = @ oldpwd

// Change the password

Update t_seats set cc_loginpassword = @ newpwd where cc_autold = @ autold

With these two SQL statements, we should write the two methods at the data access layer.

18. Verify the old password and change the data access layer code

After writing the data access layer, We will rewrite the business logic layer. The method of business logic layer depends on the current needs.

Verify that the new password is consistent, and that the old password is correct and that the change is successful. Encapsulate a method and return different values as required.

19. Write the business logic layer

Next we will call it at the interface layer.

20. Finally, write the code at the interface layer.

21. VerificationProgram

Next let's talk aboutPerform recursive loading and recursive deletion with three layers

For convenience, I still build it in the same application.

It is still a three-tier step. What SQL statements are required for Recursive loading.

Obtain the sub-category based on the parent ID, and then write the data access layer.

Create a separate table

22. Preparations for Recursive Loading

23. Model class for data storage

Twenty-four methods at the data access layer

This database operation method is used for Recursive loading. Next, write the business logic layer method. At this time, the business logic layer does not have any logic processing work, that is, it just gets the data, that is, it is soy sauce.

Method 25: recursive Loading

26. tightly coupled approach for the business logic layer

27. Write recursive loading to the business logic layer

. Finally, change the configuration file and startup form

29. Demonstration of recursive Loading results

Can this be done? Suitable or not?

Not suitable. Why? Classes in the form are used at the business logic layer. After I change the interface to Web, this is not what is used in the business logic layer.

This logic should be written to the interface layer as the interface layer logic.

The above statement is specifically written for Windows Forms, tightly coupled.

If it is a string, it is loosely coupled. Because any program has one.

Code at the Interface Layer

Next we will delete the node, which is an extremely sub-node:

You still need to think about the SQL statement that will be executed after I click the button.

Write the data access layer first:

Delete-data access layer code

Delete-business logic layer code

33. Delete-Interface Layer

. How To Get The bll Layer

Author's recentArticleList:
C # basic tutorial (free of charge, the best gift for code lovers. Note: The authors share their carefully organized basic C # tutorials without any commercial purposes.
I hope to share my experiences with more code lovers. Please give me more advice !!!)
Layer 3 Layer 3 (1)
SQL database ado.net Database Application diagram 1
Database Application details 2
Ado. Net (connotation efficiency problem)
Process-oriented, object-oriented, and advanced Process-oriented, object-oriented in-depth understanding 1
Process-oriented, object-oriented in-depth understanding 2
Object-oriented deep understanding 3
Winform Basics Winform Basics
Commonly used controls in winform
Process-oriented Comparison of three cycles
Method (I) in C)
Our common Array
Object-oriented Thought Change
C # super-class and easy-to-use classes
The use of destructor and namespaces in C #
C # super-class and easy-to-use strings
How to quickly process strings in C #
Value Type, reference type, and others
Arraylist and hashtable
Arraylist and hashtable
File Management
Polymorphism
Section on other issues in C #
GDI + The GDI + code I have collected over the years
The GDI + Code 2 I collected over the years
HTML overview and CSS HTML language that you cannot ignore
You can't ignore HTML 2.
HTML language 3 that you cannot ignore
CSS basic content-special contribution to the Mid-Autumn Festival
CSS basic content 2
Javascript Basics Javascript basics 1

 

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.