📄 purchase2.jsp
字号:
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="TeaWeb.PurcharDetail"%>
<%@page import="TeaWeb.PurcharItemDetail"%>
<%@page import="TeaWeb.OracleHepler"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<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" />
</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%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="20" align="center" valign="middle"> </td>
</tr>
</table>
<table width="90%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="20" align="left" valign="middle">
<!-- 数据更新:
1、插入进货信息表
2、插入进货明细表(可能会是多条记录)
3、更新库存表中的库存量
4、更新仓库的表的仓库的剩余容量-->
<%
PurcharDetail pd = (PurcharDetail)session.getAttribute("Purchase"); //获取临时存放在session对象中的数据
// pd即是一个session对象也可用于类的对象
//创建ORACLE的连接,执行SQL语句
OracleHepler db = new OracleHepler();
Connection cn = db.getconnection();
try
{
//不让它自动提交
cn.setAutoCommit(false);
//下面构建进货信息表的插入语句
String sql_PurcharDetail = "Insert into Purchase(PurID,Code,AutoCode,PurchaseTime,ProductCost,CarriageCost,OtherCost,PurCost,Operater,Note,Status,PurUpDate)";
sql_PurcharDetail += "Values(Seq_Purchase.NextVal,?,?,To_Date(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,?,?,?,sysdate)";
PreparedStatement pstms = cn.prepareStatement(sql_PurcharDetail);
pstms.setString(1,pd.Code);
pstms.setString(2,pd.AutoCode);
pstms.setString(3, "2008-11-11 16:01:01");
pstms.setFloat(4,pd.ProductCost);
pstms.setFloat(5,pd.CarriageCost);
pstms.setFloat(6,pd.OtherCost);
pstms.setFloat(7,pd.Cost);
pstms.setString(8,pd.perater);
pstms.setString(9,pd.Status);
pstms.setString(10,pd.Note);
pstms.execute();
//下面构建进货明细表的插入语句、仓库可用空间的更新语句、更新库存表中的库存量
for (int i = 0; i <= pd.Product.size() - 1; i++)
{
//进货明细表的插入语句
String str = "";
PurcharItemDetail pdi = (PurcharItemDetail)pd.Product.get(i);
str += "Insert Into PurchaseItem(PurItID,PurchaseCode,ProductCode,Price,Num,PurItCost,SupplierCode,WarehouseCode,Note)";
str += " Values(Seq_PurchaseItem.NextVal,?,?,?,?,?,?,?,?)";
pstms = cn.prepareStatement(str);
pstms.setString(1,pd.Code);
pstms.setString(2,pdi.ProductCode);
pstms.setFloat(3,pdi.Price);
pstms.setInt(4,pdi.Num);
pstms.setFloat(5,pdi.Cost);
pstms.setString(6,pdi.SupplierCode);
pstms.setString(7,pdi.WarehouseCode);
pstms.setString(8,"");
pstms.execute();
//仓库可用空间的更新语句
str = "Update Storage Set Capability = Capability - ? Where Code = ?";
pstms = cn.prepareStatement(str);
pstms.setInt(1,pdi.Num);
pstms.setString(2,pdi.WarehouseCode);
pstms.execute();
//更新库存表中的库存量
str = "Select * from Stock Where (ProductCode = ?) And (StorageCode = ?)"; //查找存放在该仓库中是否已经有该产品
pstms = cn.prepareStatement(str);
pstms.setString(1,pdi.ProductCode);
pstms.setString(2,pdi.WarehouseCode);
ResultSet rs = pstms.executeQuery();
boolean IsExist = false;
if (rs.next())
{
IsExist = true;
}
if (IsExist) //说明该产品已经放去上去过,这时候只需要修改可用量
{
str = "Update Stock Set Num = Num + ? Where (ProductCode = ?) And (StorageCode = ?)";
}
else //没放上去过,则重新写入新数据
{
str = "Insert into Stock(Num,ProductCode,StorageCode,StocUpDate)";
str += "Values(?,?,?,sysdate)";
}
pstms = cn.prepareStatement(str);
pstms.setInt(1,pdi.Num);
pstms.setString(2,pdi.ProductCode);
pstms.setString(3,pdi.WarehouseCode);
pstms.execute();
}
//都执行完了,咱就提交了
cn.commit();
cn.setAutoCommit(true);
pstms.close(); //释放执行SQL的对象
cn.close(); //释放连接
session.setAttribute("Purchase",null); //释放所占用的临时缓存
out.print("<script language='javascript'>");
out.print("document.location = 'PurchaseList.jsp';");
out.print("</script>");
}
catch(Exception e)
{
//失败了,回滚了
cn.rollback();
out.print(e.getMessage());
}
%>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -