📄 sellstock.jsp
字号:
<%--
* @author Pushkala
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
*
* Name of the File : SellStock.jsp
*
* Creation/Modification History :
* Pushkala 26-Apr-2002 Created
*
* Overview of Application :
*
* This page is part of the IBFBS application.
* This page displays the Portfolio Details of the stock held by the logged in user.
* The user can navigate to this page by clicking the Portfolio tab in the header.
* The user can choose to sell off some of his stocks by entering the quantity in
* the text field provided.
*
--%>
<%@page contentType="text/html;charset=WINDOWS-1252" language="java" %>
<%@page import="oracle.otnsamples.ibfbs.trademanagement.ejb.PortfolioInfo" %>
<%@page import="oracle.otnsamples.ibfbs.trademanagement.helper.DateFormatter" %>
<%@page import="oracle.otnsamples.ibfbs.usermanagement.ejb.AccountInfo" %>
<%@page import="java.util.Collection" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.util.StringTokenizer" %>
<html>
<head>
<title>OTN Financial Brokerage System : Sell Stock Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1252">
<link rel="stylesheet" href="includes/contents.css" type="text/css">
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='includes/tab.js' TYPE='text/javascript'><\/SCRIPT>");
//-->
</SCRIPT>
<script language="JavaScript">
// Function to set the value of recordnumber which is required for page formatting
function setRecordNum(recNum) {
formObj = document.PAGEFORMAT;
formObj.RECORDNUM.value = recNum;
formObj.submit();
}
// Function to validate the quantity of stock entered for selling
function validateSell(numOfRows) {
var numOfNulls = 0; // Counter for number of nulls
// Loop through all the records
for (var i=0; i<= numOfRows-1; i++) {
var sellQty;
var availQty;
// If the form has only one record
if (numOfRows == 1) {
sellQty = document.SELL.SELLQTY.value;
availQty = document.SELL.AVAILQTY.value;
// If the sell quantity is null, alert the user
if (sellQty == "") {
alert("Sell Quantity should be entered");
return;
}
} else {
sellQty = document.SELL.SELLQTY[i].value;
availQty = document.SELL.AVAILQTY[i].value;
}
// If the sell quantity is null, increment counter
if (sellQty == "") {
numOfNulls = numOfNulls + 1;
} else {
// If the quantity entered is not a number, alert the user
if (isNaN(sellQty)) {
alert("Sell Quantity should be a number");
return;
}
// If the quantity entered is less than or equal to zero, alert the user
if (sellQty <= 0) {
alert("Sell Quantity should be greater than zero");
return;
}
// Position of decimal in the entered value
pos = sellQty.indexOf(".");
// pos = -1 indicates that the string does not contain decimal places
if (pos != -1) {
alert("Sell Quantity should be an integer value");
return;
}
// If the sell quantity entered is greater than the available quantity, alert the user
if (Number(sellQty) > Number(availQty)) {
alert("Sell Quantity should be less than or equal to the available Quantity");
return;
}
}
}
// If the counter for nulls is equal to the total number of rows which
// indicates that the user has not entered any sell quantity, alert the user
if (numOfNulls == numOfRows) {
alert("Sell Quantity should be entered");
return;
}
// Submit the form
document.SELL.submit();
}
// Function to to reset all the entered values in the form
function resetSell(numOfRows) {
if (numOfRows == 1) {
document.SELL.SELLQTY.value = "";
} else {
for (var i=0; i<= numOfRows-1; i++) {
var sellQty = document.SELL.SELLQTY[i].value;
if (sellQty != "") {
document.SELL.SELLQTY[i].value = "";
}
}
}
}
</script>
</head>
<body bgcolor="#FFFFEA" onLoad="MM_preloadImages('images/myhome.gif','images/profile.gif','images/personalize.gif','images/portfolio.gif','images/logout.gif')">
<jsp:include page="Header.jsp?TABIMAGE=portfolio.gif" flush="TRUE"/>
<table width="100%" border="1" cellpadding="0" cellspacing="0" bgcolor="#FFFFEA" bordercolor="#008000" height="80%">
<tr>
<td width="20%" bordercolor="#FFFFEA" valign="center" bgcolor="#FFFFD5">
<jsp:include page="LeftList.jsp" flush="TRUE"/>
</td>
<td bordercolor="#FFFFEA" valign="top" align="center">
<%
String tab = request.getParameter("EVENTNAME");
if (tab.equals("SELL")) {
java.util.HashMap hm = (java.util.HashMap) session.getAttribute("SELL.RESPONSE");
Collection retCollection = (Collection)hm.get("PORTFOLIOINFO");
Iterator retIter = retCollection.iterator();
String hasPrev = "false";
String hasNext = "false";
Collection pfCollection = null;
if (retIter.hasNext()) {
hasPrev = (String)retIter.next();
hasNext = (String)retIter.next();
pfCollection = (Collection)retIter.next();
}
// Record Number of the first record in the set displayed
String recordNum = request.getParameter("RECORDNUM");
// Get the Account information of the logged in user
AccountInfo acInfo = (AccountInfo)hm.get("ACCOUNTINFO");
hm.clear();
session.removeAttribute("SELL.RESPONSE");
// Get the lines per page
int linesPerPage = acInfo.getLinesPerPage().intValue();
if (recordNum == null) recordNum = "1";
%>
<br>
<b><font face="Verdana, Times New Roman, Times, serif" color="#990000" size="2">
Sell Stock
</font></b>
<br><br>
<form name="SELL" method="POST" action="controllerservlet">
<table width="60%" cellpadding="2" cellspacing="2">
<%
Iterator pfIter = pfCollection.iterator();
String color1 = "#FFFFCC";
String color2 = "#CCFFCC";
String color = color2;
int rowCount = 0;
while (pfIter.hasNext()) {
PortfolioInfo pif = (PortfolioInfo)pfIter.next();
// Alternate between color1 and color2
color = (color.equals(color2))?color1:color2;
rowCount += 1;
if (rowCount == 1) {
%>
<tr>
<th bgcolor="#008000" class="tabHead">
<div align="center">DATE</div>
</th>
<th bgcolor="#008000" class="tabHead">
<div align="center">NAME</div>
</th>
<th bgcolor="#008000" class="tabHead">
<div align="center">PRICE ($)</div>
</th>
<th bgcolor="#008000" class="tabHead">
<div align="center">QUANTITY</div>
</th>
<th bgcolor="#008000" class="tabHead">
<div align="center">SELL QUANTITY</div>
</th>
</tr>
<input type="hidden" name="EVENTNAME" value="SELLSTOCK">
<%
}
// Display the values in the Collection
%>
<tr bgcolor="<%=color%>">
<td class="tableText" height="30">
<div align="center">
<%= DateFormatter.getStringFromDate(pif.getPurchaseDate(), "dd-MMM-yyyy") %>
</div>
</td>
<td class="tableText" height="30">
<div align="left"> <%=pif.getCompanyName()%></div>
</td>
<td class="tableText" height="30">
<div align="right"><%=pif.getPrice()%> </div>
</td>
<td class="tableText" height="30">
<div align="right"><%=pif.getQuantity()%> </div>
</td>
<td class="tableText" align="center">
<input type="text" name="SELLQTY" size="8">
<input type="hidden" name="AVAILQTY" value="<%=pif.getQuantity()%>">
<input type="hidden" name="LINENO" value="<%=pif.getLineNo()%>">
<input type="hidden" name="SYMBOL" value="<%=pif.getSymbol()%>">
<input type="hidden" name="TRADEID" value="<%=pif.getTradeId()%>">
</td>
</tr>
<%
}
%>
<%
// If the page required iteration, set a form with the RECORDNUM to the index of the
// first record and the EVENTNAME, display the Prev and Next buttons if required
if (hasPrev.equals("true") || hasNext.equals("true")) {
%>
<tr bgcolor="#FFFFEA">
<td align="center">
<%
// If there are some more previous records, display the prev button
if (hasPrev.equals("true")) {
int prev = Integer.parseInt(recordNum) - linesPerPage;
%>
<img src="images/prev.gif" alt="Previous" onMouseUp="setRecordNum('<%=prev%>');">
<%
}
%>
</td>
<td> </td>
<td> </td>
<td> </td>
<td align="center">
<%
// If there are some more next records, display the next button
if (hasNext.equals("true")) {
int next = Integer.parseInt(recordNum) + linesPerPage;
%>
<img src="images/next.gif" alt="Next" onMouseUp="setRecordNum('<%=next%>');">
<%
}
%>
</td>
</tr>
<%
}
%>
</table>
<%
if (rowCount == 0) {
%>
<font face="Verdana, Times New Roman, Times, serif" color="#008000" size="2">
<b>No Transactions found for the logged in user...</b>
</font>
<%
} else {
%>
<br>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td align="right" valign="center">
<img src="images/submit.gif" alt="Submit" onMouseUp="validateSell(<%=rowCount%>);">
</td>
<td valign="center">
<img src="images/reset.gif" alt="Reset" onMouseUp="resetSell(<%=rowCount%>);">
</td>
</tr>
</table>
<%
}
%>
</form>
<form name="PAGEFORMAT" action="controllerservlet" method="post">
<input type="hidden" name="EVENTNAME" value="SELL">
<input type="hidden" name="RECORDNUM">
</form>
<%
} else if (tab.equals("SELLSTOCK")) {
String retMessage = (String) session.getAttribute("SELLSTOCK.RESPONSE");
session.removeAttribute("SELLSTOCK.RESPONSE");
// The return message contains both Success and Failure messages
// String Tokenize the return message and format the message
// to display to the user
StringTokenizer st = new StringTokenizer(retMessage, "\n");
%>
<br><br>
<%
// Get all the tokens from the return message
while (st.hasMoreTokens()) {
String nextStr = st.nextToken();
if (nextStr.startsWith("Transaction")) {
%>
<font face="Verdana, Times New Roman, Times, serif" color="#008000" size="2">
<%
} else if (nextStr.startsWith("Failed")) {
%>
<font face="Verdana, Times New Roman, Times, serif" color="#FF0000" size="2">
<%
}
%>
<b>
<%= nextStr %>
</b>
</font><br>
<%
}
}
%>
</td>
</tr>
</table>
<jsp:include page="Footer.jsp" flush="false"/>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -