📄 addbuyproductaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package cn.bway.foreigntrade.repertory.buyproduct.action;
import java.sql.Connection;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.bway.common.WebConstant;
import cn.bway.common.action.BaseAction;
import cn.bway.common.code.codeDao;
import cn.bway.common.dao.HibernateSessionFactory;
import cn.bway.common.vo.PageListVO;
import cn.bway.foreigntrade.operation.productmanage.impl.ProductmanageManagerFactory;
import cn.bway.foreigntrade.operation.productmanage.model.Productmanage;
import cn.bway.foreigntrade.reperstory.product.impl.ProductManagerFactory;
import cn.bway.foreigntrade.reperstory.product.model.Product;
import cn.bway.foreigntrade.repertory.buyproduct.form.BuyproductForm;
import cn.bway.foreigntrade.repertory.buyproduct.impl.BuyproductManagerFactory;
import cn.bway.foreigntrade.repertory.buyproduct.model.Buyproduct;
/**
* MyEclipse Struts
* Creation date: 03-12-2008
*
* XDoclet definition:
* @struts.action path="/addExportclient" name="buyproductForm" scope="request" validate="true"
*/
public class AddBuyproductAction extends BaseAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
BuyproductForm eForm = (BuyproductForm) form;// TODO Auto-generated method stub
ActionErrors errors = new ActionErrors();
Session sess =null;
Transaction tx =null;
String returnStr = null;
Connection conn = null;
PageListVO rvo = null;
try {
request.setCharacterEncoding("utf-8");
//增加采购材料
Buyproduct exp=new Buyproduct();
exp.setBuydocumentid(eForm.getBuydocumentid());
exp.setSpecs(eForm.getSpecs());
exp.setColors(eForm.getColors());
exp.setTotals(eForm.getTotals());
exp.setTotalprice(eForm.getTotalprice());
exp.setNotes(eForm.getNotes());
exp.setSimpleprice(eForm.getSimpleprice());
exp.setPicurl(eForm.getPicurl());
exp.setProductid(eForm.getProductid());
BuyproductManagerFactory.getBuyproductManager().addBuyproduct(exp);
//查找产品
Productmanage pro=(Productmanage) ProductmanageManagerFactory.getProductmanageManager().getProductmanage(eForm.getProductid());
Product product=new Product();
//判断库存是否存在该产品
rvo=(PageListVO) ProductManagerFactory.getProductManager().queryProduct("材料仓库",pro.getId());
ArrayList ListResult= (ArrayList) rvo.getretVO();
if(ListResult.size()<1){//不存在
//增加库存
product.setCodes(""+pro.getId());
product.setNames(pro.getNames());
product.setPrice(pro.getPrice());
product.setSpec(pro.getSpec());
product.setCraftwork(pro.getCraftwork());
product.setColor(pro.getColor());
product.setStuff(pro.getStuff());
product.setProvide(pro.getProvide());
product.setProductionperiod(pro.getProductionperiod());
product.setQc(pro.getQc());
product.setTypes("材料仓库");
product.setNumbers(eForm.getTotals());
ProductManagerFactory.getProductManager().addProduct(product);
}else{//存在库存
for(int i=0;i<ListResult.size();i++){
product=(Product) ListResult.get(i);
Integer pr=Integer.parseInt(product.getNumbers());
System.out.println(pr+"---------------存在的数量");
product.setNumbers(""+(Integer.parseInt(eForm.getTotals())+pr));
ProductManagerFactory.getProductManager().modfilyProduct(product);
}
}
returnStr = WebConstant.FORWARD_INITPAGE;
} catch (Exception e) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("edu.system.excption", e.getMessage()));
this.saveErrors(request, errors);
tx.rollback();
e.printStackTrace();
} finally {
try {
if (null != conn) {
conn.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
HibernateSessionFactory.closeSession();
}
return mapping.findForward(returnStr);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -