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

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

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import com.chinacannel.xlchemical.service.LinkService;
  3. import org.apache.struts.actions.DispatchAction;
  4. import org.apache.struts.action.ActionMapping;
  5. import org.apache.struts.action.ActionForward;
  6. import org.apache.struts.action.ActionForm;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.chinacannel.entity.Link;
  10. import java.util.List;
  11. import com.chinacannel.xlchemical.struts.ActionForm.LinkActionForm;
  12. import com.chinacannel.common.PageInfo;
  13. import com.chinacannel.common.ImageUpload;
  14. public class LinkAction extends DispatchAction {
  15.     LinkService ls = new LinkService();
  16.     public ActionForward EditLink(ActionMapping actionMapping,
  17.                                   ActionForm actionForm,
  18.                                   HttpServletRequest servletRequest,
  19.                                   HttpServletResponse servletResponse) {
  20.         LinkActionForm laf = (LinkActionForm) actionForm;
  21.         Link link = new Link();
  22.         String Message = "";
  23.         ImageUpload iu = new ImageUpload();
  24.         Images image = new Images();
  25.         boolean b = false;
  26.         try {
  27.             ls.beginTran();
  28.             if (!laf.getLinkID().equals(new Long(0))) {
  29.                 link = ls.GetLinkById(laf.getLinkID());
  30.             }
  31.             link.setLin_CName(laf.getCName());
  32.             link.setLin_EName(laf.getEName());
  33.             link.setLin_Url(laf.getUrl());
  34.             link.setLin_Type(laf.getType());
  35.             if(laf.getLinkImg().getFileSize()>0){
  36.                 if(!laf.getImageID().equals(new Long(0))){
  37.                     iu.deleteImage(laf.getImageID().intValue());
  38.                 }
  39.                 image = iu.saveImage(paf.getProductImg(), servletRequest, false);
  40.                 pro.setImage(image);
  41.             }
  42.             if(!laf.getLinkID().equals(new Long(0))){
  43.                 b = ls.UpdateLink(link);
  44.                 Message = "更新成功,请返回!";
  45.             }else{
  46.                 b = ls.AddLink(link);
  47.                 Message = "添加成功,请返回!";
  48.             }
  49.             ls.commit();
  50.         } catch (Exception ex) {
  51.             log.error(ex.getMessage(), ex);
  52.             try {
  53.                 ls.rollback();
  54.             } catch (Exception ex2) {
  55.                 log.error(ex2.getMessage(), ex2);
  56.             }
  57.         }
  58.         if(b == false){
  59.             Message = "添加失败,请返回!";
  60.         }
  61.         servletRequest.setAttribute("Message", Message);
  62.         servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
  63.         return actionMapping.findForward("EditLink");
  64.     }
  65.     public ActionForward OpenLink(ActionMapping actionMapping,
  66.                                   ActionForm actionForm,
  67.                                   HttpServletRequest servletRequest,
  68.                                   HttpServletResponse servletResponse) {
  69.         List linkList = null;
  70.         String title = "链接管理";
  71.         Long linkID = new Long(0);
  72.         Link link = new Link();
  73.         try {
  74.             if (servletRequest.getParameter("LinkID") != null) {
  75.                 linkID = new Long(servletRequest.getParameter("LinkID"));
  76.             }
  77.             ls.beginTran();
  78.             linkList = ls.GetAllLink();
  79.             link = ls.GetLinkById(linkID);
  80.             ls.commit();
  81.         } catch (Exception ex) {
  82.             log.error(ex.getMessage(), ex);
  83.             try {
  84.                 ls.rollback();
  85.             } catch (Exception ex2) {
  86.                 log.error(ex2.getMessage(), ex2);
  87.             }
  88.         }
  89.         servletRequest.setAttribute("link", link);
  90.         servletRequest.setAttribute("title", title);
  91.         servletRequest.setAttribute("linkList", linkList);
  92.         return actionMapping.findForward("OpenLink");
  93.     }
  94.     public ActionForward DeleteLink(ActionMapping actionMapping,
  95.                                     ActionForm actionForm,
  96.                                     HttpServletRequest servletRequest,
  97.                                     HttpServletResponse servletResponse) {
  98.         Long linID = new Long(0);
  99.         Link link = null;
  100.         String Message = "";
  101.         try {
  102.             linID = new Long(servletRequest.getParameter("linID"));
  103.             ls.beginTran();
  104.             link = ls.GetLinkById(linID);
  105.             ls.DeleteLink(link);
  106.             Message = "删除成功,请返回!";
  107.             ls.commit();
  108.         } catch (Exception ex) {
  109.             log.error(ex.getMessage(), ex);
  110.             try {
  111.                 ls.rollback();
  112.             } catch (Exception ex2) {
  113.                 log.error(ex2.getMessage(), ex2);
  114.             }
  115.         }
  116.         servletRequest.setAttribute("Message", Message);
  117.         servletRequest.setAttribute("Url", "/Manage/Link.do?todo=OpenLink");
  118.         return actionMapping.findForward("DeleteLink");
  119.     }
  120.     public ActionForward ShowLink(ActionMapping actionMapping,
  121.                                   ActionForm actionForm,
  122.                                   HttpServletRequest servletRequest,
  123.                                   HttpServletResponse servletResponse) {
  124.         int pageNo = 0;
  125.         PageInfo pageInfo = null;
  126.         try {
  127.             pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
  128.         } catch (Exception ex1) {}
  129.         try {
  130.             ls.beginTran();
  131.             pageInfo = ls.getPageInfo(new Long(3), pageNo);
  132.             ls.commit();
  133.         } catch (Exception ex) {
  134.             log.error(ex.getMessage(), ex);
  135.             try {
  136.                 ls.rollback();
  137.             } catch (Exception ex2) {
  138.                 log.error(ex2.getMessage(), ex2);
  139.             }
  140.         }
  141.         servletRequest.setAttribute("pageInfo", pageInfo);
  142.         return actionMapping.findForward("ShowLink");
  143.     }
  144. }