A348 Home Work 5 - Project Databases/XML/XSL |
Modified: |
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:
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.
Redirect to page "OverDraft.xml" when insufficient funds are available. Do not alter any database tables if there are insufficient funds.
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:
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.
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>
|
Complete:
Turn in