JSP(12) - 商品處理模組

zhyuh發表於2005-06-14
該模組基本上為 進貨模組(http://blog.itpub.net/post/334/32287)的反過程。[@more@]

dispose_bef.jsp:






response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader("Expires", 0); //prevents caching at the proxy server

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
java.util.Date d=new java.util.Date();
DateFormat dFormat=new SimpleDateFormat("yyyy-MM-dd",Locale.CHINESE);

String sExchId = request.getParameter("exch_id");
String sExchName = "";
String sExchUnit = "";
String sExchQutt = "";

String sCommQutt = request.getParameter("exch_qutt");

boolean rsnull=true;

if(sExchId != null && !sExchId.equals("")){

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@TCSCH074.tcsgdccn.com:1521:orcl";
//orcl為你的資料庫的SID
String user="store";
String password="store";
Connection conn= DriverManager.getConnection(url,user,password);
String sQuery = null;
Statement stmt = null;
ResultSet rs = null;

try{

sQuery = "select comm_name, comm_unit, comm_qutt from commodity ";
sQuery = sQuery + " where comm_id='"+sExchId+"'";

stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);

while(rs.next())
{
rsnull=false;
sExchName = rs.getString("comm_name");
sExchUnit = rs.getString("comm_unit");
sExchQutt = rs.getString("comm_qutt");
}

}
catch(Exception e){
System.out.println("檢索商品資訊時出錯!");
e.printStackTrace();
out.println("

檢索商品資訊時出錯!請聯絡技術支援人員。

");
out.println( e.getMessage() );
out.println("

");
}
finally{
if(stmt != null) stmt.close();
conn.close();
}
}
%>





進貨







<!--

--&gt



javascript:window.alert("商品編號不存在!")>

<!----&gt

處理


商品編號: >

處理數量: >


處理日期: 

當日處理批次:  


         




商品名稱: 

單價: 

庫存: 






dispose_aft.jsp:




String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>






處理







String sExchSeq = request.getParameter("exch_seq");
String sExchCommID = request.getParameter("exch_id");
String sExchCustID = "000001";
String sExchQutt = request.getParameter("exch_qutt");
String sExchDate = request.getParameter("exch_date");

String sCommName = null;
String sCommQutt = null;
String sCommUnit = null;
String sExchMon = null;

if (sExchSeq.equals("")){
throw new Exception("當日進貨批次不準為空");
}
if (sExchCommID.equals("")){
throw new Exception("商品編號不準為空!");
}
if (sExchQutt.equals("")){
throw new Exception("進貨數量不準為空!");
}

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@TCSCH074.tcsgdccn.com:1521:orcl";
//orcl為你的資料庫的SID
String user="store";
String password="store";
Connection conn= DriverManager.getConnection(url,user,password);
String sInsert = null;
String sQuery = null;
String sUpdate = null;
Statement stmt = null;
ResultSet rs = null;

try {
sQuery = "select comm_name,comm_qutt,comm_unit from commodity where comm_id='"+sExchCommID+"'";

stmt = conn.createStatement();
rs = stmt.executeQuery(sQuery);
if (rs.next()) {
sCommName = rs.getString("comm_name");
sCommQutt = rs.getString("comm_qutt");
sCommUnit = rs.getString("comm_unit");
}

sExchMon = String.valueOf(Double.parseDouble(sCommUnit)*Double.parseDouble(sExchQutt));

sInsert = "insert into exchange(EXCH_SEQ, EXCH_CST_ID, EXCH_COMM_ID, EXCH_NB, EXCH_MON, EXCH_DATE, EXCH_TYPE) ";
sInsert = sInsert + "values("+sExchSeq+",'"+sExchCustID+"','"+sExchCommID+"',"+sExchQutt+","+sExchMon+",to_date('"+sExchDate+"','yyyy-mm-dd'),'F')";

sUpdate = "update commodity set COMM_QUTT=("+sCommQutt+"-"+sExchQutt+") where comm_id='"+sExchCommID+"'";

//out.println(sQuery+"
");
//out.println(sInsert+"
");
//out.println(sUpdate+"
");

stmt = conn.createStatement();
stmt.addBatch(sInsert);
stmt.addBatch(sUpdate);
stmt.executeBatch();

conn.commit();
out.println("商品處理完成
");
out.println("商品編號:"+sExchCommID+"
");
out.println("商品:"+sCommName+"
");
out.println("數量:"+sExchQutt+"
");
out.println("單價:"+sCommUnit+"
");
out.println("金額:"+sExchMon+"
");
}

catch (Exception e){
System.out.println("處理操作失敗!");
e.printStackTrace();
out.println("處理操作失敗!
");
out.println(e.getMessage());
out.println("

");
}

finally {
if (stmt != null) stmt.close();
conn.close();
}
%>


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/207/viewspace-800205/,如需轉載,請註明出處,否則將追究法律責任。

相關文章