⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 merchantgoodsaction.java

📁 基于struts的网上商店源码
💻 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 + -