DownLoadAction.java~79~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:8k
源码类别:
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.DownLoadService;
- import com.chinacannel.xlchemical.struts.ActionForm.DownLoadActionForm;
- import com.chinacannel.entity.DownLoad;
- import java.util.Date;
- import com.chinacannel.common.ImageUpload;
- import com.chinacannel.entity.Image;
- import com.chinacannel.common.PageInfo;
- public class DownLoadAction extends DispatchAction {
- private DownLoadService ds = new DownLoadService();
- public ActionForward EditDownLoad(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- DownLoadActionForm daf = (DownLoadActionForm) actionForm;
- DownLoad dl = new DownLoad();
- ImageUpload iu = new ImageUpload();
- boolean b = false;
- String Message = "";
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- ds.beginTran();
- if (!daf.getId().equals(new Long(0))) {
- dl = ds.GetDownLoadById(daf.getId());
- }
- dl.setDow_Time(new Date());
- dl.setDow_Title(daf.getCnTitle());
- dl.setDow_Summary(daf.getSummary());
- dl.setDow_Order(daf.getOrder());
- dl.setDow_Language(Language);
- dl.setDow_Type(new Long(servletRequest.getParameter("Type")));
- if (daf.getDownLoadImg().getFileSize() > 0) {
- if (!daf.getImageID().equals(new Long(0))) {
- iu.deleteImage(daf.getFileID().intValue());
- }
- Image fileUp = null;
- fileUp = iu.saveImage(daf.getImage(), servletRequest, false);
- dl.setFileUp(fileUp);
- }
- if (daf.getImage().getFileSize() > 0) {
- if (!daf.getFileID().equals(new Long(0))) {
- iu.deleteImage(daf.getImageID().intValue());
- }
- Image imageUp = null;
- imageUp = iu.saveImage(daf.getDownLoadImg(), servletRequest, false);
- dl.setImageUp(imageUp);
- String s = daf.getImage().getFileName();
- String FileBackName = s.substring(s.lastIndexOf(".")+1);
- dl.setDow_FileSize(new Long(daf.getDownLoadImg().getFileSize()));
- dl.setDow_BackName(FileBackName);
- }
- if (!daf.getId().equals(new Long(0))) {
- b = ds.UpdateDownLoad(dl);
- Message = "更新下载文件成功";
- } else {
- b = ds.AddDownLoad(dl);
- Message = "添加下载文件成功";
- }
- ds.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ds.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "操作失败!请返回";
- }
- servletRequest.setAttribute
- ("Url", "/Manage/DownLoad.do?todo=OpenDownLoadList&Type=" + daf.getType());
- servletRequest.setAttribute("Message", Message);
- return actionMapping.findForward("EditDownLoad");
- }
- public ActionForward OpenDownLoad(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Long dowID = new Long(0);
- DownLoad dl = new DownLoad();
- try {
- ds.beginTran();
- if (servletRequest.getParameter("dowID") != null) {
- dowID = new Long(servletRequest.getParameter("dowID"));
- dl = ds.GetDownLoadById(dowID);
- }
- ds.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ds.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("MainTitle", "上传文件管理");
- servletRequest.setAttribute("ChildTitle", "编辑上传文件");
- servletRequest.setAttribute("dl", dl);
- return actionMapping.findForward("OpenDownLoad");
- }
- public ActionForward OpenDownLoadList(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- int pageNo = 0;
- PageInfo pageInfo = null;
- String Language = "CN";
- Long type = new Long(0);
- try {
- pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
- } catch (Exception ex1) {}
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (servletRequest.getParameter("Type") != null) {
- type = new Long(servletRequest.getParameter("Type"));
- }
- ds.beginTran();
- pageInfo = ds.getPageInfo(type, Language, pageNo);
- ds.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ds.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("MainTitle", "上传文件管理");
- servletRequest.setAttribute("ChildTitle", "上传文件列表");
- servletRequest.setAttribute("pageInfo", pageInfo);
- return actionMapping.findForward("OpenDownLoadList");
- }
- public ActionForward DeleteDownLoad(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- DownLoad dl = new DownLoad();
- Long dowID = new Long(0);
- Long Type = new Long(0);
- boolean b = false;
- String Message = "";
- try {
- if (servletRequest.getParameter("dowID") != null &&
- servletRequest.getParameter("dowID") != "") {
- dowID = new Long(servletRequest.getParameter("dowID"));
- }
- if (servletRequest.getParameter("Type") != null) {
- Type = new Long(servletRequest.getParameter("Type"));
- }
- ds.beginTran();
- dl = ds.GetDownLoadById(dowID);
- b = ds.DeleteDownLoad(dl);
- Message = "删除成功,请返回!";
- ds.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- ds.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if(b == false){
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute
- ("Url", "/Manage/DownLoad.do?todo=OpenDownLoadList&Type=" + Type);
- return actionMapping.findForward("DeleteDownLoad");
- }
- }