JSP(11) - 退貨模組

zhyuh發表於2005-06-14

該模組處理退貨資訊,基本上是銷售模組 (http://blog.itpub.net/post/334/32291) 的反過程。

[@more@]

return_back_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 sCommId="";
String sCommName="";
String sCommUnit="";
String sCommQutt="";

String sCustId = "";
String sCustName = "";
String sCustDisc = "";
String sCustTtSum = "";
String sExchQutt = "";
String sExchSeq = "1";

String sTodaySeq = "";


if( request.getAttribute("commName")!=null){
sCommId = request.getAttribute("commId").toString();
sCommName = request.getAttribute("commName").toString();
sCommUnit = request.getAttribute("commUnit").toString();
sCommQutt = request.getAttribute("commQutt").toString();

sCustId = request.getAttribute("custId").toString();
sCustName = request.getAttribute("custName").toString();
sCustDisc = request.getAttribute("custDisc").toString();
sCustTtSum = request.getAttribute("custTtSum").toString();
sExchQutt = request.getAttribute("exchQutt").toString();
sExchSeq = request.getAttribute("exchSeq").toString();

sTodaySeq = request.getAttribute("todaySeq").toString();
}

if ( request.getAttribute("custName")!=null){
sCustId = request.getAttribute("custId").toString();
sCustName = request.getAttribute("custName").toString();
sCustDisc = request.getAttribute("custDisc").toString();
sCustTtSum = request.getAttribute("custTtSum").toString();

sCommId = request.getAttribute("commId").toString();
sCommName = request.getAttribute("commName").toString();
sCommUnit = request.getAttribute("commUnit").toString();
sCommQutt = request.getAttribute("commQutt").toString();
sExchQutt = request.getAttribute("exchQutt").toString();
sExchSeq = request.getAttribute("exchSeq").toString();

sTodaySeq = request.getAttribute("todaySeq").toString();
}
%>







退貨







<!--

--&gt






退貨


商品編號: 

客戶卡號: 

退貨數量: 

退貨日期: 

當日交易批次: 


         





商品名稱: 

單價:     

庫存:     





顧客姓名: 

折扣:     

購物總額: 

該顧客今天已經有筆交易紀錄




return_back_aft.jsp:




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






退貨







String sCommId=request.getParameter("exch_comm_id");
String sCustId = request.getParameter("exch_cust_id");
String sExchQutt = request.getParameter("exch_qutt");
String sExchSeq = request.getParameter("exch_seq");
String sExchDate = request.getParameter("exch_date");

String sCommName="";
String sCommUnit="";
String sCommQutt="";
String sCustName = "";
String sCustDisc = "";
String sCustTtSum = "";

String sExchCurMon = "";
String sCommLeft = "";
String sExchMon = "";

if (sExchSeq.equals("")){
throw new Exception("當日交易批次不準為空");
}
if (sCommId.equals("")){
throw new Exception("商品編號不準為空!");
}
if (sExchQutt.equals("")){
throw new Exception("退貨數量不準為空!");
}
if (sCustId.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 sQuery = null;
String sInsert = null;
String sUpdate1 = null;
String sUpdate2 = null;
Statement stmt = null;
ResultSet rs = null;

try {

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

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

while(rs.next())
{
sCommName = rs.getString("comm_name");
sCommUnit = rs.getString("comm_unit");
sCommQutt = rs.getString("comm_qutt");
}

sQuery = "select cst_name,cst_discount, cst_trd_sum from customer where cst_id='"+sCustId+"'";

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

while(rs.next())
{
sCustName = rs.getString("cst_name");
sCustDisc = rs.getString("cst_discount");
sCustTtSum = rs.getString("cst_trd_sum");
}

sCommLeft = String.valueOf(Double.parseDouble(sCommQutt)+Double.parseDouble(sExchQutt));
sExchCurMon = String.valueOf(Double.parseDouble(sExchQutt)*Double.parseDouble(sCommUnit)*Double.parseDouble(sCustDisc)/100);
sExchMon = String.valueOf(Double.parseDouble(sCustTtSum)-Double.parseDouble(sExchCurMon));


sInsert = "insert into exchange(EXCH_SEQ, EXCH_CST_ID, EXCH_COMM_ID, EXCH_NB, EXCH_MON, EXCH_DATE, EXCH_TYPE) ";
sInsert = sInsert + "values("+sExchSeq+",'"+sCustId+"','"+sCommId+"',"+sExchQutt+","+sExchCurMon+",to_date('"+sExchDate+"','yyyy-mm-dd'),'E')";

sUpdate1 = "update commodity set COMM_QUTT="+sCommLeft+" where comm_id='"+sCommId+"'";
sUpdate2 = "update customer set cst_trd_sum="+sExchMon+" where cst_id='"+sCustId+"'";

//out.println(sInsert+"
");
//out.println(sUpdate1+"
");
//out.println(sUpdate2+"
");

stmt = conn.createStatement();
stmt.addBatch(sInsert);
stmt.addBatch(sUpdate1);
stmt.addBatch(sUpdate2);
stmt.executeBatch();

conn.commit();
out.println("退貨操作完成!"+"
");
out.println("退貨的商品編號:"+sCommId+" 商品名稱:"+sCommName+"
");
out.println("退貨顧客卡號:"+sCustId+" 顧客姓名:"+sCustName+"
");
out.println("商品單價:"+sCommUnit+"元
");
out.println("商品數量:"+sExchQutt+"
");
out.println("顧客折扣:"+sCustDisc+"%
");
out.println("退貨金額:"+sExchCurMon+"元
");
out.println("顧客累計購物金額:"+sExchMon+"元
");
out.println("這是該顧客今天的第"+sExchSeq+"筆交易。
");
out.println("商品"+sCommName+"尚有存貨"+sCommLeft);
}

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

");
}

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


return_check_cust.jsp:






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

String sCustId = request.getParameter("exch_cust_id");
String sCustName = "";
String sCustDisc = "";
String sCustTtSum = "";

String sExchSeq = request.getParameter("exch_seq");
String sExchQutt = request.getParameter("exch_qutt");
String sCommId = request.getParameter("exch_comm_id");
String sCommName = request.getParameter("comm_name");
sCommName = new String(sCommName.getBytes("ISO8859-1"));
String sCommUnit = request.getParameter("comm_unit");
String sCommQutt = request.getParameter("comm_qutt");

String sTodaySeq = "";

boolean rsnull=true;

if(sCustId != null && !sCustId.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 cst_name, cst_discount, cst_trd_sum from customer ";
sQuery = sQuery + " where cst_id='"+sCustId+"'";

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

while(rs.next())
{
rsnull=false;
sCustName = rs.getString("cst_name");
sCustDisc = rs.getString("cst_discount");
sCustTtSum = rs.getString("cst_trd_sum");
}

sQuery = "select count(*) count from exchange where exch_cst_id='"+sCustId+"'" ;
sQuery = sQuery + " and to_char(exch_date,'yyyy-mm-dd')=to_char(sysdate,'yyyy-mm-dd')";

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

while(rs.next())
{
sTodaySeq = rs.getString("count");
}
}
catch(Exception e){
System.out.println("檢索顧客資訊時出錯!");
e.printStackTrace();
out.println("

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

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

");
}
finally{
if(stmt != null) stmt.close();
conn.close();
}
}
request.setAttribute("custId",sCustId);
request.setAttribute("custName",sCustName);
request.setAttribute("custDisc",sCustDisc);
request.setAttribute("custTtSum",sCustTtSum);

request.setAttribute("exchSeq", sExchSeq);
request.setAttribute("exchQutt", sExchQutt);
request.setAttribute("commId", sCommId);
request.setAttribute("commName", sCommName);
request.setAttribute("commUnit", sCommUnit);
request.setAttribute("commQutt", sCommQutt);

request.setAttribute("todaySeq", sTodaySeq);

%>


return_check_comm.jsp:






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

String sCommId = request.getParameter("exch_comm_id");
String sCommName = "";
String sCommUnit = "";
String sCommQutt = "";

String sExchQutt = request.getParameter("exch_qutt");
String sExchSeq = request.getParameter("exch_seq");
String sCustId = request.getParameter("exch_cust_id");
String sCustName = request.getParameter("cust_name");
sCustName = new String(sCustName.getBytes("ISO8859-1"));
String sCustDisc = request.getParameter("comm_dis");
String sCustTtSum = request.getParameter("comm_tt_sum");

String sTodaySeq = request.getParameter("today_seq");

boolean rsnull=true;

if(sCommId != null && !sCommId.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='"+sCommId+"'";

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

while(rs.next())
{
rsnull=false;
sCommName = rs.getString("comm_name");
sCommUnit = rs.getString("comm_unit");
sCommQutt = 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();
}
}
request.setAttribute("commId",sCommId);
request.setAttribute("commName",sCommName);
request.setAttribute("commUnit",sCommUnit);
request.setAttribute("commQutt",sCommQutt);

request.setAttribute("exchSeq",sExchSeq);
request.setAttribute("exchQutt",sExchQutt);
request.setAttribute("custId",sCustId);
request.setAttribute("custName",sCustName);
request.setAttribute("custDisc",sCustDisc);
request.setAttribute("custTtSum",sCustTtSum);

request.setAttribute("todaySeq",sTodaySeq);
%>

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

相關文章