Introducing the Wrox Auction Site

Chapter 12 - Writing an Application
byJohn Kauffman, Fabio Claudio Ferracchiatiet al.?
Wrox Press ?2002

The tenet of e-commerce is that the Internet is able to take the place of a traditional bricks-and-mortar store, playing the role of the retailer who sits between buyer and vendor. For very little overhead, people are now able to sell their products electronically. The Internet has enabled the buyer and the seller to be brought together in a virtual (rather than a physical) manner.

Let's consider a simple example of commerce between two people, involving the kind of classified advertisements that are traditionally to be found in a local newspaper. In such a listing, advertisers will place small advertisements that list the items they wish to sell, and provide a means (usually a telephone number) by which prospective buyers can contact them.

Before we begin, we should consider the nature of a sale via a newspaper classified advertisement. During the course of the sale, the information flows in different directions at different stages. First, there is a downstream flow of information (from seller to buyer) - the listing in print in the newspaper. (Thus, the classified ad listing is just a way of bringing a buyer and seller together.) When a potential purchaser's interest has been raised, that interest must be relayed upstream (from buyer to seller) - usually by telephone or in person. Finally, there should be a face-to-face meeting in which the two parties are able to negotiate to finalize the sale - if the sale can be agreed. In our electronic world, this (the face-to-face meeting, not the agreement!) is unlikely to happen.

A Web-based Classifieds System

We'll implement a web-based classified ad system. Any user who is trying to buy an item can:

  • View items for sale.

  • Bid for an item they wish to purchase.

In addition, any user who is trying to sell an item can:

  • Place a new item for sale.

  • Browse a list of the items that they're trying to sell, and examine the bids that have been made on each of those items.

  • Accept a bid on an item that they're selling. When the seller is satisfied about the bid for his item, he will accept the bid - and the sale will be half complete. Then, the buyer must acknowledge the acceptance, and then the sale will be finalized.

This system will also allow users to do other tasks, such as:

  • Browse the listings to see what's for sale.

  • Register with the system (users can browse without registering; but they must register if they want to sell an item or bid for an item).

  • Log on to the system.

  • Change their registration details.

If our web site takes off, we'll have a large user base - some will be buyers, some will be sellers, and (hopefully) some will be both. In order to carry out either activity, a user must register with us.

Advantages over a Print-based Classifieds System

Our Internet-based classified ad system provides certain advantages to the seller over traditional printed classifieds:

  • When a seller submits an item for sale, it's immediately viewable by potential buyers. There's no time delay while we all wait for the newspaper to be printed.

  • Responses from potential buyers are held by the system's data store, rather than being passed directly back to the seller. This means that the seller doesn't have to be available to respond 24 hours a day.

  • The seller can dynamically adjust the price, based on the amount of responses an item receives.

  • The global nature of the Internet means that the potential audience for each advert is global - it's not limited to the catchment area of a printed newspaper

The Internet classified ad system also provides advantages for potential buyers:

  • Shoppers can see the level of interest in an item before determining the price they are willing to pay.

  • When a shopper makes a bid, he is told whether the bid is the highest bid made on that item.

Building the Application

We'll build our application in stages. Each stage will build on the previous ones, and will add a new piece of functionality to the application. The sequence we'll follow in this chapter is:

  • Database setup

  • Home page construction

  • User registration and login

  • Adding items to the sale listings

  • Browsing the listings and bidding for items

  • Accepting a bid and completing the sale

Once we've created the tables and the stored procedures - which, as we'll discuss shortly, we're going to do through a pre-written setup file - the next step is to write the ASP.NET pages and database components. To get us started, let's take a look at the ASP.NET pages that will feature in our application - there are ten of them altogether. Each of these pages serves a different function, and contains the code for carrying out certain tasks. The pages are given names that reflect their functionality:

Page

Purpose

Default.aspx

The home page. Provides links to the login, registration and browse pages.

BrowseListing.aspx

This page shows a table containing brief details of each item that's currently available for purchase. From this page, registered users will be also able to select a particular product for sale, and click through to BidItem.aspx (to bid on the item).

Login.aspx

Enables a registered user to enter a username and password, and hence login to the system.

Register.aspx

Contains a form that enables new users to enter the necessary registration details. Also used to enable existing users to change their registration details.

MenuForRegisteredUsers.aspx

This is the first page that users see once they've logged in - it welcomes registered users to the site, presenting a simple menu of options that they can choose from. The menu in this page allows the user to navigate to other pages that can only be accessed by registered users.

Sometimes, this page performs a second function: if the user placed bids on items during previous visits to the site, they will be displayed. Furthermore, if the vendor of an item has subsequently accepted a bid, the page will alert the user to the fact that their bid was successful.

ViewMySaleItems.aspx

Allows registered users to view the details of all of the items that they have made available for sale. From this page, the user can click-through to Items.aspx and edit these details. The 'highest bid' for each item is also displayed, and the user can accept a bid on an item via this page.

Items.aspx

Allows registered users to enter details of an item that they wish to make available for sale.

BidItem.aspx

Allows a potential buyer to view the details of a sale item, and to enter a bid.

AcceptBid.aspx

When a potential buyer's bid has been accepted, the buyer is alerted via MenuForRegisteredUsers.aspx (as described above). At this stage, the buyer can click through to AcceptBid.aspx and acknowledge the alert, and thus complete the sale.

Logout.aspx

Logs out the currently logged in user.

Setting up the Application

Like many web-based applications, the underlying structure of this project is dependent on the ability to store and retrieve information. Therefore, we need to support some form of data storage. For the purposes of this application, as we have throughout the book so far, we'll be using an MSDE relational database to store all of the application's data.

All of the files for this application are available from http://www.wrox.com. When you've got them, you should run the setup.exe program, which will create a virtual directory in IIS, and create the database along with its associated tables and stored procedures. The name of the virtual directory is bid, which allows you to access the application using an address of http://localhost/bid/.

The Setup Program

The setup program has no options, and all you have to do is hit the button. When setup is complete, you'll see a dialog that looks like this:

click to expand

Here, you have the chance to view the log files for the creation of both the application and the database. If there were no errors, you also get the option to run the case study. This allows you to examine a finished version of the application.

The Database Model

The diagram below shows the relationships between the tables that we're using in our system. In it, you can see that there are five tables in the database:

click to expand

The purposes of each of these five tables are as follows:

Table

Description

Person

Contains details of all the registered users in the system.

Item

Contains details of each item that is for sale, or has been sold.

Bid

Contains details of each bid on an Item.

Sale

Contains details of each sale, including the item bought and who bought it.

Seller

Contains details of the items a Person has for sale.

Accessing the Database

To follow good design principles, we've abstracted all of our access to these tables in two ways. First, we've created a set of stored procedures. The application will talk to the stored procedures, and the stored procedures will talk to the tables. This means that if we ever need to change the tables (for example, by adding or changing columns), all we have to do is ensure that the stored procedure still works in the same way - this will ensure that the application will continue working. Moreover, access using stored procedures can be faster than accessing the tables directly.

Second, we'll use a Data Access Layer (DAL) in our application. The DAL is a layer of code that wraps up all of the complexities of accessing databases - it's another layer of abstraction. We will call the DAL from our ASP.NET pages, and the DAL will talk to the stored procedures. The reason for creating a DAL is similar to that for using stored procedures: it allows changes to be managed easily. It also allows us to keep all of the data code in a single place. In this example, the DAL is simply a set of classes with a number of data-related methods that we can call from our pages. Using a DAL has the added advantage of making our pages simpler, too.

In the sample code, the DAL comprises two VB.NET files, Item.vb and Person.vb, which are held in the Components subdirectory. We won't reproduce or examine the code for these files here, however, because we want to concentrate on the ASP.NET pages. You can examine the copies of these files that are included in the download at your leisure.



Beginning ASP. NET 2.0 and Databases
Beginning ASP.NET 2.0 and Databases (Wrox Beginning Guides)
ISBN: 0471781347
EAN: 2147483647
Year: 2004
Pages: 263

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net