JSP(7) - 銷售模組
本模組處理銷售事務,並允許根據商品編號和顧客卡號核實商品和顧客的詳細資訊。
要點
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"));
源程式
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();
}
%>
<!--
-->
商品編號檢查 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+"/";
%>
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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 基於java jsp的寵物狗銷售網站系統JavaJS網站
- 黑馬PM- B端產品-銷售模組設計
- JSP(11) - 退貨模組JS
- JSP(9) - 增加商品模組JS
- JSP(6) - 進貨模組JS
- 促銷模組
- 盤活銷售資料,助力銷售團隊管理
- 智雲通CRM:銷售小白如何領銷售任務?
- 銷售智慧名片與銷售管理系統那個好用?
- 公司銷售管理系統:公司銷售人員如何管理?
- Springboot 多模組 jspSpring BootJS
- JSP(12) - 商品處理模組JS
- JSP(10) - 修改商品資訊模組JS
- JSP(4) - 增加客戶模組JS
- 智雲通CRM:如何用銷售思維分析銷售資料?
- 簡述銷售管理CRM系統的銷售自動化
- 移動銷售:經得起未來考驗的銷售模式模式
- 銷售管理系統和銷售自動化SFA一樣嗎?
- JSP(5) - 修改客戶資訊模組JS
- CRM系統銷售漏斗按銷售流程可分為幾個階段?
- 智雲通CRM:銷售鋪墊階段,如何運用“植入銷售”策略?
- 銷售也要學會使用者心理分析:淺談服裝銷售
- 遊戲商業化與付費點:銷售手段和銷售工具(下篇)遊戲
- comScore:美國電子商務網站海外銷售收入佔收入7%網站
- 互動出版網計算機頻道圖書7日銷售排行計算機
- 理銷售和分銷中的協議協議
- 銷售和分銷憑證的結構
- 微商茶葉代理銷售
- 零售資料分析指導銷售:促銷時機看售罄率
- CRM銷售管理系統如何幫助小微企業進行銷售?
- 金蝶雲星空資料整合案例分享:銷售退貨單-銷售退貨
- 如何從銷售線索到銷售業績?這款智慧營銷工具是如何做到的?
- .NET 7+Angular 4 輕量級新零售進銷存系統Angular
- Epic遊戲商城數次促銷銷售額曝光遊戲
- 八大核心能力鑄就銷售精英:解鎖成功銷售的金鑰
- 亞馬遜銷售最好的書籍亞馬遜
- tableau 對比銷售額分析
- 建立銷售管理資料庫資料庫