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