ProductAction.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:7k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import org.apache.struts.actions.DispatchAction;
- import org.apache.struts.action.ActionForward;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionMapping;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import com.chinacannel.xlchemical.service.ProductService;
- import com.chinacannel.xlchemical.struts.ActionForm.ProductActionForm;
- import com.chinacannel.entity.Product;
- import com.chinacannel.common.ImageUpload;
- import com.chinacannel.entity.Image;
- import java.util.Date;
- import com.chinacannel.common.PageInfo;
- public class ProductAction extends DispatchAction {
- ProductService ps = new ProductService();
- public ActionForward EditProduct(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- ProductActionForm paf = (ProductActionForm) actionForm;
- Product pro = new Product();
- ImageUpload iu = new ImageUpload();
- Image image = null;
- String Language = "CN";
- boolean b = false;
- String Message = "";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (!paf.getId().equals(new Long(0))) {
- pro = ps.GetProductById(paf.getId());
- }
- if (paf.getProductImg().getFileSize() > 0) {
- if (!paf.getImageID().equals(new Long(0))) {
- iu.deleteImage(paf.getImageID().intValue());
- }
- image = iu.saveImage(paf.getProductImg(), servletRequest, false);
- pro.setImage(image);
- }
- pro.setPro_Action(paf.getAction());
- pro.setPro_EnName(paf.getEnName());
- pro.setPro_Modality(paf.getModality());
- pro.setPro_Molecular(paf.getMolecular());
- pro.setPro_Name(paf.getName());
- pro.setPro_Language(Language);
- pro.setPro_Time(new Date());
- if (!paf.getId().equals(new Long(0))) {
- pro.setPro_ID(paf.getId());
- b = ps.UpdateProduct(pro);
- Message = "修改产品成功,请返回";
- } else {
- b = ps.AddProduct(pro);
- Message = "添加产品成功,请返回";
- }
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ps.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "操作失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", "Manage/Product.do?todo=OpenProduct");
- return actionMapping.findForward("EditProduct");
- }
- public ActionForward OpenProduct(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- int pageNo = 0;
- String Language = "CN";
- PageInfo pageInfo = null;
- try {
- pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
- } catch (Exception ex1) {}
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- ps.beginTran();
- pageInfo = ps.getPageInfo(Language, pageNo);
- ps.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ps.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("pageInfo", pageInfo);
- return actionMapping.findForward("OpenProduct");
- }
- public ActionForward OpenProductInfo(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long proID = new Long(0);
- Product pro = null;
- try {
- if (servletRequest.getParameter("proID") != null) {
- proID = new Long(servletRequest.getParameter("proID"));
- }
- ps.beginTran();
- if (!proID.equals(new Long(0))) {
- pro = ps.GetProductById(proID);
- }
- ps.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ps.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("pro", pro);
- return actionMapping.findForward("OpenProductInfo");
- }
- public ActionForward DeletProduct(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long proID = new Long(0);
- Product pro = null;
- boolean b = false;
- String Message = "";
- try {
- proID = new Long(servletRequest.getParameter("proID"));
- ps.beginTran();
- pro = ps.GetProductById(proID);
- b = ps.DeletePorduct(pro);
- ps.commit();
- Message = "删除成功,请返回!";
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ps.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "Manage/Product.do?todo=OpenProduct");
- return actionMapping.findForward("DeletProduct");
- }
- }