ITPub博客

首页 > 应用开发 > Java > JSP(7) - 销售模块

JSP(7) - 销售模块

原创 Java 作者:zhyuh 时间:2005-06-14 16:21:41 0 删除 编辑

本模块处理销售事务,并允许根据商品编号和顾客卡号核实商品和顾客的详细信息。

要点
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:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
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>







<!--

-->






销售


商品编号

客户卡号

购物数量

购物日期

当日购物批次


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



商品编号检查 name=btn_comm_id onclick="javascript:checkComm()">

商品名称

单价:     

库存:     



顾客卡号检查 name=btn_cust_id onclick="javascript:checkCust()">

顾客姓名

折扣:     

购物总额

该顾客今天已经有笔交易纪录




sale_out_aft.jsp:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%
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:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
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:

<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.DateFormat" %>
<%
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/,如需转载,请注明出处,否则将追究法律责任。

上一篇: JSP(6) - 进货模块
请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2009549