Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

ASP.NET 2.0 Everyday Apps For Dumies 2006 phần 5 pot
Nội dung xem thử
Mô tả chi tiết
data into another table that also has an identity column. In that case, the
@@IDENTITY function returns the identity value for the second table. Fortunately, the Cart database doesn’t use triggers, so the @@IDENTITY function
will correctly return the identity value generated by the Orders table.
Connecting to the database
The connection string used to access the Cart database is stored in the
application’s web.config file, like this:
<connectionStrings>
<add name=”ConnectionString”
connectionString=”Data
Source=localhost\SQLExpress;
Initial Catalog=Cart;Integrated Security=True”/>
</connectionStrings>
The only place in the application that references this connection string is
here in the web.config file. This makes it easy to relocate the database
when you put the application into production.
The Application’s Folders
The Shopping Cart application includes the following folders:
(Root): The application’s root folder contains the application’s six pages
(Default.aspx, Product.aspx, Cart.aspx, CheckOut.aspx, and
Completed.aspx) as well as the Master Page (Default.master).
App_Data: This folder is designed to store databases used by the application. However, this particular application uses a database that’s stored
in a location that’s determined by SQL Server. So the database for our
Cart isn’t actually stored in this folder. (If you use the script presented in
Listing 6-1 to create the database, the database file is stored in C:\Apps.)
App_Code: This folder contains the C# or Visual Basic code files that
define the classes used by the application. For more information about
these classes, see the section “Designing the Classes” later in this chapter.
Images: Here, you’ll find the banner image displayed by the Master Page
and the image files that show pictures of the store’s products.
Chapter 6: Building a Shopping Cart Application 161
12_597760 ch06.qxp 1/11/06 9:55 PM Page 161
Designing the Classes
Unlike most of the other applications presented in this book, the Shopping
Cart application depends on several classes that both define the business
objects used by the program as well as provide the database access. In particular, the application uses the following classes:
Customer: Represents a single customer.
ShoppingCart: Represents the user’s shopping cart.
CartItem: Represents an item in the user’s shopping cart.
Order: Represents an order.
OrderDB: Handles the details of writing an order to the database.
The following sections describe each of these classes in detail.
The Customer class
The Customer class represents a single customer. Its constructors and properties are spelled out in Table 6-4.
Table 6-4 The Customer Class
Constructor Description
Customer() Creates an instance of the Customer
class with default property values.
Customer(string lastName, Creates an instance of the Customer
string firstName, string class with the specified property values.
address, string city,
string state, string
zipCode, string
phoneNumber, string email)
Property Description
string LastName The customer’s last name.
string FirstName The customer’s first name.
162 Part III: Building E-Commerce Applications
12_597760 ch06.qxp 1/11/06 9:55 PM Page 162
Property Description
string Address The customer’s street address.
string City The customer’s city.
string State The customer’s state.
string zipCode The customer’s Zip code.
string phoneNumber The customer’s phone number.
string email The customer’s e-mail address.
The ShoppingCart class
The ShoppingCart class represents a user’s shopping cart. Its constructors,
properties, and methods are listed in Table 6-5.
Table 6-5 The ShoppingCart class
Constructor Description
ShoppingCart() Creates a new shopping cart with no
items.
Property Description
int Count The number of items in the shopping cart.
Method Description
List<CartItem> GetItems() Returns a List object that contains one
CartItem object for each item in the
shopping cart.
void AddItem(string id, Adds a new item with the specified
string name, decimal price) product ID, name, and price.
void UpdateQuantity Updates the quantity at the specified
(int index, int quantity) index.
void DeleteItem(int index) Deletes the item at the specified index.
string PhoneNumber The customer’s phone number.
Chapter 6: Building a Shopping Cart Application 163
12_597760 ch06.qxp 1/11/06 9:55 PM Page 163