<%@page contentType="text/html; charset=UTF-8"%>
<%@include file="/inc/init.jsp"%>
<%@include file="/inc/checklogin.jsp"%>
<%
	String action = pu.getString("action");
	String referer=pu.referer();
	Product_db pdb = new Product_db();
	int productid = pu.getInt("productid");
	//添加产品
	if (action.equals("add")) {
		String name = pu.getStringByNoChars("name");
		int classid = pu.getInt("classid");
		int isshow = pu.getInt("isshow");
		int sequence = pu.getInt("sequence");
		String price = pu.getString("price");
		String price2 = pu.getString("price2");
		int number = pu.getInt("number");
		String remark = pu.getString("remark");
		String create_time = new DateUtil().getCurTime();
		pdb.insert(name, classid, isshow, sequence, price, price2,
				number, remark, create_time);
		session.setAttribute("msg", "新产品 " + name + " 添加成功！");
		response.sendRedirect(referer);
		return;
	} else if (action.equals("edit")) {
		String name = pu.getStringByNoChars("name");
		int classid = pu.getInt("classid");
		int isshow = pu.getInt("isshow");
		int sequence = pu.getInt("sequence");
		String price = pu.getString("price");
		String price2 = pu.getString("price2");
		int number = pu.getInt("number");
		String remark = pu.getString("remark");
		pdb.update(productid, "name", name);
		pdb.update(productid, "classid", String.valueOf(classid));
		pdb.update(productid, "isshow", String.valueOf(isshow));
		pdb.update(productid, "sequence", String.valueOf(sequence));
		pdb.update(productid, "price", price);
		pdb.update(productid, "price2", price2);
		pdb.update(productid, "number", String.valueOf(number));
		pdb.update(productid, "remark", remark);
		session.setAttribute("msg", "产品 " + name + " 更新成功！");
		response.sendRedirect(referer);
		return;
	} else if (action.equals("del")) {
		DOC doc = pdb.getOne(productid);
		boolean isOk = false;
		if (DOCUtil.isFine(doc)) { //有内容才进去下一步骤
			String name = doc.get("name");
			int classid = doc.geti("classid");
			int isshow = doc.geti("isshow");
			int sequence = doc.geti("sequence");
			String price = doc.get("price");
			String price2 = doc.get("price2");
			int number = doc.geti("number");
			String remark = doc.get("remark");
			String create_time = doc.get("create_time");
			Product_reback pr = new Product_reback();
			isOk = pr.insert(productid, name, classid, isshow,sequence, price,
					price2, number, remark, create_time);
            doc=null;
			if (isOk) {
				pdb.delete(productid);
				session.setAttribute("msg", "产品 " + name + " 删除成功！");
				response.sendRedirect(referer);
				return;
			} else {
				session.setAttribute("msg", "产品 " + name + " 删除失败！");
				response.sendRedirect(referer);
				return;
			}
		} else {
			session.setAttribute("msg", "产品删除失败，请联系管理员！");
			response.sendRedirect(referer);
			return;
		}
	} else {
		response.sendRedirect(referer);
	}
%>