A348 Home Work 5 - Project  Databases/XML/XSL

Modified

Overview 

Three key stock trading functions remain: removing cart contents, committing selected stocks to buy or sell, and producing a summary of stock trading performance.

Home work 4 completed logic for adding stocks to buy (BuyStock.asp) or sell (SellStock.asp) to the shopping cart, a metaphor for the Cart database table.  Logic for viewing the cart (CartSummary.asp) was also implemented.

Cart removal (CartEdit.asp) - Remove trades from the cart as marked by a trader. When completed redirects to CartSummary.asp to display the shopping cart contents, no need to write a style sheet.

The stocks to remove are input on the URL address line from the browser, designated by the unique TRADEID number. To designate removal of TRADEID 95 and 101, the address line would be:

http://localhost/project/CartEdit.asp?95=on&101=on

Determining trades to remove is similar to BuyStock.asp and SellStock.asp. The TRADEIDs can be determined with the Request.QueryString object.

Committing (CartCommit.asp) - The purpose of this assignment is to implement logic that commits the stock trades contained in the cart for the current logged in trader. That is, stocks are bought or sold against the trader's portfolio and account balance.

The logic for committing the trades can be stated as follows:

  1. First  - Verify that the Session("trader") variable is defined, redirect to Login.xml if not defined.

     

  2. Before Selling - Verify that the number of stocks owned are at least equal to the number in the cart to be sold. You can make the simplifying assumption that this must be true for each individual sale. The assumption is reasonable even though a trader can buy and sell the same stock at the same time.

    The necessary records are produced by an inner join of the Cart and Portfolio tables on SYMBOL and ID selecting records where ID is the trader and BUY is false. This is sufficient because the SellList.asp module listed stocks to sell from the trader's portfolio, there is no stock to sell in the cart that is not in the portfolio.

    Redirect to page "userStockShortage.xml" when stocks owned is less than the number of stocks to sell. Do not alter any database tables if there are insufficient stocks owned.

     

  3. Before Buying - Verify a sufficient balance for the total stock purchase after stocks in the cart are sold.

    Redirect to page "OverDraft.xml" when insufficient funds are available. Do not alter any database tables if there are insufficient funds.

     

  4. Committing a buy (after verifying there are sufficient funds)

     

  5. Committing a sell (after verifying there are sufficient stocks in the portfolio)

     

  6. Account balance - The balance is updated to reflect the stocks bought and sold less the 5% commission on the value of each trade.

     

  7. Cart - After all trades have been committed the cart is emptied of the trader's selections.

     

  8. Completed - Redirect to page "Portfolio.asp" showing the trader the results.

 

Performance (TradingPerformance.asp) - The trading performance summary consists of a balance for the profit or loss for all stock trades and the total of commissions.

The logic is:

  1. Select all records from the Trades database table for the trader.
  2. For each trader record:
    1. Compute the value of each trade as PRICE*SHARES; add to the balance of the stocks sold or subtract from the balance of the stocks bought.
    2. Sum the commission is 5% of the value of each trade.
  3. Subtract the commission from the balance.
  4. Place the balance and commission in an XML tree.
  5. Display balance and commission by transforming the XML with XSL.

The key difference from other project modules is that the XML tree is not generated from a database but is constructed dynamically by placing values in the XML tree. The XML tree can be created from text by:

var xmlData = Server.CreateObject("Microsoft.XMLDOM");
xmlData.async = false;
xmlData.loadXML("<PERFORMANCE><BALANCE/><COMMISSION/></PERFORMANCE>");
The elements <BALANCE> and <COMMISSION> are to be assigned a text value; a value of 123.45 is assigned as the text of the BALANCE node by:
  var root = xmlData.documentElement;
  var node = root.selectSingleNode("BALANCE"); 
  node.text = 123.45;
The XSL transformation file is "TradingPerformanceContent.htm", downloaded for HW5. 
For more on tree manipulations, see class notes.

 

Global.asa

On opening an ASP script on a virtual directory for the first time, the server first reads the file Global.Asa from the root directory of the same virtual directory of the script. The Global.Asa file would normally contain session timeout limits, initialization, etc. The example below contains sets the important Session.Timeout to 1 minute. If the client associated with the session has no activity in 1 minute that causes a call to the Session_OnEnd subroutine in the Global.Asa script by the server, the server undefines the session variables and effectively forgets about the client. The Session.Timeout default is 20 minutes.

For the project, use the following Global.asa (copied with the Home Work 5 files). Its purpose is, on an inactivity timeout, to remove any stocks from the cart for the trader and to logout the trader.

If timeouts occur too soon, change the Session.Timeout = 1 to a larger value.

<Script LANGUAGE = VBScript RUNAT = Server>  
 Sub Session_OnStart 
	Response.Expires = 1      ' Page cached 1 minute
	Session.Timeout = 1       ' End session after 1 minute
 End Sub 

 Sub Session_OnEnd
    if Session("trader") <> "" then
		set conn = Server.CreateObject("ADODB.Connection") 
		conn.Mode = 3
		conn.Open ("DSN=Project")
		conn.Execute("UPDATE TRADER SET LOGGED = 0 WHERE ID='" & Session("trader") & "'")   
		conn.Execute("DELETE FROM CART WHERE ID='" & Session("trader") & "'")
		conn.Close()
	end if
 End Sub 
</Script>

Assignment

Complete:

  1. Commit stock trades from cart (CartCommit.asp).
  2. Remove trades from cart (CartEdit.asp).
  3. Calculate the performance as the balance and commission (TradingPerformance.asp)

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
  2. Email notification to rwisman@ius.edu with subject: YOUR NAME - A348 HW5