基于javaweb+mysql的ssh超市进销存管理系统超市管理系统(java+hibernate+struts+jsp+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSH超市进销存管理系统超市管理系统(java+hibernate+struts+jsp+mysql)
管理员:
admin/123456
员工:
emp0001 123456
emp0002 123456
emp003 123456
/**
* 根据主键查询
* @param empNo
* @return
*/
public EmployeeInfo GetEmployee(String empNo) {
Session s = null;
try {
s = HibernateUtil.getSession();
EmployeeInfo emp = (EmployeeInfo)s.get(EmployeeInfo.class, empNo);
return emp;
} finally {
HibernateUtil.closeSession();
}
}
}
/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateUtil {
/**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
}
public void setGoodUnit(String goodUnit) {
this.goodUnit = goodUnit;
}
public String getGoodModel() {
return this.goodModel;
}
public void setGoodModel(String goodModel) {
this.goodModel = goodModel;
}
public String getGoodSpecs() {
return this.goodSpecs;
}
public void setGoodSpecs(String goodSpecs) {
this.goodSpecs = goodSpecs;
}
public Double getGoodPrice() {
return this.goodPrice;
}
public void setGoodPrice(Double goodPrice) {
this.goodPrice = goodPrice;
}
public String getGoodPlace() {
return this.goodPlace;
}
public void setGoodPlace(String goodPlace) {
this.goodPlace = goodPlace;
}
public String getGoodMemo() {
return this.goodMemo;
}
public void setGoodMemo(String goodMemo) {
this.goodMemo = goodMemo;
}
this.employeeName = employeeName;
this.employeePassword = employeePassword;
}
// Property accessors
public String getEmployeeNo() {
return this.employeeNo;
}
public void setEmployeeNo(String employeeNo) {
this.employeeNo = employeeNo;
}
public String getEmployeeName() {
return this.employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmployeePassword() {
return this.employeePassword;
}
public void setEmployeePassword(String employeePassword) {
this.employeePassword = employeePassword;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
else
goodInfoPageFootStr += " 首页 ";
if(currentPage>1)
goodInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + prev + ";document.queryForm.submit();' href='#'"+">上页</A> ";
else
goodInfoPageFootStr += " 上一页 ";
if(currentPage<totalPage)
goodInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + next + ";document.queryForm.submit();' href='#'"+">下页</A> ";
else
goodInfoPageFootStr += " 下一页 ";
if(totalPage>1&¤tPage!=totalPage)
goodInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + totalPage + ";document.queryForm.submit();' href='#'"+">尾页</A> ";
else
goodInfoPageFootStr += " 尾页 ";
goodInfoPageFootStr+="第<input name=currentPage type=text size=2>页 <input type=submit value=GO>" ;
return goodInfoPageFootStr;
}
//查询商品分类
public String QueryGoodsClassInfo() {
goodsClassList=goodsDao.QueryGoodsClassInfo();
return SUCCESS;
}
//新增商品
public String AddGoods(){
QueryGoodsClassInfo();
return SUCCESS;
}
//保存商品
public String SaveGoods(){
GoodInfo goodInfo=new GoodInfo();
goodInfo.setGoodClassId(goodClassId);
goodInfo.setGoodMemo(goodMemo);
goodInfo.setGoodModel(goodModel);
goodInfo.setGoodName(goodName);
goodInfo.setGoodNo(goodNo);
goodInfo.setGoodPlace(goodPlace);
goodInfo.setGoodPrice(goodPrice);
goodInfo.setGoodSpecs(goodSpecs);
goodInfo.setGoodUnit(goodUnit);
goodInfo.setIsSpecial(isSpecial);
try {
goodsDao.SaveGoods(goodInfo);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
//保存商品分类
public String AddGoodsClassInfo() {
GoodClassInfo goodClassInfo=new GoodClassInfo();
<%} %>
</tr>
<tr>
<td align="center"><IMG src='../image/title.jpg'></td>
</tr>
</table>
<%@page contentType="text/html;charset=GBK" %>
<%@page import="java.util.ArrayList" %>
<%@page import="com.zdn.domain.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<link href="../css/style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<%
GoodInfo goodInfo=(GoodInfo)request.getAttribute("goodInfo");
boolean isUpdate=goodInfo!=null;
%>
<form method="post" name="theForm" onsubmit="return checkGoodAddForm(theForm);" action="SaveGoods.action">
<table width=600 border=0 cellpadding=0 cellspacing=0 align="center">
<tr style="color:blue;font-size:14px;">
<td style="height: 14px">
</tr>
<tr>
<td style="height: 26px">
<input type=text name="GoodNo" size=20 value="<%=isUpdate?goodInfo.getGoodNo():"" %>" <%if(isUpdate){ %>readonly<%} %>/>
<br/>
<select name="GoodClassId">
<%
ArrayList<GoodClassInfo> goodsClassList = (ArrayList<GoodClassInfo>)request.getAttribute("goodsClassList");
for(int i=0;i<goodsClassList.size();i++) {
GoodClassInfo goodsClass = (GoodClassInfo)goodsClassList.get(i);
%>
<option value="<%=goodsClass.getGoodClassId()%>" <%if(isUpdate&&goodInfo.getGoodClassId().equals(goodsClass.getGoodClassId())){ %>selected<%} %>><%=goodsClass.getGoodClassName() %></option>
}
public class EmployeeDao {
private final int PAGE_SIZE = 5;
/*验证用户登录*/
public boolean CheckLogin(String userName,String password) {
Session s = null;
try {
s = HibernateUtil.getSession();
EmployeeInfo employee = (EmployeeInfo)s.get(EmployeeInfo.class, userName);
if(employee == null) {
return false;
} else if( !employee.getEmployeePassword().equals(password)) {
return false;
}
} finally {
HibernateUtil.closeSession();
}
return true;
}
/**
* 添加用户
* @param employee
* @throws Exception
*/
public void AddEmployee(EmployeeInfo employee) throws Exception {
Session s = null;
Transaction tx = null;
try {
s = HibernateUtil.getSession();
tx = s.beginTransaction();
s.saveOrUpdate(employee);
tx.commit();
} catch (HibernateException e) {
if(tx != null)
tx.rollback();
return occurdate;
}
public void setOccurdate(String occurdate) {
this.occurdate = occurdate;
}
public int getSellnum() {
return sellnum;
}
public void setSellnum(int sellnum) {
this.sellnum = sellnum;
}
public int getBuynum() {
return buynum;
}
public void setBuynum(int buynum) {
this.buynum = buynum;
}
public String getGoodname() {
return goodname;
}
public void setGoodname(String goodname) {
this.goodname = goodname;
}
}
/**
*/
/*当前的总页码*/
private int totalPage;
private String goodNo;
private String goodName;
private String supplierName;
private double price;
private int number;
private double totalPrice;
private Timestamp buyDate;
private String fromDate;
private String toDate;
private GoodsDao goodsDao = new GoodsDao();
private BuyDao buyDao = new BuyDao();
private StockDao stockDao=new StockDao();
private List<GoodInfo> goodList;
private List<BuyInfo> buyList;
String pageFootStr;
//新增商品进货信息-查询商品
public String AddBuyInfo(){
QueryGoodInfo();
return SUCCESS;
}
//保存商品进货信息
public String SaveBuyInfo(){
BuyInfo buyInfo=new BuyInfo();
buyInfo.setBuyDate(buyDate);
buyInfo.setGoodNo(goodNo);
buyInfo.setNumber(number);
buyInfo.setPrice(price);
buyInfo.setSupplierName(supplierName);
buyInfo.setTotalPrice(totalPrice);
GoodStockInfo stock=stockDao.GetStock(goodNo);
if(stock==null)
stock=new GoodStockInfo();
stock.setGoodNo(goodNo);
stock.setGoodCount(number+stock.getGoodCount().intValue());
try {
buyDao.SaveBuyInfo(buyInfo,stock);
//stockDao.AddStock(stock);
} catch (Exception e) {
e.printStackTrace();
}
Session s = null;
try {
s = HibernateUtil.getSession();
String hql = "from GoodStockInfo s where 1=1";
if(!goodNo.equals("")) {
hql += " and s.goodNo='"+goodNo+"'" ;
}
if(!goodName.equals("")) {
hql += " and s.goodInfo.goodName='"+goodName+"'" ;
}
Query q = s.createQuery(hql);
int recordCount = q.list().size();
int mod = recordCount % this.PAGE_SIZE;
int totalPage = recordCount / this.PAGE_SIZE;
if(mod != 0) totalPage++;
return totalPage;
} finally {
HibernateUtil.closeSession();
}
}
@SuppressWarnings("unchecked")
public List<GoodStockInfo> QueryStockInfo(String goodNo, String goodName,
int currentPage) {
Session s = null;
try {
s = HibernateUtil.getSession();
String hql = "from GoodStockInfo s where 1=1";
if(!goodNo.equals("")) {
hql += " and s.goodNo='"+goodNo+"'" ;
}
if(!goodName.equals("")) {
hql += " and s.goodInfo.goodName='"+goodName+"'" ;
}
Query q = s.createQuery(hql);
/*计算当前显示页码的开始记录*/
int startIndex = (currentPage-1) * this.PAGE_SIZE;
q.setFirstResult(startIndex);
q.setMaxResults(this.PAGE_SIZE);
List<GoodStockInfo> stockInfoList = q.list();
return stockInfoList;
} finally {
HibernateUtil.closeSession();
}
}
/**
* 更新库存
* @param stock
* @throws Exception
return sellInfoPageFootStr;
}
private void QueryGoodInfo() {
goodList=goodsDao.QueryGoodInfo("","",-1,1);
}
public List<GoodInfo> getGoodList() {
return goodList;
}
public void setGoodList(List<GoodInfo> goodList) {
this.goodList = goodList;
}
public String getGoodNo() {
return goodNo;
}
public void setGoodNo(String goodNo) {
this.goodNo = goodNo;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double totalPrice) {
this.totalPrice = totalPrice;
}
public Timestamp getSellDate() {
return sellDate;
}
public void setSellDate(Timestamp sellDate) {
this.sellDate = sellDate;
}
public int getCurrentPage() {
return currentPage;
public String getGoodname() {
return goodname;
}
public void setGoodname(String goodname) {
this.goodname = goodname;
}
}
/**
*/
public class GoodStockInfo implements java.io.Serializable {
// Fields
private String goodNo;
private Integer goodCount=0;
private GoodInfo goodInfo;
// Constructors
/** default constructor */
public GoodStockInfo() {
}
/** minimal constructor */
public GoodStockInfo(String goodNo) {
this.goodNo = goodNo;
}
/** full constructor */
public GoodStockInfo(String goodNo, Integer goodCount) {
this.goodNo = goodNo;
this.goodCount = goodCount;
}
// Property accessors
public String getGoodNo() {
return this.goodNo;
}
public void setGoodNo(String goodNo) {
/**
*/
public class VYearProiftId implements java.io.Serializable {
// Fields
private String occurdate;
private int sellnum;
private int buynum;
private String goodname;
// Constructors
/** default constructor */
public VYearProiftId() {
}
/** full constructor */
public VYearProiftId(String occurdate, String goodname,int sellnum,int buynum) {
this.occurdate = occurdate;
this.goodname = goodname;
this.sellnum=sellnum;
this.buynum=buynum;
}
public String getOccurdate() {
return occurdate;
}
public void setOccurdate(String occurdate) {
this.occurdate = occurdate;
}
public int getSellnum() {
return sellnum;
}
public void setSellnum(int sellnum) {
this.sellnum = sellnum;
}
@SuppressWarnings("unchecked")
public List<GoodStockInfo> QueryStockInfo(String goodNo, String goodName,
int currentPage) {
Session s = null;
try {
s = HibernateUtil.getSession();
String hql = "from GoodStockInfo s where 1=1";
if(!goodNo.equals("")) {
hql += " and s.goodNo='"+goodNo+"'" ;
}
if(!goodName.equals("")) {
hql += " and s.goodInfo.goodName='"+goodName+"'" ;
}
Query q = s.createQuery(hql);
/*计算当前显示页码的开始记录*/
int startIndex = (currentPage-1) * this.PAGE_SIZE;
q.setFirstResult(startIndex);
q.setMaxResults(this.PAGE_SIZE);
List<GoodStockInfo> stockInfoList = q.list();
return stockInfoList;
} finally {
HibernateUtil.closeSession();
}
}
/**
* 更新库存
* @param stock
* @throws Exception
*/
public void AddStock(GoodStockInfo stock) throws Exception {
Session s = null;
Transaction tx = null;
try {
s = HibernateUtil.getSession();
tx = s.beginTransaction();
s.saveOrUpdate(stock);
tx.commit();
} catch (HibernateException e) {
if(tx != null)
tx.rollback();
throw e;
} finally {
HibernateUtil.closeSession();
}
}
/**
}
Query q = s.createQuery(hql);
/*计算当前显示页码的开始记录*/
int startIndex = (currentPage-1) * this.PAGE_SIZE;
q.setFirstResult(startIndex);
q.setMaxResults(this.PAGE_SIZE);
List<GoodInfo> goodInfoList = q.list();
return goodInfoList;
} finally {
HibernateUtil.closeSession();
}
}
/**
* 根据主键查询商品
* @param goodNo
* @return
*/
public GoodInfo GetGoodsInfo(String goodNo) {
Session s = null;
try {
s = HibernateUtil.getSession();
GoodInfo goods = (GoodInfo)s.get(GoodInfo.class, goodNo);
return goods;
} finally {
HibernateUtil.closeSession();
}
}
/**
* 删除商品
* @param goodNo
*/
public void DeleteGoodsInfo(String goodNo) {
Session s = null;
Transaction tx = null;
try {
s = HibernateUtil.getSession();
tx = s.beginTransaction();
Object goodInfo = s.load(GoodInfo.class, goodNo);
s.delete(goodInfo);
tx.commit();
} catch (HibernateException e) {
if(tx != null)
tx.rollback();
throw e;
} finally {
HibernateUtil.closeSession();
}
}
}
return SUCCESS;
}
public String QuerySellInfo(){
if(currentPage == 0) currentPage = 1;
if(goodNo==null)goodNo="";
if(goodName==null)goodName="";
setTotalPage(sellDao.CalculateTotalPage(goodNo,goodName,fromDate,toDate));
sellList = sellDao.QuerySellInfo(goodNo,goodName,fromDate,toDate,currentPage);
pageFootStr = this.MakeSellInfoPageFootStr();
return SUCCESS;
}
private String MakeSellInfoPageFootStr() {
String sellInfoPageFootStr = "";
int next, prev;
prev=currentPage-1;
next=currentPage+1;
sellInfoPageFootStr += " 共<span>"+ totalPage+"</span>页";
sellInfoPageFootStr +=" 第<span>"+currentPage+"</span>页 ";
if(currentPage>1)
//pageFootStr += " <A href=" + actionPath + "¤tPage=1"+">首页</A> ";
sellInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=1;document.queryForm.submit();' href='#'"+">首页</A> ";
else
sellInfoPageFootStr += " 首页 ";
if(currentPage>1)
sellInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + prev + ";document.queryForm.submit();' href='#'"+">上页</A> ";
else
sellInfoPageFootStr += " 上一页 ";
if(currentPage<totalPage)
sellInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + next + ";document.queryForm.submit();' href='#'"+">下页</A> ";
else
sellInfoPageFootStr += " 下一页 ";
if(totalPage>1&¤tPage!=totalPage)
sellInfoPageFootStr += " <A onclick='document.queryForm.currentPage.value=" + totalPage + ";document.queryForm.submit();' href='#'"+">尾页</A> ";
else
sellInfoPageFootStr += " 尾页 ";
sellInfoPageFootStr+="第<input name=currentPage type=text size=2>页 <input type=submit value=GO>" ;
return sellInfoPageFootStr;
}
private void QueryGoodInfo() {
goodList=goodsDao.QueryGoodInfo("","",-1,1);
}
public List<GoodInfo> getGoodList() {
return goodList;
}
public void setGoodList(List<GoodInfo> goodList) {
this.goodList = goodList;
}
public String getGoodNo() {
return goodNo;
}
public void setGoodNo(String goodNo) {
this.employeeName = employeeName;
this.employeePassword = employeePassword;
}
// Property accessors
public String getEmployeeNo() {
return this.employeeNo;
}
public void setEmployeeNo(String employeeNo) {
this.employeeNo = employeeNo;
}
public String getEmployeeName() {
return this.employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmployeePassword() {
return this.employeePassword;
}
public void setEmployeePassword(String employeePassword) {
this.employeePassword = employeePassword;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
/**
* 进货登记
*
*/
public class BuyDao {
private final int PAGE_SIZE = 5;
//保存进货登记信息
public void SaveBuyInfo(BuyInfo buyInfo,GoodStockInfo stock) throws Exception {
Session s = null;
Transaction tx = null;
try {
s = HibernateUtil.getSession();
tx = s.beginTransaction();
s.save(buyInfo);
s.saveOrUpdate(stock);
tx.commit();
} catch (HibernateException e) {
if(tx != null)
tx.rollback();
throw e;
} finally {
HibernateUtil.closeSession();
}
}
@SuppressWarnings("unchecked")
public List<BuyInfo> QueryBuyInfo(String goodNo, String goodName,
String fromDate, String toDate, int currentPage) {
Session s = null;
try {
s = HibernateUtil.getSession();
String hql = "from BuyInfo b where 1=1";
if(!goodNo.equals("")) {
hql += " and b.goodNo='"+goodNo+"'" ;
}
if(!goodName.equals("")) {