?? merchantgoodsaction.java
字號:
/*
* 作者:
* 時間:2007年11月28日
* 功能:庫存銷售管理->現有商品管理
* 查看管理現在商品的各種信息
*/
package com.mole.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mole.struts.bean.GoodsTypeBean;
import com.mole.struts.bean.MerchantGoodsBean;
import com.mole.struts.bean.Page;
import com.mole.struts.dao.MerchantGoodsDAO;
import com.mole.struts.form.MerchantGoodsForm;
/**
* MyEclipse Struts Creation date: 11-08-2007
*
* XDoclet definition:
*
* @struts.action path="/merchantGoods" name="merchantGoodsForm"
* input="/merchantGoods.jsp" scope="request" validate="true"
*/
public class MerchantGoodsAction extends Action {
// private String store;
/*
* Generated Methods
*/
/**
* Method execute
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String storeId = (String) request.getSession().getAttribute("store");
MerchantGoodsForm merchantGoodsForm = (MerchantGoodsForm) form;
MerchantGoodsDAO dao = new MerchantGoodsDAO();
String action = request.getParameter("action");
if (action == null || action.equals("new")) {// 獲取顯示現有商品的詳情的頁面
Page page = new Page();
int pageSize = (request.getParameter("pageSizeSelect") == null ? 10
: Integer.parseInt(request.getParameter("pageSizeSelect")));
int currentPage = (request.getParameter("page") == null ? 1
: Integer.parseInt(request.getParameter("page")));
int count = dao.getPageInfo(storeId, pageSize);
page.setPageSize(pageSize);
page.setRecordCount(count);
page.setPageCount((count + pageSize - 1) / pageSize);
page.setCurrentPage(currentPage);
ArrayList<MerchantGoodsBean> al = new ArrayList<MerchantGoodsBean>();
try {
al = dao.queryGoods(storeId, page.getCurrentPage(), page
.getPageSize());
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "用戶名或密碼錯誤,請重新登陸!");
session.setAttribute("returnUrl", "show.do?action=goLogin");
return mapping.findForward("goMessage");
}
request.setAttribute("merchantGoods", al);
request.setAttribute("Page", page);
return mapping.findForward("goMerchantGoods");
} else if (action.equals("modify")) {// 獲取修改現有商品的詳情的頁面
String id = request.getParameter("id");
MerchantGoodsBean bean = new MerchantGoodsBean();
try {
bean = dao.queryGoods(id);
} catch (Exception e) {
e.printStackTrace();
}
request.getSession().setAttribute("GoodsId", id);
request.setAttribute("merchantGoods", bean);
ArrayList<GoodsTypeBean> al = null;
try {
al = dao.queryGoodsType(storeId);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "用戶名或密碼錯誤,請重新登陸!");
session.setAttribute("returnUrl",
"show.do?action=goMerchantGoodsModify");
return mapping.findForward("goMessage");
}
request.setAttribute("goodsType", al);
return mapping.findForward("goMerchantGoodsModify");
} else if (action.equals("add")) {// 獲取添加現有商品的詳情的頁面
ArrayList<GoodsTypeBean> al = null;
try {
al = dao.queryGoodsType(storeId);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "用戶名或密碼錯誤,請重新登陸!");
session.setAttribute("returnUrl",
"show.do?action=goMerchantGoodsAdd");
return mapping.findForward("goMessage");
}
request.setAttribute("goodsType", al);
return mapping.findForward("goMerchantGoodsAdd");
} else if (action.equals("delete")) {// 刪除一條現有商品的信息
String sql = "DELETE FROM [Goods] WHERE [ID]="
+ request.getParameter("id");
dao.executeUpdate(sql);
return new ActionForward("/merchantGoods.do?action=new");
} else if (action.equals("onAdd")) {// 添加一條現有商品信息
MerchantGoodsBean merchantGoods = new MerchantGoodsBean();
merchantGoods.setStoreId(storeId);
merchantGoods.setGoodsNumber(merchantGoodsForm.getGoodsNumber());
merchantGoods.setName(merchantGoodsForm.getName());
merchantGoods.setGoodsType(merchantGoodsForm.getGoodsType());
merchantGoods.setPrice(merchantGoodsForm.getPrice());
merchantGoods.setDescription(merchantGoodsForm.getDescription());
merchantGoods.setCommend(merchantGoodsForm.getCommend());
try {
dao.insertGoods(merchantGoods);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "用戶名或密碼錯誤,請重新登陸!");
session.setAttribute("returnUrl",
"show.do?action=goMerchantGoodsAdd");
return mapping.findForward("goMessage");
}
return new ActionForward("/merchantGoods.do?action=new");
} else if (action.equals("onModify")) {// 修改一條現有商品的信息
MerchantGoodsBean merchantGoods = new MerchantGoodsBean();
merchantGoods.setId(merchantGoodsForm.getId());
merchantGoods.setStoreId(storeId);
merchantGoods.setGoodsNumber(merchantGoodsForm.getGoodsNumber());
merchantGoods.setName(merchantGoodsForm.getName());
merchantGoods.setGoodsType(merchantGoodsForm.getGoodsType());
merchantGoods.setPrice(merchantGoodsForm.getPrice());
merchantGoods.setImage(merchantGoodsForm.getImage());
merchantGoods.setDescription(merchantGoodsForm.getDescription());
merchantGoods.setCommend(merchantGoodsForm.getCommend());
try {
dao.updateGoods(merchantGoods);
} catch (Exception e) {
e.printStackTrace();
HttpSession session = request.getSession();
session.setAttribute("title", "錯誤信息");
session.setAttribute("message", "提交數據庫失敗!");
session.setAttribute("returnUrl",
"show.do?action=goMerchantGoodsModify");
return mapping.findForward("goMessage");
}
return new ActionForward("/merchantGoods.do?action=new");
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -