ProductAction.java~1~
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:7k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import org.apache.struts.actions.DispatchAction;
  3. import org.apache.struts.action.ActionForward;
  4. import javax.servlet.http.HttpServletRequest;
  5. import org.apache.struts.action.ActionMapping;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.struts.action.ActionForm;
  8. import com.chinacannel.xlchemical.service.ProductService;
  9. import com.chinacannel.xlchemical.struts.ActionForm.ProductActionForm;
  10. import com.chinacannel.entity.Product;
  11. import com.chinacannel.common.ImageUpload;
  12. import com.chinacannel.entity.Image;
  13. import java.util.Date;
  14. import com.chinacannel.common.PageInfo;
  15. public class ProductAction extends DispatchAction {
  16.     ProductService ps = new ProductService();
  17.     public ActionForward EditProduct(ActionMapping actionMapping,
  18.                                      ActionForm actionForm,
  19.                                      HttpServletRequest servletRequest,
  20.                                      HttpServletResponse servletResponse) {
  21.         ProductActionForm paf = (ProductActionForm) actionForm;
  22.         Product pro = new Product();
  23.         ImageUpload iu = new ImageUpload();
  24.         Image image = null;
  25.         String Language = "CN";
  26.         boolean b = false;
  27.         String Message = "";
  28.         try {
  29.             if (servletRequest.getSession().getAttribute("Language") != null) {
  30.                 Language = servletRequest.getSession().getAttribute("Language").
  31.                            toString();
  32.             }
  33.             if (!paf.getId().equals(new Long(0))) {
  34.                 pro = ps.GetProductById(paf.getId());
  35.             }
  36.             if (paf.getProductImg().getFileSize() > 0) {
  37.                 if (!paf.getImageID().equals(new Long(0))) {
  38.                     iu.deleteImage(paf.getImageID().intValue());
  39.                 }
  40.                 image = iu.saveImage(paf.getProductImg(), servletRequest, false);
  41.                 pro.setImage(image);
  42.             }
  43.             pro.setPro_Action(paf.getAction());
  44.             pro.setPro_EnName(paf.getEnName());
  45.             pro.setPro_Modality(paf.getModality());
  46.             pro.setPro_Molecular(paf.getMolecular());
  47.             pro.setPro_Name(paf.getName());
  48.             pro.setPro_Language(Language);
  49.             pro.setPro_Time(new Date());
  50.             if (!paf.getId().equals(new Long(0))) {
  51.                 pro.setPro_ID(paf.getId());
  52.                 b = ps.UpdateProduct(pro);
  53.                 Message = "修改产品成功,请返回";
  54.             } else {
  55.                 b = ps.AddProduct(pro);
  56.                 Message = "添加产品成功,请返回";
  57.             }
  58.         } catch (Exception ex) {
  59.             log.error(ex.getMessage(), ex);
  60.             try {
  61.                 ps.rollback();
  62.             } catch (Exception ex2) {
  63.                 log.error(ex2.getMessage(), ex2);
  64.             }
  65.         }
  66.         if (b == false) {
  67.             Message = "操作失败,请返回!";
  68.         }
  69.         servletRequest.setAttribute("Message", Message);
  70.         servletRequest.setAttribute("Url", "/Manage/Product.do?todo=OpenProduct");
  71.         return actionMapping.findForward("EditProduct");
  72.     }
  73.     public ActionForward OpenProduct(ActionMapping actionMapping,
  74.                                      ActionForm actionForm,
  75.                                      HttpServletRequest servletRequest,
  76.                                      HttpServletResponse servletResponse) {
  77.         int pageNo = 0;
  78.         String Language = "CN";
  79.         PageInfo pageInfo = null;
  80.         try {
  81.             pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
  82.         } catch (Exception ex1) {}
  83.         try {
  84.             if (servletRequest.getSession().getAttribute("Language") != null) {
  85.                 Language = servletRequest.getSession().getAttribute("Language").
  86.                            toString();
  87.             }
  88.             ps.beginTran();
  89.             pageInfo = ps.getPageInfo(Language, pageNo);
  90.             ps.commit();
  91.         } catch (Exception ex) {
  92.             log.error(ex.getMessage(), ex);
  93.             try {
  94.                 ps.rollback();
  95.             } catch (Exception ex2) {
  96.                 log.error(ex2.getMessage(), ex2);
  97.             }
  98.         }
  99.         servletRequest.setAttribute("pageInfo", pageInfo);
  100.         return actionMapping.findForward("OpenProduct");
  101.     }
  102.     public ActionForward OpenProductInfo(ActionMapping actionMapping,
  103.                                          ActionForm actionForm,
  104.                                          HttpServletRequest servletRequest,
  105.                                          HttpServletResponse servletResponse) {
  106.         Long proID = new Long(0);
  107.         Product pro = null;
  108.         try {
  109.             if (servletRequest.getParameter("proID") != null) {
  110.                 proID = new Long(servletRequest.getParameter("proID"));
  111.             }
  112.             ps.beginTran();
  113.             if (!proID.equals(new Long(0))) {
  114.                 pro = ps.GetProductById(proID);
  115.             }
  116.             ps.commit();
  117.         } catch (Exception ex) {
  118.             log.error(ex.getMessage(), ex);
  119.             try {
  120.                 ps.rollback();
  121.             } catch (Exception ex2) {
  122.                 log.error(ex2.getMessage(), ex2);
  123.             }
  124.         }
  125.         servletRequest.setAttribute("pro", pro);
  126.         return actionMapping.findForward("OpenProductInfo");
  127.     }
  128.     public ActionForward DeletProduct(ActionMapping actionMapping,
  129.                                       ActionForm actionForm,
  130.                                       HttpServletRequest servletRequest,
  131.                                       HttpServletResponse servletResponse) {
  132.         Long proID = new Long(0);
  133.         Product pro = null;
  134.         boolean b = false;
  135.         String Message = "";
  136.         try {
  137.             proID = new Long(servletRequest.getParameter("proID"));
  138.             ps.beginTran();
  139.             pro = ps.GetProductById(proID);
  140.             b = ps.DeletePorduct(pro);
  141.             ps.commit();
  142.             Message = "删除成功,请返回!";
  143.         } catch (Exception ex) {
  144.             log.error(ex.getMessage(), ex);
  145.             try {
  146.                 ps.rollback();
  147.             } catch (Exception ex2) {
  148.                 log.error(ex2.getMessage(), ex2);
  149.             }
  150.         }
  151.         if (b == false) {
  152.             Message = "删除失败,请返回!";
  153.         }
  154.         servletRequest.setAttribute("Message", Message);
  155.         servletRequest.setAttribute("Url",
  156.                                     "/Manage/Product.do?todo=OpenProduct");
  157.         return actionMapping.findForward("DeletProduct");
  158.     }
  159. }