<%@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_class_db pcdb = new Product_class_db();
	int classid = pu.getInt("classid");
	String name = pu.getStringByNoChars("name");
	String createtime=new DateUtil().getCurTime();
	String showname = pu.getString("companyname");
	String producturl=pu.getString("producturl");
	String retain1=pu.getString("retain1");
	String retain2=pu.getString("retain2");
	String retain3=pu.getString("retain3");//备注信息
	String retain4=pu.getString("retain4");
	String retain5=pu.getString("retain5");
	String retain6=pu.getString("retain6");
	String retain7=pu.getString("retain7");
	String retain8=pu.getString("retain8");
	String retain9=pu.getString("retain9");
	String retain10=pu.getString("retain10");
	//添加产品
	if (action.equals("add")) {
		pcdb.insert(name,createtime,showname,producturl,retain1,retain2,retain3,retain4,retain5,retain6,"","","","");
		session.setAttribute("msg", "产品分类 " + name + " 添加成功！");
		response.sendRedirect(referer);
		return;
	} else if (action.equals("edit")) {
		pcdb.update(classid, "name",name);
		pcdb.update(classid, "showname",showname);
		pcdb.update(classid, "producturl",producturl);
		pcdb.update(classid, "retain1",retain1);
		pcdb.update(classid, "retain2",retain2);
		pcdb.update(classid, "retain3",retain3);
		pcdb.update(classid, "retain4",retain4);
		pcdb.update(classid, "retain5",retain5);
		pcdb.update(classid, "retain6",retain6);
		pcdb.update(classid, "retain7",retain7);
		pcdb.update(classid, "retain8",retain8);
		pcdb.update(classid, "retain9",retain9);
		pcdb.update(classid, "retain10",retain10);
		session.setAttribute("msg", "产品分类 " + name + " 更新成功！");
		response.sendRedirect(referer);
		return;
	} else if (action.equals("del")) { //删除分类
		DOC doc = pcdb.getOne(classid);
		boolean isOk = false;
		if (DOCUtil.isFine(doc)) { //有内容才进去下一步骤
			String name2 = doc.get("name");
			String create_time = doc.get("create_time");
			Product_class_reback_db pcrdb = new Product_class_reback_db();
			isOk = pcrdb.insert(classid, name2, create_time);
		}
		doc = null;
		if (isOk) {
			pcdb.delete(classid);
			session.setAttribute("msg", "产品分类删除成功！");
			response.sendRedirect(referer);
			return;
		} else {
			session.setAttribute("msg", "产品分类 " + classid + " 删除失败！");
			response.sendRedirect(referer);
			return;
		}
	}
%>