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

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.DownLoadService;
  9. import com.chinacannel.xlchemical.struts.ActionForm.DownLoadActionForm;
  10. import com.chinacannel.entity.DownLoad;
  11. import java.util.Date;
  12. import com.chinacannel.common.ImageUpload;
  13. import com.chinacannel.entity.Image;
  14. import com.chinacannel.common.PageInfo;
  15. public class DownLoadAction extends DispatchAction {
  16.     private DownLoadService ds = new DownLoadService();
  17.     public ActionForward EditDownLoad(ActionMapping actionMapping,
  18.                                       ActionForm actionForm,
  19.                                       HttpServletRequest servletRequest,
  20.                                       HttpServletResponse servletResponse) {
  21.         DownLoadActionForm daf = (DownLoadActionForm) actionForm;
  22.         DownLoad dl = new DownLoad();
  23.         ImageUpload iu = new ImageUpload();
  24.         boolean b = false;
  25.         String Message = "";
  26.         String Language = "CN";
  27.         try {
  28.             if (servletRequest.getSession().getAttribute("Language") != null) {
  29.                 Language = servletRequest.getSession().getAttribute("Language").
  30.                            toString();
  31.             }
  32.             ds.beginTran();
  33.             if (!daf.getId().equals(new Long(0))) {
  34.                 dl = ds.GetDownLoadById(daf.getId());
  35.             }
  36.             dl.setDow_Time(new Date());
  37.             dl.setDow_Title(daf.getCnTitle());
  38.             dl.setDow_Summary(daf.getSummary());
  39.             dl.setDow_Order(daf.getOrder());
  40.             dl.setDow_Language(Language);
  41.             dl.setDow_Type(new Long(servletRequest.getParameter("Type")));
  42.             if (daf.getDownLoadImg().getFileSize() > 0) {
  43.                 if (!daf.getFileID().equals(new Long(0))) {
  44.                     iu.deleteImage(daf.getFileID().intValue());
  45.                 }
  46.                 Image fileUp = null;
  47.                 fileUp = iu.saveImage(daf.getImage(), servletRequest, false);
  48.                 dl.setFileUp(fileUp);
  49.             }
  50.             if (daf.getImage().getFileSize() > 0) {
  51.                 if (!daf.getImageID().equals(new Long(0))) {
  52.                     iu.deleteImage(daf.getImageID().intValue());
  53.                 }
  54.                 Image imageUp = null;
  55.                 imageUp = iu.saveImage(daf.getDownLoadImg(), servletRequest, false);
  56.                 dl.setImageUp(imageUp);
  57.                 String s = daf.getDownLoadImg().getFileName();
  58.                 String FileBackName = s.substring(s.lastIndexOf(".")+1);
  59.                 dl.setDow_FileSize(new Long(daf.getDownLoadImg().getFileSize()));
  60.                 dl.setDow_BackName(FileBackName);
  61.             }
  62.             if (!daf.getId().equals(new Long(0))) {
  63.                 b = ds.UpdateDownLoad(dl);
  64.                 Message = "更新下载文件成功";
  65.             } else {
  66.                 b = ds.AddDownLoad(dl);
  67.                 Message = "添加下载文件成功";
  68.             }
  69.             ds.commit();
  70.         } catch (Exception ex) {
  71.             log.error(ex.getMessage(), ex);
  72.             try {
  73.                 ds.rollback();
  74.             } catch (Exception ex2) {
  75.                 log.error(ex2.getMessage(), ex2);
  76.             }
  77.         }
  78.         if (b == false) {
  79.             Message = "操作失败!请返回";
  80.         }
  81.         servletRequest.setAttribute
  82.                 ("Url", "/Manage/DownLoad.do?todo=OpenDownLoadList&Type=" + daf.getType());
  83.         servletRequest.setAttribute("Message", Message);
  84.         return actionMapping.findForward("EditDownLoad");
  85.     }
  86.     public ActionForward OpenDownLoad(ActionMapping actionMapping,
  87.                                       ActionForm actionForm,
  88.                                       HttpServletRequest servletRequest,
  89.                                       HttpServletResponse servletResponse) {
  90.         Long dowID = new Long(0);
  91.         DownLoad dl = new DownLoad();
  92.         try {
  93.             ds.beginTran();
  94.             if (servletRequest.getParameter("dowID") != null) {
  95.                 dowID = new Long(servletRequest.getParameter("dowID"));
  96.                 dl = ds.GetDownLoadById(dowID);
  97.             }
  98.             ds.commit();
  99.         } catch (Exception ex) {
  100.             log.error(ex.getMessage(), ex);
  101.             try {
  102.                 ds.rollback();
  103.             } catch (Exception ex2) {
  104.                 log.error(ex2.getMessage(), ex2);
  105.             }
  106.         }
  107.         servletRequest.setAttribute("MainTitle", "上传文件管理");
  108.         servletRequest.setAttribute("ChildTitle", "编辑上传文件");
  109.         servletRequest.setAttribute("dl", dl);
  110.         return actionMapping.findForward("OpenDownLoad");
  111.     }
  112.     public ActionForward OpenDownLoadList(ActionMapping actionMapping,
  113.                                           ActionForm actionForm,
  114.                                           HttpServletRequest servletRequest,
  115.                                           HttpServletResponse servletResponse) {
  116.         int pageNo = 0;
  117.         PageInfo pageInfo = null;
  118.         String Language = "CN";
  119.         Long type = new Long(0);
  120.         try {
  121.             pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
  122.         } catch (Exception ex1) {}
  123.         try {
  124.             if (servletRequest.getSession().getAttribute("Language") != null) {
  125.                 Language = servletRequest.getSession().getAttribute("Language").
  126.                            toString();
  127.             }
  128.             if (servletRequest.getParameter("Type") != null) {
  129.                 type = new Long(servletRequest.getParameter("Type"));
  130.             }
  131.             ds.beginTran();
  132.             pageInfo = ds.getPageInfo(type, Language, pageNo);
  133.             ds.commit();
  134.         } catch (Exception ex) {
  135.             log.error(ex.getMessage(), ex);
  136.             try {
  137.                 ds.rollback();
  138.             } catch (Exception ex2) {
  139.                 log.error(ex2.getMessage(), ex2);
  140.             }
  141.         }
  142.         servletRequest.setAttribute("MainTitle", "上传文件管理");
  143.         servletRequest.setAttribute("ChildTitle", "上传文件列表");
  144.         servletRequest.setAttribute("pageInfo", pageInfo);
  145.         return actionMapping.findForward("OpenDownLoadList");
  146.     }
  147.     public ActionForward DeleteDownLoad(ActionMapping actionMapping,
  148.                                         ActionForm actionForm,
  149.                                         HttpServletRequest servletRequest,
  150.                                         HttpServletResponse servletResponse) {
  151.         DownLoad dl = new DownLoad();
  152.         Long dowID = new Long(0);
  153.         Long Type = new Long(0);
  154.         boolean b = false;
  155.         String Message = "";
  156.         try {
  157.             if (servletRequest.getParameter("dowID") != null &&
  158.                 servletRequest.getParameter("dowID") != "") {
  159.                 dowID = new Long(servletRequest.getParameter("dowID"));
  160.             }
  161.             if (servletRequest.getParameter("Type") != null) {
  162.                 Type = new Long(servletRequest.getParameter("Type"));
  163.             }
  164.             ds.beginTran();
  165.             dl = ds.GetDownLoadById(dowID);
  166.             b = ds.DeleteDownLoad(dl);
  167.             Message = "删除成功,请返回!";
  168.             ds.commit();
  169.         } catch (Exception ex) {
  170.             log.error(ex.getMessage(), ex);
  171.             try {
  172.                 ds.rollback();
  173.             } catch (Exception ex2) {
  174.                 log.error(ex2.getMessage(), ex2);
  175.             }
  176.         }
  177.         if(b == false){
  178.             Message = "删除失败,请返回!";
  179.         }
  180.         servletRequest.setAttribute("Message", Message);
  181.         servletRequest.setAttribute
  182.                 ("Url", "/Manage/DownLoad.do?todo=OpenDownLoadList&Type=" + Type);
  183.         return actionMapping.findForward("DeleteDownLoad");
  184.     }
  185. }