目录
1 概述
2 数据库表
3 关键代码
4 效果演示
1 概述
一个功能简单,操作方便的商品销售系统可以大大的方便小型的企业管理人员对商品进行管理,提高企业管理的效率。
本系统包含:商品管理 商品分类管理 出库管理 入库管理 退货管理 销售管理 供应商管理 客户管理 员工管理 以及库存统计和盘存统计
2 数据库表
表 admin管理员信息表
名称 |
类型 |
说明 |
userId |
int |
编号 |
userName |
varchar(50) |
名称 |
userPw |
varchar(50) |
密码 |
usertype |
varchar(50) |
类型 |
表goods 物资信息表
名称 |
类型 |
说明 |
id |
int |
编号 |
catelog_id |
int |
分类编号 |
name |
varchar(50) |
名称 |
chandi |
varchar(50) |
词典 |
danwei |
varchar(50) |
单位 |
guige |
varchar(50) |
规格 |
beizhu |
varchar(50) |
备注 |
photo |
varchar(150) |
图片 |
表 ruku 入库信息表
名称 |
类型 |
说明 |
id |
int |
编号 |
danjuhao |
varchar(50) |
单据号 |
shijian |
datetime |
时间 |
zongjiage |
int |
价格 |
jingshouren |
varchar(50) |
经手人 |
beizhu |
varchar(50) |
备注 |
3 关键代码
package com.action;import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.dao.DB;
import com.orm.TAdmin;
import com.orm.Tcatelog;
import com.orm.Txiaoshou;
import com.service.liuService;public class xiaoshou_servlet extends HttpServlet
{public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {String type=req.getParameter("type");if(type.endsWith("xiaoshouMana")){xiaoshouMana(req, res);}if(type.endsWith("xiaoshouAdd")){xiaoshouAdd(req, res);}if(type.endsWith("xiaoshouEdit")){xiaoshouEdit(req, res);}if(type.endsWith("xiaoshouDel")){xiaoshouDel(req, res);}}public void xiaoshouAdd(HttpServletRequest req,HttpServletResponse res){String id=String.valueOf(new Date().getTime());int goods_id=Integer.parseInt(req.getParameter("goods_id"));String shijian=req.getParameter("shijian");float zongjia=Float.parseFloat(req.getParameter("zongjia"));String zhifufangshi=req.getParameter("zhifufangshi");int gukename=Integer.parseInt(req.getParameter("kehu_id"));String beizhu=req.getParameter("beizhu");String del="no";String sql="insert into t_xiaoshou (`id`, `goods_id`, `shijian`, `zongjia`, `zhifufangshi`, `gukename`, `beizhu`, `del`) values(?,?,?,?,?,?,?,?)";Object[] params={id,goods_id,shijian,zongjia,zhifufangshi,gukename,beizhu,del};DB mydb=new DB();mydb.doPstm(sql, params);//mydb.closed();//int id=Integer.parseInt(req.getParameter("id"));sql="update t_rukuMingxi set shuliang=shuliang-1 where shuliang>0 and goods_id="+goods_id;Object[] params1={};mydb=new DB();mydb.doPstm(sql, params1);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "xiaoshou?type=xiaoshouMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void xiaoshouEdit(HttpServletRequest req,HttpServletResponse res){int goods_id=Integer.parseInt(req.getParameter("goods_id"));String shijian=req.getParameter("shijian");float zongjia=Float.parseFloat(req.getParameter("zongjia"));String zhifufangshi=req.getParameter("zhifufangshi");int gukename=Integer.parseInt(req.getParameter("kehu_id"));String beizhu=req.getParameter("beizhu");String del="no";String sql="update t_xiaoshou set goods_id='"+goods_id+"',shijian='"+shijian+"',zongjia='"+zongjia+"',zhifufangshi='"+zhifufangshi+"',gukename='"+gukename+"',beizhu='"+beizhu+"' where id='"+req.getParameter("id")+"'";Object[] params={};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "xiaoshou?type=xiaoshouMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void xiaoshouDel(HttpServletRequest req,HttpServletResponse res){String id=req.getParameter("id");String sql="update t_xiaoshou set del='yes' where id=?";Object[] params={id};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "xiaoshou?type=xiaoshouMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void xiaoshouMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException{String page1=req.getParameter("page");if(page1==null){page1="1";}//分页设置int EVERYPAGENUM=10;//每页条数int page=Integer.parseInt(page1); //传递过来的当前页int cou = 1;//得到信息总数 int pagecount=1; //总页数String sql1="select count(*) as cou from t_xiaoshou where del='no'";Object[] params1={};DB mydb1=new DB();try{mydb1.doPstm(sql1, params1);ResultSet rs=mydb1.getRs();while(rs.next()){cou= rs.getInt("cou");}rs.close();}catch(Exception e){e.printStackTrace();}mydb1.closed();if (cou % EVERYPAGENUM == 0) {pagecount= cou / EVERYPAGENUM;} else {pagecount=cou / EVERYPAGENUM + 1;} req.setAttribute("EVERYPAGENUM", EVERYPAGENUM); req.setAttribute("page", page);req.setAttribute("cou", cou);req.setAttribute("pagecount", pagecount);List xiaoshouList=new ArrayList();String sql="select * from t_xiaoshou where del='no' order by id desc";Object[] params={};DB mydb=new DB();try{mydb.doPstm(sql, params);ResultSet rs=mydb.getRs();for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {rs.next();}for (int t = 0; t < EVERYPAGENUM; t++) {if (rs.next()) {Txiaoshou xiaoshou=new Txiaoshou();xiaoshou.setId(rs.getString("id"));xiaoshou.setGoods_id(rs.getInt("goods_id"));xiaoshou.setShijian(rs.getDate("shijian"));xiaoshou.setZongjia(rs.getFloat("zongjia"));xiaoshou.setZhifufangshi(rs.getString("zhifufangshi"));xiaoshou.setGukename(rs.getInt("gukename"));xiaoshou.setBeizhu(rs.getString("beizhu"));xiaoshou.setDel(rs.getString("del"));xiaoshou.setGoods_name(liuService.getGoodsName(rs.getInt("goods_id")));xiaoshou.setGuke_name(liuService.getGukeName(rs.getInt("gukename")));xiaoshouList.add(xiaoshou);} else {break; //减少空循环的时间}}rs.close();}catch(Exception e){e.printStackTrace();}mydb.closed();req.setAttribute("xiaoshouList", xiaoshouList);req.getRequestDispatcher("admin/xiaoshou/xiaoshouMana.jsp").forward(req, res);}public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) {RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);try {dispatch.forward(request, response);return;} catch (ServletException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}public void init(ServletConfig config) throws ServletException {super.init(config);}public void destroy() {}
}
package com.action;import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.dao.DB;
import com.orm.Yuangong;public class yuangong_servlet extends HttpServlet
{ public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {String type=req.getParameter("type");if(type.endsWith("yuangongAdd")){yuangongAdd(req, res);}if(type.endsWith("yuangongEdit")){yuangongEdit(req, res);}if(type.endsWith("yuangongMana")){yuangongMana(req, res);}if(type.endsWith("yuangongDel")){yuangongDel(req, res);}if(type.endsWith("yuangongQuanxian")){yuangongQuanxian(req, res);}}public void yuangongAdd(HttpServletRequest req,HttpServletResponse res){String name=req.getParameter("name");String sex=req.getParameter("sex");String age=req.getParameter("age");String tel=req.getParameter("tel");String address=req.getParameter("address");String zhiwei=req.getParameter("zhiwei");String sql="insert into t_yuangong (`name`, `sex`, `age`, `tel`, `address`, `zhiwei`, `quanxian`, `loginName`, `loginPw`, `del`) values(?,?,?,?,?,?,?,?,?,?)";Object[] params={name,sex,age,tel,address,zhiwei,0,"","","no"};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "yuangong?type=yuangongMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void yuangongEdit(HttpServletRequest req,HttpServletResponse res){String name=req.getParameter("name");String sex=req.getParameter("sex");String age=req.getParameter("age");String tel=req.getParameter("tel");String address=req.getParameter("address");String zhiwei=req.getParameter("zhiwei");String sql="update t_yuangong set name='"+name+"',sex='"+sex+"',age='"+age+"',tel='"+tel+"',address='"+address+"',zhiwei='"+zhiwei+"' where id="+Integer.parseInt(req.getParameter("id"));Object[] params={};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "yuangong?type=yuangongMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void yuangongDel(HttpServletRequest req,HttpServletResponse res){int id=Integer.parseInt(req.getParameter("id"));String sql="update t_yuangong set del=? where id=?";Object[] params={"yes",id};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "yuangong?type=yuangongMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void yuangongMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException{String page1=req.getParameter("page");if(page1==null){page1="1";}//分页设置int EVERYPAGENUM=10;//每页条数int page=Integer.parseInt(page1); //传递过来的当前页int cou = 1;//得到信息总数 int pagecount=1; //总页数String sql1="select count(*) as cou from t_yuangong where del='no'";Object[] params1={};DB mydb1=new DB();try{mydb1.doPstm(sql1, params1);ResultSet rs=mydb1.getRs();while(rs.next()){cou= rs.getInt("cou");}rs.close();}catch(Exception e){e.printStackTrace();}mydb1.closed();if (cou % EVERYPAGENUM == 0) {pagecount= cou / EVERYPAGENUM;} else {pagecount=cou / EVERYPAGENUM + 1;} req.setAttribute("EVERYPAGENUM", EVERYPAGENUM); req.setAttribute("page", page);req.setAttribute("cou", cou);req.setAttribute("pagecount", pagecount);List yuangongList=new ArrayList();String sql="select * from t_yuangong where del='no'";Object[] params={};DB mydb=new DB();try{mydb.doPstm(sql, params);ResultSet rs=mydb.getRs();for (int i = 0; i < (page - 1) * EVERYPAGENUM; i++) {rs.next();}for (int t = 0; t < EVERYPAGENUM; t++) {if (rs.next()) {Yuangong yuangong=new Yuangong();yuangong.setId(rs.getInt("id"));yuangong.setName(rs.getString("name"));yuangong.setSex(rs.getString("sex"));yuangong.setAge(rs.getString("age"));yuangong.setTel(rs.getString("tel"));yuangong.setAddress(rs.getString("address"));yuangong.setZhiwei(rs.getString("zhiwei"));yuangong.setQuanxian(rs.getInt("quanxian"));yuangong.setLoginName(rs.getString("loginName"));yuangong.setLoginPw(rs.getString("loginPw"));yuangongList.add(yuangong);} else {break; //减少空循环的时间}}rs.close();}catch(Exception e){e.printStackTrace();}mydb.closed();req.setAttribute("yuangongList", yuangongList);req.getRequestDispatcher("admin/yuangong/yuangongMana.jsp").forward(req, res);}public void yuangongQuanxian(HttpServletRequest req,HttpServletResponse res){int id=Integer.parseInt(req.getParameter("id"));int quanxian=Integer.parseInt(req.getParameter("quanxian"));String loginName=req.getParameter("loginName");String loginPw=req.getParameter("loginPw");String sql="update t_yuangong set quanxian=?,loginName=?,loginPw=? where id="+id;Object[] params={quanxian,loginName,loginPw};DB mydb=new DB();mydb.doPstm(sql, params);mydb.closed();req.setAttribute("message", "操作成功");req.setAttribute("path", "yuangong?type=yuangongMana");String targetURL = "/common/success.jsp";dispatch(targetURL, req, res);}public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) {RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);try {dispatch.forward(request, response);return;} catch (ServletException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}public void init(ServletConfig config) throws ServletException {super.init(config);}public void destroy() {}
}
4 效果演示
idea或eclipse开发,mysql数据库