N342 Home Work 5 - Project Databases/XML/XSL |
Modified: |
The solution is to require IE to check for new versions on every visit to a page. In IE: Tools | Internet Options | Temporary Internet Files | Settings | Every Visit to Page
The following error may occur when accessing XML files downloaded from one computer to another such as the ZIP files for the assignment. Vista (and perhaps XP) blocks access to files, presumably attempting to protect you from using files you have copied to your computer.Unblock access to individual files by the following:
- Open in Windows Explorer the directory containing the file, either the XML file or one referenced by the XML.
- Right click on the file and open Properties.
- Click Unblock.
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Access is denied. Error processing resource 'file:///W:/N341/Project/TraderSummaryContent.htm'.
Unblock access to all files in a directory by the following:
- Download Streams, copy Streams.exe to Windows directory if possible.
- To unblock all the files in directory c:\temp and any subdirectories enter:
Streams –d –s c:\temp
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 unwanted 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://www.ius.edu/username/N342/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 a SELECT using an inner join of the Cart and Portfolio tables on SYMBOL and ID selecting records where ID is the trader and BUY is false. The INNER JOIN includes the following:
FROM CART INNER JOIN PORTFOLIO ON CART.SYMBOL = PORTFOLIO.SYMBOL AND CART.ID = PORTFOLIO.ID
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.
Iterate through the record set produced by the SELECT verifying a sufficient number of stocks. 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.
Note that accessing the recordset can be simplified by naming fields. For example, naming CART.SHARES field as SELL:
rs=conn.Execute("SELECT CART.SHARES AS SELL, PORTFOLIO.SHARES AS OWN
allows recordset operations to be written as:
if( rs("SELL") > rs("OWN") ) ...
Redirect to page "OverDraft.xml" when insufficient funds are available. Do not alter any database tables if there are insufficient funds.
There are three cases to handle:
Note that multiple recordsets can be defined simultaneously. One can then write statements such as:
var rc = conn.Execute("SELECT * FROM CART WHERE ID = '"+trader+"';");
while( !rc.EOF ) {
var rp = conn.Execute("SELECT * FROM PORTFOLIO WHERE SYMBOL = '"+rc("SYMBOL")+"' AND ID='"+trader+"'");
rc.MoveNext();
}
This example selects all records for a trader from the CART table (rc recordset) and, using the current CART record, the PORTFOLIO record with the matching SYMBOL (for that trader).
Testing requires placing several buy/sell stock transactions in the CART table for a registered and logged in trader. Then execute:
http://www.ius.edu/username/N342/Project/CartCommit.asp
Performance (TradingPerformance.asp) - The trading performance summary
consists of a balance for all stock trades and the total
of commissions paid. 
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 computed BALANCE and COMMISSION 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.
Testing requires placing several buy/sell stock transactions in the TRADES table for a registered and logged in trader. Then execute:
http://www.ius.edu/username/N342/Project/TradingPerformance.asp
The file, Global.Asa, is part of HW5 files and should be copied into the Project directory. The Global.Asa file should automatically be executed when a session starts and ends; the purpose is usually to perform session initializations on start, logout traders and delete the cart when the session times out.
However, at the current time, the IUS server is not properly executing the Global.Asa file. Please ignore for this assignment but it would need to be resolved for a production system. The default sessions timeout limit and the one used at IUS is set at 20 minutes.
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 minutes
End Sub
Sub Session_OnEnd
if(Session("trader")<>"") then
set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = 3
conn.Open ("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("Project.mdb") )
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 - Due before class on the date listed in the syllabus.