package com.lyq.struts.action;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.lyq.dao.MedicineDao;
import com.lyq.dao.SellDao;
import com.lyq.persistence.Medicine;
import com.lyq.persistence.SellDetail;
import com.lyq.persistence.User;
import com.lyq.struts.form.SellDetailForm;
/**
* 销售Action类
* @author Li Yong Qiang
*/
public class SellAction extends BaseAction {
//向购物车中添加药品
public ActionForward order(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//获取SellDetailForm
SellDetailForm sdf = (SellDetailForm) form;
if (sdf != null && sdf.getSellPrice() > 0 && sdf.getMedId() > 0) {
MedicineDao medDao = new MedicineDao();
//加载药品信息
Medicine med = medDao.loadMedicine(sdf.getMedId());
//如果购买的数量小于库存数量,进行错误处理
if (med.getMedCount() < sdf.getSellCount()) {
ActionMessages errors = new ActionMessages();
ActionMessage message = new ActionMessage("drug.drugCount.error", "");
errors.add("", message);
this.saveErrors(request, errors);
return mapping.findForward("error");
}
sdf.setSellTime(new Date());
//计算总价
double sum = sdf.getSellPrice() * sdf.getSellCount();
sdf.setTotal(sum);
HttpSession session = request.getSession();
// 获取订单
List list = (List) session.getAttribute("order");
List meds = new ArrayList(); // 实例化一个List对象
if (list == null) {
sdf.setId(1);
} else {
int i = 1;
// 迭代已添加的药品
for (; i <= list.size(); i++) {
SellDetailForm temp = (SellDetailForm) list.get(i - 1);
temp.setId(i);
sum += temp.getTotal(); //计算总价格
meds.add(temp);
}
sdf.setId(i);
}
meds.add(sdf);
// 将总价保存到session之中
session.setAttribute("sum", new Double(sum));
// 将新的订单保存到session之中
session.setAttribute("order", meds);
}
return mapping.findForward("order");
}
//选购药品
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
SellDetailForm sdf = (SellDetailForm) form;
if (sdf.getId() > 0) {
MedicineDao medDao = new MedicineDao();
Medicine med = medDao.loadMedicine(sdf.getId());
sdf.setMedId(med.getId());
sdf.setSellName(med.getName());
sdf.setSellPrice(med.getPrice());
sdf.setSellCount(1);
sdf.setFactoryAdd(med.getFactoryAdd());
}
return mapping.findForward("add");
}
//结账购物车中的药品
public ActionForward buy(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
//获取购物车中所有药品
List list = (List) session.getAttribute("order");
if (list != null && list.size() > 0) {
try {
SellDao dao = new SellDao();
MedicineDao medDao = new MedicineDao();
//获取当前操作员(用户)
User user = (User) request.getSession().getAttribute("user");
//通过循环进行结账
for (int i = 0; i < list.size(); i++) {
SellDetailForm sdf = (SellDetailForm) list.get(i);
//加载药品信息
Medicine med = medDao.loadMedicine(sdf.getMedId());
int dCount = med.getMedCount();
int sCount = sdf.getSellCount();
//如果库存中数量足够,进行结账,否则进行错误处理
if (dCount >= sCount) {
SellDetail sd = new SellDetail();
sd.setSellCount(sdf.getSellCount());
sd.setSellName(sdf.getSellName());
sd.setSellPrice(sdf.getSellPrice());
sd.setSellTime(new Date());
sd.setMed(med);
sd.setUser(user);
//保存销售明细
dao.saveSellDetail(sd);
//更新库库存信息
med.setMedCount(dCount - sCount);
medDao.saveOrUpdate(med);
} else {
ActionMessages errors = new ActionMessages();
ActionMessage message = new ActionMessage(
"drug.drugCount.error", "");
errors.add("", message);
this.saveErrors(request, errors);
return mapping.findForward("error");
}
}
} finally {
session.removeAttribute("order");
session.removeAttribute("sum");
}
}
return mapping.findForward("paging");
}
//分页查询销售明细
public ActionForward paging(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//获取当前页码
String currPage = request.getParameter("currPage");
String action = request.getContextPath()
+ "/sell/sell.do?command=paging";
String hql = "from SellDetail s order by s.sellTime desc";
//分页查询
Map map = this.getPage(hql, recPerPage, currPage, action, null);
//将结果集放到request中
request.setAttribute("list", map.get("list"));
//将结果集放到分页条中
request.setAttribute("pagingBar", map.get("bar"));
return mapping.findForward("findAllSuccess");
}
//删除购物车中指定的药品
public ActionForward deleteOrder(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//获取id
String id = request.getParameter("id");
if (id != null && !id.isEmpty()) {
HttpSession session = request.getSession();
//获取购物车
List order = (List) session.getAttribute("order");
List list = null;
if (order != null) {
//获取总额
double sum = ((Double) session.getAttribute("sum"))
.doubleValue();
//创建新的购物车对象
list = new ArrayList();
for (int i = 0; i < order.size(); i++) {
SellDetailForm sdf = (SellDetailForm) order.get(i);
if (!id.equals(String.valueOf(sdf.getId()))) {
list.add(sdf);
} else {
sum -= sdf.getTotal();
}
}
session.setAttribute("order", list);
session.setAttribute("sum", new Double(sum));
}
}
return mapping.findForward("order");
}
//模糊查询,分页显示
public ActionForward blurQuery(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//获取关键词
String keyWord = request.getParameter("keyWord");
String action = request.getContextPath()
+ "/sell/sell.do?command=blurQuery";
//HQL查询语句
String hql = "from SellDetail s";
//获取当前页码
String currPage = request.getParameter("currPage");
Object[] where = null;
// 转码
if (currPage != null && !currPage.isEmpty()) {
keyWord = new String(keyWord.getBytes("iso-8859-1"), "gbk");
}
if (keyWord != null && !keyWord.isEmpty()) {
action += "&keyWord=" + keyWord;
keyWord = "%" + keyWord + "%";
hql += " where s.sellName like ?";
where = new Object[] { keyWord };
}
//分页查询
Map map = this.getPage(hql, recPerPage, currPage, action, where);
//将结果集放到request中
request.setAttribute("list", map.get("list"));
//将结果集放到分页条中
request.setAttribute("pagingBar", map.get("bar"));
return mapping.findForward("findAllSuccess");
}
// 清空订单
public ActionForward clear(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
session.removeAttribute("sum");
session.removeAttribute("order");
return mapping.findForward("order");
}
// 查询指定时间段的销售明细
public ActionForward today(ActionMapping mapping, ActionForm
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java web的医药管理系统(源码+数据库).zip
共164个文件
jsp:31个
java:30个
class:30个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 24 浏览量
2023-01-25
00:43:51
上传
评论
收藏 9.37MB ZIP 举报
温馨提示
使用说明:把源码导入Java ee工具,导入MySQL数据库sql脚本,修改数据库连接语句,调试运行即可。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java web的医药管理系统(源码+数据库).zip (164个子文件)
SellAction.class 10KB
MedicineAction.class 9KB
RequireAction.class 7KB
SystemAction.class 5KB
BaseAction.class 5KB
CategoryAction.class 5KB
UserDao.class 4KB
SupperDao.class 3KB
MedicineForm.class 3KB
Medicine.class 3KB
QueryUtil.class 3KB
HibernateFilter.class 3KB
SellDao.class 2KB
MedicineDao.class 2KB
ChartUtil.class 2KB
SellDetail.class 2KB
SellDetailForm.class 2KB
LoginAction.class 2KB
DeleteReqMedAction.class 2KB
DeleteMedicineAction.class 2KB
CategoryDao.class 2KB
Category.class 2KB
LanguageAction.class 2KB
CharacterEncodingFilter.class 2KB
DeleteAction.class 2KB
UserForm.class 2KB
StringUtil.class 1KB
SellSeq.class 1KB
CategoryForm.class 1KB
User.class 1KB
.classpath 2KB
org.eclipse.wst.common.component 483B
org.eclipse.wst.jsdt.ui.superType.container 49B
styles.css 1KB
hibernate3.jar 2.15MB
jfreechart-1.0.14.jar 1.39MB
xerces-2.6.2.jar 987KB
mysql.jar 699KB
struts.jar 537KB
javassist.jar 460KB
antlr-2.7.6.jar 433KB
log4j-1.2.11.jar 342KB
dom4j-1.6.1.jar 307KB
jcommon-1.0.17.jar 303KB
cglib-2.1.3.jar 276KB
jaxen-1.1-beta-7.jar 222KB
ehcache-1.2.3.jar 203KB
xml-apis.jar 191KB
commons-beanutils-1.7.0.jar 184KB
commons-collections-2.1.1.jar 171KB
commons-digester.jar 164KB
commons-validator-1.3.1.jar 136KB
jaas.jar 102KB
jakarta-oro.jar 64KB
commons-fileupload-1.2.1.jar 56KB
commons-logging-1.0.4.jar 37KB
asm.jar 26KB
asm-attrs.jar 16KB
jta.jar 9KB
jdbc2_0-stdext.jar 7KB
SellAction.java 10KB
MedicineAction.java 10KB
RequireAction.java 7KB
SystemAction.java 5KB
BaseAction.java 5KB
SupperDao.java 4KB
CategoryAction.java 4KB
UserDao.java 4KB
QueryUtil.java 2KB
MedicineForm.java 2KB
MedicineDao.java 2KB
Medicine.java 2KB
CategoryDao.java 2KB
SellDao.java 2KB
ChartUtil.java 2KB
HibernateFilter.java 2KB
SellDetailForm.java 2KB
SellDetail.java 1KB
DeleteMedicineAction.java 1KB
DeleteReqMedAction.java 1KB
LanguageAction.java 1KB
LoginAction.java 1KB
UserForm.java 1KB
StringUtil.java 1KB
Category.java 1KB
CharacterEncodingFilter.java 1KB
DeleteAction.java 1KB
CategoryForm.java 919B
SellSeq.java 795B
User.java 774B
login_zh.jpg 276KB
login_en.jpg 276KB
top1.jpg 93KB
top3.jpg 37KB
m1.jpg 19KB
top2.jpg 14KB
title_bg1.jpg 13KB
bottom.jpg 13KB
top_bg1.jpg 13KB
.jsdtscope 580B
共 164 条
- 1
- 2
资源评论
等天晴i
- 粉丝: 3777
- 资源: 10万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功