A348 Home Work 4 - Project  Databases/XML/XSL

Modified

Overview 

Homework 4 is a continuation of Homework 3.

BuyStock.asp

Places stocks to buy in the Cart. When completed redirects to CartSummary.asp to display the shopping cart contents, no need to write a BuyStockContent.htm style sheet.

The stocks are input on the URL address line from the browser. To buy 10 shares of IBM and 15 shares of Microsoft (symbol is MSFT), the address line would be:

localhost/Project/BuyStock.asp?IBM=10&MSFT=15

The stocks and number of shares are placed on the URL line from a form using a GET method. Because we do not know beforehand the number or names of the variables, the Request(variable name) cannot be used. Instead, we can collect stock symbols and shares with the Request.QueryString object.

The following prints out each parameter key and item value. It should be in the Project directory as BuyStock.asp, try executing from the browser with the address line above.

<%@ Language=JScript%>
<%
   var n = Request.QueryString.Count;
   for (i=1; i<=n; i++)
       Response.Write(Request.QueryString.Key(i)+"="+Request.QueryString.Item(i)+"<br>");
%>

The Cart table has fields for: ID, SYMBOL, SHARES, PRICE and BUY. Each stock in the address line must be placed in the Cart with the ID of the trader, the stock SYMBOL, number of SHARES, PRICE, and BUY=true since the trader is buying.

The fundamental points are:

  1. The key value is a SYMBOL from the Stock table (e.g. Request.QueryString.Key(2)='MSFT').
  2. Each SYMBOL must be SELECTed from the Stock table to determine the PRICE of the stock.
  3. ID, SYMBOL, SHARES, PRICE and BUY fields must be INSERTed into the Cart table. The value of the fields are:
  4. When completed redirect to CartSummary.asp.

Testing - When integrated into the stock trading system, the BuyStock.asp script is executed from a HTML form with method="GET". The URL will include ALL named form inputs, not just those that a significant. Your script should verify, at a minimum, that inputs are non-blank and non-zero before adding to the cart.

For example, the following URL has UAL= and GMC=0; only IBM and MFST stocks should be added to the cart:

Test for empty string in JavaScript by:

Note that no check is made at this time that the trader has sufficient funds to buy stock but is performed at checkout.

 

SellList.asp and SellListContent.htm

List all the stocks in the Portfolio table for the trader ID and the value of each stock. The script is very similar to Portfolio.asp and testing style sheet can be very similar to TraderSummaryContent.htm file.

To write the SellListContent.htm style sheet, modify the TraderSummaryContent.htm file with the names of the SYMBOL, NAME, SHARES, PRICE, and STOCKVALUE.

The information needed is in two tables. Portfolio table holds the trader stock SYMBOL and number of SHARES, Stock table holds the SYMBOL and PRICE. Compute STOCKVALUE as SHARES*PRICE.

The challenge is to write the SQL to SELECT from the two tables based on the common SYMBOL field. Fortunately, what is needed is nearly the same as used in Portfolio.asp. Consult ASP-ADO-XML-XSL discussion on how to Join Database Tables.

 

SellStock.asp

Places stocks from the Portfolio table to sell in the Cart. When completed redirects to CartSummary.asp to display the shopping cart contents, no need to write a SellStockContent.htm style sheet.

The script is very similar to the BuyStock.asp with the exceptions:

Note that no check is made at this time that the trader has the stock to sell but is performed at checkout.

Assignment

Complete:

  1. Buy stocks from those available (BuyStock.asp) and place in shopping cart.
  2. List stocks owned to sell (SellList.asp).
  3. Sell stocks from those owned (SellStock.asp) and place in shopping cart.

Turn in

  1. Project directory.
    1. FTP to www.csci.ius.edu
      • In browser address enter: ftp://www.csci.ius.edu
      • Login using your IUS username and password.
      • Copy the contents of the Project directory onto ftp page.
    2. Test in IE. The Welcome.xml is a default page.
      • In browser address enter: http://www.csci.ius.edu/username/Welcome.xml
  2. Email notification to rwisman@ius.edu with subject: YOUR NAME - A348 HW4