package com.webtier;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.domain.GoodsForm;
import org.apache.struts.action.Action;
import com.dao.BigTypeDao;
import com.dao.GoodsDao;
import java.util.List;
import com.dao.SmallTypeDao;
import com.tool.Chinese;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
//商品的Action
public class GoodsAction
extends Action {
private int action;
private GoodsDao dao = null;
private BigTypeDao big=new BigTypeDao();
private SmallTypeDao small = new SmallTypeDao();
private HttpSession session = null;
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
UnsupportedEncodingException {
request.setCharacterEncoding("gb2312");
this.dao = new GoodsDao();
small = new SmallTypeDao();
action = Integer.parseInt(request.getParameter("action"));
session = request.getSession();
String ids=null;
switch (action) {
case 0: {
return goodSelect(mapping, form, request, response); //全部查询小类别信息
}
case 1: {
return goodForward(mapping, form, request, response); //转向页面
}
case 2: {
return selectSmallName(mapping, form, request, response); //查询小类别的名称
}
case 3: {
return saveGoods(mapping, form, request, response); //把从页面中信息存储在bean中
}
case 4: {
return insertGoods(mapping, form, request, response); //添加商品的信息
}
case 5: {
return selectOneGoods(mapping, form, request, response); //查看商品的详细信息
}
case 6: {
return deleteGoods(mapping, form, request, response); //删除商品信息
}
case 7: {
return goodSelectMark(mapping, form, request, response); // 按特价商品信息查询
}
case 8: {
return goodSelectSmall(mapping, form, request, response); //按小类别商品信息查询
}
case 9: {
return goodSelectBig(mapping, form, request, response); //按大类别商品信息查询
}
case 10: {
return managerFreePirceForward(mapping, form, request, response); //转向特价商品页面
}
case 11: {
return managerFreePirce(mapping, form, request, response); //设置特价价格
}
case 12: {
return goodSelectBigHead(mapping, form, request, response); //按大类别商品信息查询商品和商品小类别的名称
}
case 13: {
return goodSelectSmallHead(mapping, form, request, response); //按小类别商品信息查询商品和商品小类别的名称
}
case 14: {
return goodSelectNewHead(mapping, form, request, response); //新品查询
}
case 15: {
return goodSelectFreeHead(mapping, form, request, response); //特价商品
}
case 16: {
return goodSelectOneHead(mapping, form, request, response); //前台单独查询商品的信息
}
case 17:{
return goodUpdate(mapping,form,request,response);//修改商品信息
}
case 18:{
return goodUpdateForward(mapping, form, request, response);//根据id获取商品相关信息
}
}
GoodsForm goodsForm = (GoodsForm) form;
throw new java.lang.UnsupportedOperationException(
"Method $execute() not yet implemented.");
}
public ActionForward goodUpdate(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
GoodsForm gf=(GoodsForm)form;
gf.setName(Chinese.chinese(request.getParameter("goodsname")));
gf.setBig(Integer.valueOf(request.getParameter("bigType")));
gf.setSmall(Integer.valueOf(request.getParameter("smallType")));
gf.setId(Integer.parseInt((String)request.getParameter("id")));
int i=dao.UpdateGoods(gf);
if(i==1){
request.setAttribute("success", "商品信息修改成功");
}
return mapping.findForward("goodUpdaterSuccess");
}
public ActionForward goodUpdateForward(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
GoodsForm gf=dao.selectOneGoods(Integer.valueOf(request.getParameter("id")));
//将商品信息的ActionForm返回到视图
request.setAttribute("formforward", gf);
//将该商品的大类别与小类别的Actionform返回给视图
// request.setAttribute("bigTypeform", dao.selectBig(Integer.valueOf(gf.getBig())));
// request.setAttribute("smallTypeform", dao.selectSmall(Integer.valueOf(gf.getSmall())));
request.setAttribute("bigTypeAll", big.selectBig());
request.setAttribute("smallTypeAll", small.selectSmall());
return mapping.findForward("goodUpdaterequest");
}
// 前台单独查询商品的信息
public ActionForward goodSelectOneHead(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
request.setAttribute("form",dao.selectOneGoods(Integer.valueOf(request.getParameter("id"))));
return mapping.findForward("goodSelectOneHead");
}
//特价商品
public ActionForward goodSelectFreeHead(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
List list = null;
String mark = request.getParameter("mark");
list = dao.selectMark(Integer.valueOf(mark));
int pageNumber = list.size(); //计算出有多少条记录
int maxPage = pageNumber; //计算有多少页数
String number = request.getParameter("i");
if (maxPage % 4 == 0) {
maxPage = maxPage / 4;
}
else {
maxPage = maxPage / 4 + 1;
}
if (number == null) {
number = "0";
}
request.setAttribute("number", String.valueOf(number));
request.setAttribute("maxPage", String.valueOf(maxPage));
request.setAttribute("pageNumber", String.valueOf(pageNumber));
request.setAttribute("list", list);
return mapping.findForward("goodSelectFreeHead");
}
//新品查询
public ActionForward goodSelectNewHead(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
List list = null;
String mark = request.getParameter("mark");
list = dao.selectMark(Integer.valueOf(mark));
request.setAttribute("list", list);
return mapping.findForward("goodSelectNewHead");
}
//按小类别商品信息查询商品和商品小类别的名称
public ActionForward goodSelectSmallHead(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
List list = null;
list = dao.selectSmall(Integer.valueOf(request.getParameter("small")));
int pageNumber = list.size(); //计算出有多少条记录
int maxPage = pageNumber; //计算有多少页数
String number = request.getParameter("i");
if (maxPage % 4 == 0) {
maxPage = maxPage / 4;
}
else {
maxPage = maxPage / 4 + 1;
}
if (number == null) {
number = "0";
}
request.setAttribute("number", String.valueOf(number));
request.setAttribute("maxPage", String.valueOf(maxPage));
request.setAttribute("pageNumber", String.valueOf(pageNumber));
request.setAttribute("list", list);