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 SystemWe'll implement a web-based classified ad system. Any user who is trying to buy an item can:
In addition, any user who is trying to sell an item can:
This system will also allow users to do other tasks, such as:
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 SystemOur Internet-based classified ad system provides certain advantages to the seller over traditional printed classifieds:
The Internet classified ad system also provides advantages for potential buyers:
Building the ApplicationWe'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:
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:
Setting up the ApplicationLike 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 ProgramThe 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:
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 ModelThe 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:
The purposes of each of these five tables are as follows:
Accessing the DatabaseTo 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. |