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