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