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

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

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import org.apache.struts.actions.DispatchAction;
  3. import com.chinacannel.xlchemical.service.InformationService;
  4. import org.apache.struts.action.ActionForward;
  5. import javax.servlet.http.HttpServletRequest;
  6. import org.apache.struts.action.ActionMapping;
  7. import javax.servlet.http.HttpServletResponse;
  8. import org.apache.struts.action.ActionForm;
  9. import com.chinacannel.entity.Information;
  10. import com.chinacannel.xlchemical.struts.ActionForm.InformationActionForm;
  11. import java.util.Date;
  12. import java.util.List;
  13. import com.chinacannel.common.PageInfo;
  14. import com.chinacannel.entity.Category;
  15. import com.chinacannel.xlchemical.service.CategoryService;
  16. import com.chinacannel.xlchemical.service.MenuService;
  17. import com.chinacannel.entity.Menu;
  18. import com.chinacannel.common.ImageUpload;
  19. import com.chinacannel.entity.Image;
  20. import java.util.ArrayList;
  21. import com.chinacannel.xlchemical.struts.ActionForm.AdminActionForm;
  22. public class InformationAction extends DispatchAction {
  23.     InformationService is = new InformationService();
  24.     CategoryService cs = new CategoryService();
  25.     MenuService ms = new MenuService();
  26.     //通过ID或键值取得一条信息
  27.     public ActionForward OpenInformation(ActionMapping actionMapping,
  28.                                          ActionForm actionForm,
  29.                                          HttpServletRequest servletRequest,
  30.                                          HttpServletResponse servletResponse) {
  31.         Information inf = new Information();
  32.         Long infID = new Long(0);
  33.         String key = "";
  34.         Category cat = null;
  35.         Menu menu = null;
  36.         String Language = "CN";
  37.         try {
  38.             if (servletRequest.getSession().getAttribute("Language") != null) {
  39.                 Language = servletRequest.getSession().getAttribute("Language").
  40.                            toString();
  41.             }
  42.             if (servletRequest.getParameter("infID") != null) {
  43.                 infID = new Long(servletRequest.getParameter("infID"));
  44.             }
  45.             if (servletRequest.getParameter("key") != null) {
  46.                 key = servletRequest.getParameter("key").toString();
  47.             }
  48.             is.beginTran();
  49.             if (servletRequest.getParameter("catID") != null) {
  50.                 cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
  51.                         "catID")));
  52.             }
  53.             if (servletRequest.getParameter("menID") != null) {
  54.                 menu = ms.GetMenuById(new Long(servletRequest.getParameter(
  55.                         "menID")));
  56.             }
  57.             if (cat != null) {
  58.                 servletRequest.setAttribute("cat", cat);
  59.             } else if (!key.equals("")) {
  60.                 if (key.equals("DSZZL")) {
  61.                     inf = is.GetInformationByKey(key, Language);
  62.                     List list = is.GetInformationListByKey("HDXX", Language);
  63.                     List list2 = is.GetInformationListByKey("DSZZC", Language);
  64.                     servletRequest.setAttribute("list", list);
  65.                     servletRequest.setAttribute("list2", list2);
  66.                 }
  67.             } else if (!infID.equals(new Long(0))) {
  68.                 inf = is.GetInformationById(infID);
  69.             } else if (menu != null) {
  70.                 if (menu.getMen_Type().equals(new Long(0))) {
  71.                     inf = is.GetFirstInformationByMenuID(menu.getMen_ID());
  72.                 }
  73.                 servletRequest.setAttribute("menu", menu);
  74.             }
  75.             GetTitle(key, cat, menu, servletRequest);
  76.             is.commit();
  77.         } catch (Exception ex) {
  78.             log.error(ex.getMessage(), ex);
  79.             try {
  80.                 is.rollback();
  81.             } catch (Exception ex2) {
  82.                 log.error(ex2.getMessage(), ex2);
  83.             }
  84.         }
  85.         servletRequest.setAttribute("inf", inf);
  86.         if (menu == null) {
  87.             return actionMapping.findForward("OpenInformation");
  88.         } else {
  89.             return actionMapping.findForward("OpenInformation2");
  90.         }
  91.     }
  92.     private void GetTitle(String key, Category cat, Menu menu,
  93.                           HttpServletRequest servletRequest) {
  94.         String MainTitle = "";
  95.         String ChildTitle = "";
  96.         if (!key.equals("")) {
  97.             MainTitle = "缺省模块管理";
  98.             if (key.equals("HDXX")) {
  99.                 ChildTitle = "董事长专栏 - 活动信息";
  100.             } else if (key.equals("DSZZL")) {
  101.                 ChildTitle = "董事长专栏";
  102.             } else if (key.equals("DSZZC")) {
  103.                 ChildTitle = "董事长专栏 - 董事长致辞";
  104.             }
  105.         } else if (cat != null) {
  106.             MainTitle = "缺省模块管理";
  107.             ChildTitle = "[" + cat.getCat_Name() + "]信息";
  108.         } else if (menu != null) {
  109.             MainTitle = "常规模块管理";
  110.             ChildTitle = "[" + menu.getMen_Name() + "]信息";
  111.         }
  112.         servletRequest.setAttribute("MainTitle", MainTitle);
  113.         servletRequest.setAttribute("ChildTitle", ChildTitle);
  114.         servletRequest.setAttribute("key", key);
  115.     }
  116.     public ActionForward EditInformation(ActionMapping actionMapping,
  117.                                          ActionForm actionForm,
  118.                                          HttpServletRequest servletRequest,
  119.                                          HttpServletResponse servletResponse) {
  120.         Information inf = new Information();
  121.         InformationActionForm iaf = (InformationActionForm) actionForm;
  122.         String Language = "CN";
  123.         String Message = "";
  124.         String Url = "";
  125.         Menu menu = null;
  126.         ImageUpload iu = new ImageUpload();
  127.         try {
  128.             if (servletRequest.getSession().getAttribute("Language") != null) {
  129.                 Language = servletRequest.getSession().getAttribute("Language").
  130.                            toString();
  131.             }
  132.             is.beginTran();
  133.             if (!iaf.getId().equals(new Long(0))) {
  134.                 inf = is.GetInformationById(iaf.getId());
  135.             }
  136.             if (!iaf.getCatID().equals(new Long(0))) {
  137.                 Category cat = null;
  138.                 cat = cs.GetCategoryById(iaf.getCatID());
  139.                 inf.setCategory(cat);
  140.             }
  141.             if (!iaf.getMenuID().equals(new Long(0))) {
  142.                 menu = ms.GetMenuById(iaf.getMenuID());
  143.                 inf.setMenu(menu);
  144.             }
  145.             if (iaf.getInformationImage() != null &&
  146.                 iaf.getInformationImage().getFileSize() > 0) {
  147.                 if (!iaf.getImageID().equals(new Long(0))) {
  148.                     iu.deleteImage(iaf.getImageID().intValue());
  149.                 }
  150.                 Image img = iu.saveImage(iaf.getInformationImage(),
  151.                                          servletRequest, false);
  152.                 inf.setImage(img);
  153.             }
  154.             inf.setInf_Content(iaf.getContent());
  155.             inf.setInf_Language(Language);
  156.             inf.setInf_Time(new Date());
  157.             inf.setInf_Title(iaf.getTitle());
  158.             inf.setInf_Index(iaf.getIndex());
  159.             inf.setInf_Summary(iaf.getSummary());
  160.             if (iaf.getId().equals(new Long(0))) {
  161.                 is.AddInformation(inf);
  162.                 inf.setInf_Key(iaf.getKey());
  163.                 Message = "添加信息成功,请返回!";
  164.             } else {
  165.                 is.UpdateInformation(inf);
  166.                 Message = "修改信息成功,请返回!";
  167.             }
  168.             is.commit();
  169.         } catch (Exception ex) {
  170.             log.error(ex.getMessage(), ex);
  171.             try {
  172.                 is.rollback();
  173.             } catch (Exception ex2) {
  174.                 log.error(ex2.getMessage(), ex2);
  175.             }
  176.         }
  177.         if (inf.getInf_Key() != null && !inf.getInf_Key().equals("")) {
  178.             Url = "/Manage/Information.do?todo=OpenInformation&key=" +
  179.                   inf.getInf_Key();
  180.         } else if (inf.getCategory() != null) {
  181.             Url = "/Manage/Information.do?todo=OpenInformationList&catID=" +
  182.                   inf.getCategory().getCat_ID();
  183.         } else if (inf.getMenu() != null) {
  184.             if (inf.getMenu().getMen_Type() == 0) {
  185.                 Url = "/Manage/Menu.do?todo=OpenMenu&language=" +
  186.                       inf.getMenu().getMen_Language() + "&superiorID=" +
  187.                       inf.getMenu().getMen_Superior();
  188.             } else {
  189.                 Url = "/Manage/Information.do?todo=OpenInformationList&menuID=" +
  190.                       inf.getMenu().getMen_ID();
  191.             }
  192.         } else {
  193.             Url = "/Manage/Information.do?todo=OpenInformationList";
  194.         }
  195.         servletRequest.setAttribute("Message", Message);
  196.         servletRequest.setAttribute("Url", Url);
  197.         return actionMapping.findForward("EditInformation");
  198.     }
  199.     public ActionForward DeleteInformation(ActionMapping actionMapping,
  200.                                            ActionForm actionForm,
  201.                                            HttpServletRequest servletRequest,
  202.                                            HttpServletResponse servletResponse) {
  203.         Information inf = null;
  204.         boolean b = false;
  205.         String Message = "";
  206.         String Url = "";
  207.         Long menuID = new Long(0);
  208.         Long catID = new Long(0);
  209.         try {
  210.             if (servletRequest.getParameter("menuID") != null &&
  211.                 servletRequest.getParameter("menuID") != "") {
  212.                 menuID = new Long(servletRequest.getParameter("menuID"));
  213.             }
  214.             if (servletRequest.getParameter("catID") != null &&
  215.                 servletRequest.getParameter("catID") != "") {
  216.                 catID = new Long(servletRequest.getParameter("catID"));
  217.             }
  218.             is.beginTran();
  219.             inf = is.GetInformationById(new Long(servletRequest.getParameter(
  220.                     "infID")));
  221.             b = is.DeleteInformation(inf);
  222.             Message = "删除成功,请返回!";
  223.             is.commit();
  224.             if (!menuID.equals(new Long(0))) {
  225.                 Url = "/Manage/Information.do?todo=OpenInformationList&menuID=" +
  226.                       menuID;
  227.             } else if (!catID.equals(new Long(0))) {
  228.                 Url = "/Manage/Information.do?todo=OpenInformationList&catID=" +
  229.                       catID;
  230.             } else {
  231.                 Url = "/Manage/Information.do?todo=OpenInformation&key=" +
  232.                       inf.getInf_Key();
  233.             }
  234.         } catch (Exception ex) {
  235.             log.error(ex.getMessage(), ex);
  236.             try {
  237.                 is.rollback();
  238.             } catch (Exception ex2) {
  239.                 log.error(ex2.getMessage(), ex2);
  240.             }
  241.         }
  242.         if (b == false) {
  243.             Message = "删除失败,请返回!";
  244.         }
  245.         servletRequest.setAttribute("Message", Message);
  246.         servletRequest.setAttribute("Url", Url);
  247.         return actionMapping.findForward("DeleteInformation");
  248.     }
  249.     public ActionForward OpenInformationList(ActionMapping actionMapping,
  250.                                              ActionForm actionForm,
  251.                                              HttpServletRequest servletRequest,
  252.                                              HttpServletResponse servletResponse) {
  253.         PageInfo pageInfo = null;
  254.         int pageNo = 0;
  255.         String Language = "CN";
  256.         String Key = "";
  257.         Category cat = null;
  258.         Menu menu = null;
  259.         InformationActionForm iaf = actionForm;
  260.         try {
  261.             pageNo = Integer.parseInt(servletRequest.getParameter("pageNo"));
  262.         } catch (Exception ex1) {}
  263.         try {
  264.             if (servletRequest.getSession().getAttribute("Language") != null) {
  265.                 Language = servletRequest.getSession().getAttribute("Language").
  266.                            toString();
  267.             }
  268.             if (servletRequest.getParameter("Key") != null) {
  269.                 Key = servletRequest.getParameter("Key");
  270.             }
  271.             is.beginTran();
  272.             if (servletRequest.getParameter("catID") != null) {
  273.                 cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
  274.                         "catID")));
  275.                 servletRequest.setAttribute("cat", cat);
  276.             }
  277.             if (servletRequest.getParameter("menuID") != null) {
  278.                 menu = ms.GetMenuById(new Long(servletRequest.getParameter(
  279.                         "menuID")));
  280.                 servletRequest.setAttribute("menu", menu);
  281.             }
  282.             GetTitle(Key, cat, menu, servletRequest);
  283.             pageInfo = is.getPageInfo(Key, cat, menu, Language, pageNo);
  284.             is.commit();
  285.         } catch (Exception ex) {
  286.             log.error(ex.getMessage(), ex);
  287.             try {
  288.                 is.rollback();
  289.             } catch (Exception ex2) {
  290.                 log.error(ex2.getMessage(), ex2);
  291.             }
  292.         }
  293.         servletRequest.setAttribute("pageInfo", pageInfo);
  294.         return actionMapping.findForward("OpenInformationList");
  295.     }
  296.     public ActionForward OpenChirmanInfo(ActionMapping actionMapping,
  297.                                          ActionForm actionForm,
  298.                                          HttpServletRequest servletRequest,
  299.                                          HttpServletResponse servletResponse) {
  300.         List list = null;
  301.         List list2 = null;
  302.         Information inf = null;
  303.         Menu fMenu = new Menu();
  304.         List menuList = null;
  305.         Long fMenuID = new Long(0);
  306.         String Language = "CN";
  307.         try {
  308.             if (servletRequest.getSession().getAttribute("Language") != null) {
  309.                 Language = servletRequest.getSession().getAttribute("Language").
  310.                            toString();
  311.             }
  312.             if (servletRequest.getParameter("fMenuID") != null) {
  313.                 fMenuID = new Long(servletRequest.getParameter("fMenuID"));
  314.             }
  315.             is.beginTran();
  316.             fMenu = ms.GetMenuById(fMenuID);
  317.             menuList = ms.GetMenuBySuperior(fMenuID, Language);
  318.             inf = is.GetInformationByKey("DSZZL", Language);
  319.             list = is.GetInformationListByKey("HDXX", Language);
  320.             list2 = is.GetInformationListByKey("DSZZC", Language);
  321.             is.commit();
  322.         } catch (Exception ex) {
  323.             log.error(ex.getMessage(), ex);
  324.             try {
  325.                 is.rollback();
  326.             } catch (Exception ex2) {
  327.                 log.error(ex2.getMessage(), ex2);
  328.             }
  329.         }
  330.         servletRequest.setAttribute("menu", fMenu);
  331.         servletRequest.setAttribute("menuList", menuList);
  332.         servletRequest.setAttribute("list", list);
  333.         servletRequest.setAttribute("list2", list2);
  334.         servletRequest.setAttribute("inf", inf);
  335.         return actionMapping.findForward("OpenChirmanInfo");
  336.     }
  337. }