📄 addpurchaseitem3.jsp
字号:
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="TeaWeb.OracleHepler"%>
<%@page import="TeaWeb.PurcharItemDetail"%>
<%@page import="TeaWeb.PurcharDetail"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>天缘茗茶</title>
<LINK href="TeaWebCSS.css" type=text/css rel=stylesheet />
<script language="javascript">
function goto(url)
{
document.location = url;
}
</script>
</head>
<body topmargin="0" leftmargin="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" colspan="3"><%@ include file="head.jsp" %></td>
</tr>
<tr>
<td width="180" rowspan="2" align="right" valign="top"><%@ include file="left.jsp" %></td>
<td height="6" colspan="2" background="Images/TopLine.jpg"></td>
</tr>
<tr>
<td width="5" height="600" align="left" valign="top"><img src="Images/Corner.jpg" width="5" height="5" /></td>
<td width="100%" align="center" valign="top"><table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30">
</td>
</tr>
</table>
<%
try
{
request.setCharacterEncoding("gb2312");
String PCode = request.getParameter("txtCode");
String PPrice = request.getParameter("txtPrice");
String PNum = request.getParameter("txtNum");
String PSupplier = request.getParameter("txtSupplier");
String PStorage = request.getParameter("txtStorage");
if (PCode != null) //当要添加的产品为空的时候,一切都没有意义了,退出吧
{
if ((PPrice == null) || (PPrice == "")) //如果价格未提交或者提交成""则默认为0
{
PPrice = "0";
}
if ((PNum == null) || (PNum == "")) //如果数量未提交或者提交成""则默认为0
{
PNum = "0";
}
//验证获取供应商
String Supplier = "";
if (PSupplier == null) //如果供应商未提交则默认为""因为是列表默认都为第一个而不是为null
{
Supplier = "";
}
else
{
Supplier = PSupplier;
}
// 验证获取仓库
String Storage = "";
if (PStorage == null) //如果仓库未提交则默认为""因为是列表默认都为第一个而不是为null
{
Storage = "";
}
else
{
Storage = PStorage;
}
// 验证获取价格
float Price = 0;
try
{
Price = Float.parseFloat(PPrice);
}
catch(Exception ex)
{
Price = 0;
}
// 验证获取数量
int Num = 0;
try
{
Num = Integer.parseInt(PNum);
}
catch(Exception ex)
{
Num = 0;
}
float SubTotal = Price * Num;
//构造一条记录
PurcharItemDetail opid = new PurcharItemDetail();
opid.ProductCode = PCode;
opid.Price = Price;
opid.Num = Num;
opid.Cost = SubTotal;
opid.SupplierCode = Supplier;
opid.WarehouseCode = Storage;
//把记录添加到临时会话变量中
PurcharDetail pd = (PurcharDetail)session.getAttribute("Purchase");
//如果临时对象中没有进货信息,则新建一个
if (pd == null)
{
pd = new PurcharDetail();
if (session.getAttribute("UserName") != null)
{
pd.perater = session.getAttribute("UserName").toString();
}
}
int iPos = -1 ;//指示是否已经存在该产品,如果存在则保存其位置
//out.println(pd.Product.size()-1);// pd.Product.size()-1用于统计总的列表数
//刚开始添加时无任何产品时该值为-1,pd.Product.size()为0即为空的,
for(int i = 0;i<=pd.Product.size()-1;i++) //遍历当前的产品列表//size返回此列表中的元素数。
{
PurcharItemDetail obj = (PurcharItemDetail)pd.Product.get(i);//pd.Product.size()为1即从第一条开始
//get(int index)返回此列表中指定位置上的元素。
if (obj.ProductCode.equals(opid.ProductCode)) //找到存在的了只要产品的编号相同一致即可仓库号不用相同
{
iPos = i; //保存其位置
break; //找到了,就出来了,别呆太久了
}
}
if (iPos < 0) //说明没有找到,则直接加上去就可以了
{
pd.Product.add(opid);
//product是一个列表用于存储一个对象的所有数据用add来添加后pd.Product.size()-1变为0,
//pd.Product.size()对应的有一个数据即为1,每次都加一
}
else //找到了
{
PurcharItemDetail obj = (PurcharItemDetail)pd.Product.get(iPos);
obj.Num = obj.Num + opid.Num; //修改其数量//是替换原来的列表而不存新的列表
obj.Cost = obj.Price * obj.Num; //重新统计小计
pd.Product.set(iPos,obj); ////列表中指定位置不变是替换回去
//这样pd.Product.size()-1没有变化
}
//这样以后使它产品的编号和列表中指定位置相对应是一一对应
session.setAttribute("Purchase",pd);
}
out.print("<script language='javascript'>");
out.print("document.location = 'Purchase.jsp';");
out.print("</script>");
}
catch(Exception ex)
{
out.print(ex.getMessage());
}
%>
</td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -