.NET PETSHOP Detailed (3): PETSHOP Three-layer Structure Middletire

xiaoxiao2021-03-17  193

.NET PETSHOP Detailed (3): PETSHOP Three-layer Structure Middletire

Through the previous article, we have a general understanding of the entire structure of .NET PETSHOP, and it is clear that the details of the design model and implementation of the database are particularly worth mentioning that the database is accessed through the stored procedure. In the next article, I will talk to everyone to explore the middle layer of .NET PETSHOP. According to the design principle of the three-layer structure, the intermediate layer package is business logic and rules. In this example of this network pet store, shopping treatment, order processing, account management, product query, etc. are all specific business logic, as for users Interaction is not a problem that the intermediate layer is to be processed. It treats is independent of the specific user interface and interaction, but only the core business rules and logic. The intermediate business logic of .NET PETSHOP is packaged into a .NET component, its namespace is PET Shop.components (with a file in the BIN folder). Figure 1 is a Class view and file view of the intermediate layer of the .NET PETSHOP solution.

Figure 1: Class view and file view of the intermediate layer of .NET PETSHOP solution

Next, we simulate the process of customers to the department store to procure the daily necessities to illustrate the process of operation and abstract important concepts (actually User Case, we will do this when we are analyzing, and is a very important step, from here It can be initially found in the logic entity to be involved in our implementation, and it can be used for database modeling design and class design). Business Analysis of Shopping Use: 1 Customer has the will of purchase;

2 The customer registers at the login administrator and has successfully registered;

3 Push a shopping cart in the registry;

4 Find the shelves stored in the stored goods category in the supermarket;

5 Find a specific brand of goods in the specific shelves;

6 put the goods that meet the will in your own shopping cart;

7 Repeat 4-6;

8 shopping is completed;

9 to the payment office to calculate the total price and pay;

10 Print shopping list;

11 refund the shopping cart;

12 take the shopping, the shopping is complete;

Remarks: In this use case, we have made some prerequisites and assume that it is convenient for .NET PETSHOP analysis, such as the second step in actual life.

Through this use case, we can at least abstract a few important concepts, and can find the corresponding class in the application: Customer corresponds to the product, the shopping cart corresponds to ShoppingCart, the product category corresponds to Category, specific items corresponding Item And the list corresponds to the Order. As I said earlier, these concepts are very useful for our business modeling and system modeling. It is through such an analysis, with a total of 9 core classes and 5 lightweight data structures in the business logic of .NET PETSHOP. In the same way, I list these classes here and explain (see Table 1).

Class name

Description

BasketItem

A shopping commodity representing shopping cart shippingcart.

Customer

Used for account management and login verification.

CustomerDetails

Details of the user account.

CustomeraDRESS

The address information of the user account.

Error

Help features used to log in to the error.

Item

Represents a specific item in a certain product.

ItemResults

Search for Item's result set.

ORDER

Shopping lists and orders after shopping.

PRODUCT

A type of product inside the big category.

ProductRESULTS

Search the result set of products.

Profile

User configuration.

ShoppingCart

Shopping cart, used for shopping throughout the process, until the order.

Database

Access the database via ADO.NET, encapsulate specific access methods.

SearchResults

Fragous search result set.

Table 1: Class of .NET PETSHOP intermediate layer

CustomerAddress, CustomerDetails, ItemResults, ProductResults, and SearchResults These of the lightweight data structures provide a loose data binding call between the data layer and the display layer. These classes are designed to have public properties, and the ASP.NET web page can access data through these attributes. The code of the class below illustrates how these five classes expose their public attributes for display layers.

Public Class ProductResults PUBLIC CLASS PRODUCTRESULTS

{

PRIVATE STRING M_PRODUCTID;

Private string m_name;

Public string productId {

Get {return m_productid;}

Set {m_ProductId = value;}

}

PUBLIC STRING NAME {

Get {return m_name;}

Set {m_name = value;}

}

}

In .NET PETSHOP Detailed (2), we have said that the database is done by storage, let's take a look at this section of the code:

Public string login (string username, string password) {

String Customerid;

// Params to Stored Proc

Database data = new database ();

Sqlparameter [] PRAMS = {

Data.makeinparam ("@ username", sqldbtype.varchar, 25, password),

Data.makeinparam ("@ password", sqldbtype.varchar, 25, username,

Data.makeoutparam ("@ Customerid", SqldbType.varchar, 25)

}

// Create Data Object and params

Data.Runproc ("UpaccountLogin", Prams); // Run The Stored Procedure

Customerid = (String) Prams [2] .value; // Get the Output Param Value

// if the customer id is an es Empty string, THE Login Faled

IF (Customerid == String.empty)

Return NULL;

Else

Return Customerid;

}

转载请注明原文地址:https://www.9cbs.com/read-129615.html

New Post(0)