JSP(7) - 銷售模組

zhyuh發表於2005-06-14

本模組處理銷售事務,並允許根據商品編號和顧客卡號核實商品和顧客的詳細資訊。

要點
1) 核實商品資訊時,採用和進貨模組不同的方法。
核實商品資訊在不可見的頁面sale_check_comm.jsp中完成,完畢後將結果返回到銷售頁面中
核實前:



......
function checkComm() {
document.frmData.action = './jsp/sale_check_comm.jsp';
document.frmData.submit();
}
核實後返回結果:
request.setAttribute("custId",sCustId);
request.setAttribute("custName",sCustName);
......
2)網頁間傳遞中文資訊防止亂碼
String sCommName = request.getParameter("comm_name");
sCommName = new String(sCommName.getBytes("ISO8859-1"));

[@more@]

源程式

sale_out_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();
}
%>







<span lang="ZH-CN" style="FONT-FAMILY: 宋體">銷售</span>







<!--

--&gt






銷售


商品編號

客戶卡號

購物數量

購物日期

當日購物批次


      確定 name=btn_submit>   取消 name=btn_reset>



商品編號檢查 name=btn_comm_id onclick="javascript:checkComm()">

商品名稱

單價:     

庫存:     



顧客卡號檢查 name=btn_cust_id onclick="javascript:checkCust()">

顧客姓名

折扣:     

購物總額

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




sale_out_aft.jsp:




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






<span lang="ZH-CN" style="FONT-FAMILY: 宋體">進貨</span>







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'),'D')";

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();
}
%>


sale_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);
%>


sale_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);

%>


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

相關文章