InformationAction.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:15k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import org.apache.struts.actions.DispatchAction;
- import com.chinacannel.xlchemical.service.InformationService;
- 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.entity.Information;
- import com.chinacannel.xlchemical.struts.ActionForm.InformationActionForm;
- import java.util.Date;
- import java.util.List;
- import com.chinacannel.common.PageInfo;
- import com.chinacannel.entity.Category;
- import com.chinacannel.xlchemical.service.CategoryService;
- import com.chinacannel.xlchemical.service.MenuService;
- import com.chinacannel.entity.Menu;
- import com.chinacannel.common.ImageUpload;
- import com.chinacannel.entity.Image;
- public class InformationAction extends DispatchAction {
- InformationService is = new InformationService();
- CategoryService cs = new CategoryService();
- MenuService ms = new MenuService();
- //通过ID或键值取得一条信息
- public ActionForward OpenInformation(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Information inf = new Information();
- Long infID = new Long(0);
- String key = "";
- Category cat = null;
- Menu menu = null;
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (servletRequest.getParameter("infID") != null) {
- infID = new Long(servletRequest.getParameter("infID"));
- }
- if (servletRequest.getParameter("key") != null) {
- key = servletRequest.getParameter("key").toString();
- }
- is.beginTran();
- if (servletRequest.getParameter("catID") != null) {
- cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
- "catID")));
- }
- if (servletRequest.getParameter("menID") != null) {
- menu = ms.GetMenuById(new Long(servletRequest.getParameter(
- "menID")));
- }
- if (cat != null) {
- servletRequest.setAttribute("cat", cat);
- } else if (!key.equals("")) {
- if (key.equals("DSZZL")) {
- inf = is.GetInformationByKey(key, Language);
- List list = is.GetInformationListByKey("HDXX", Language);
- List list2 = is.GetInformationListByKey("DSZZC", Language);
- servletRequest.setAttribute("list", list);
- servletRequest.setAttribute("list2", list2);
- }
- } else if (!infID.equals(new Long(0))) {
- inf = is.GetInformationById(infID);
- } else if (menu != null) {
- if (menu.getMen_Type().equals(new Long(0))) {
- inf = is.GetFirstInformationByMenuID(menu.getMen_ID());
- }
- servletRequest.setAttribute("menu", menu);
- }
- GetTitle(key, cat, menu, servletRequest);
- is.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- is.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("inf", inf);
- if (menu == null) {
- return actionMapping.findForward("OpenInformation");
- } else {
- return actionMapping.findForward("OpenInformation2");
- }
- }
- private void GetTitle(String key, Category cat, Menu menu,
- HttpServletRequest servletRequest) {
- String MainTitle = "";
- String ChildTitle = "";
- if (!key.equals("")) {
- MainTitle = "缺省模块管理";
- if (key.equals("HDXX")) {
- ChildTitle = "董事长专栏 - 活动信息";
- } else if (key.equals("DSZZL")) {
- ChildTitle = "董事长专栏";
- } else if (key.equals("DSZZC")) {
- ChildTitle = "董事长专栏 - 董事长致辞";
- }
- } else if (cat != null) {
- MainTitle = "缺省模块管理";
- ChildTitle = "[" + cat.getCat_Name() + "]信息";
- } else if (menu != null) {
- MainTitle = "常规模块管理";
- ChildTitle = "[" + menu.getMen_Name() + "]信息";
- }
- servletRequest.setAttribute("MainTitle", MainTitle);
- servletRequest.setAttribute("ChildTitle", ChildTitle);
- servletRequest.setAttribute("key", key);
- }
- public ActionForward EditInformation(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Information inf = new Information();
- InformationActionForm iaf = (InformationActionForm) actionForm;
- String Language = "CN";
- String Message = "";
- String Url = "";
- Menu menu = null;
- ImageUpload iu = new ImageUpload();
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- is.beginTran();
- if (!iaf.getId().equals(new Long(0))) {
- inf = is.GetInformationById(iaf.getId());
- }
- if (!iaf.getCatID().equals(new Long(0))) {
- Category cat = null;
- cat = cs.GetCategoryById(iaf.getCatID());
- inf.setCategory(cat);
- }
- if (!iaf.getMenuID().equals(new Long(0))) {
- menu = ms.GetMenuById(iaf.getMenuID());
- inf.setMenu(menu);
- }
- if (iaf.getInformationImage() != null &&
- iaf.getInformationImage().getFileSize() > 0) {
- if (!iaf.getImageID().equals(new Long(0))) {
- iu.deleteImage(iaf.getImageID().intValue());
- }
- Image img = iu.saveImage(iaf.getInformationImage(),
- servletRequest, false);
- inf.setImage(img);
- }
- inf.setInf_Content(iaf.getContent());
- inf.setInf_Language(Language);
- inf.setInf_Time(new Date());
- inf.setInf_Title(iaf.getTitle());
- inf.setInf_Index(iaf.getIndex());
- inf.setInf_Summary(iaf.getSummary());
- if (iaf.getId().equals(new Long(0))) {
- is.AddInformation(inf);
- inf.setInf_Key(iaf.getKey());
- Message = "添加信息成功,请返回!";
- } else {
- is.UpdateInformation(inf);
- Message = "修改信息成功,请返回!";
- }
- is.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- is.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (inf.getInf_Key() != null && !inf.getInf_Key().equals("")) {
- Url = "Manage/Information.do?todo=OpenInformation&key=" +
- inf.getInf_Key();
- } else if (inf.getCategory() != null) {
- Url = "Manage/Information.do?todo=OpenInformationList&catID=" +
- inf.getCategory().getCat_ID();
- } else if (inf.getMenu() != null) {
- if (inf.getMenu().getMen_Type() == 0) {
- Url = "Manage/Menu.do?todo=OpenMenu&language=" +
- inf.getMenu().getMen_Language() + "&superiorID=" +
- inf.getMenu().getMen_Superior();
- } else {
- Url = "Manage/Information.do?todo=OpenInformationList&menuID=" +
- inf.getMenu().getMen_ID();
- }
- } else {
- Url = "Manage/Information.do?todo=OpenInformationList";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", Url);
- return actionMapping.findForward("EditInformation");
- }
- public ActionForward DeleteInformation(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Information inf = null;
- boolean b = false;
- String Message = "";
- String Url = "";
- Long menuID = new Long(0);
- Long catID = new Long(0);
- try {
- if (servletRequest.getParameter("menuID") != null &&
- servletRequest.getParameter("menuID") != "") {
- menuID = new Long(servletRequest.getParameter("menuID"));
- }
- if (servletRequest.getParameter("catID") != null &&
- servletRequest.getParameter("catID") != "") {
- catID = new Long(servletRequest.getParameter("catID"));
- }
- is.beginTran();
- inf = is.GetInformationById(new Long(servletRequest.getParameter(
- "infID")));
- b = is.DeleteInformation(inf);
- Message = "删除成功,请返回!";
- is.commit();
- if (!menuID.equals(new Long(0))) {
- Url = "Manage/Information.do?todo=OpenInformationList&menuID=" +
- menuID;
- } else if (!catID.equals(new Long(0))) {
- Url = "Manage/Information.do?todo=OpenInformationList&catID=" +
- catID;
- } else {
- Url = "Manage/Information.do?todo=OpenInformation&key=" +
- inf.getInf_Key();
- }
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- is.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", Url);
- return actionMapping.findForward("DeleteInformation");
- }
- public ActionForward OpenInformationList(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- PageInfo pageInfo = null;
- int pageNo = 0;
- String Language = "CN";
- String Key = "";
- Category cat = null;
- Menu menu = null;
- InformationActionForm iaf = (InformationActionForm) actionForm;
- 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("Key") != null) {
- Key = servletRequest.getParameter("Key");
- }
- is.beginTran();
- if (servletRequest.getParameter("catID") != null) {
- cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
- "catID")));
- servletRequest.setAttribute("cat", cat);
- }
- if (servletRequest.getParameter("menuID") != null) {
- menu = ms.GetMenuById(new Long(servletRequest.getParameter(
- "menuID")));
- servletRequest.setAttribute("menu", menu);
- }
- GetTitle(Key, cat, menu, servletRequest);
- pageInfo = is.getPageInfo(Key, cat, menu, iaf.getCondition(), Language,
- pageNo);
- is.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- is.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("pageInfo", pageInfo);
- return actionMapping.findForward("OpenInformationList");
- }
- public ActionForward OpenChirmanInfo(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- List list = null;
- List list2 = null;
- Information inf = null;
- Menu fMenu = new Menu();
- List menuList = null;
- Long fMenuID = new Long(0);
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (servletRequest.getParameter("fMenuID") != null) {
- fMenuID = new Long(servletRequest.getParameter("fMenuID"));
- }
- is.beginTran();
- fMenu = ms.GetMenuById(fMenuID);
- menuList = ms.GetMenuBySuperior(fMenuID, Language);
- inf = is.GetInformationByKey("DSZZL", Language);
- list = is.GetInformationListByKey("HDXX", Language);
- list2 = is.GetInformationListByKey("DSZZC", Language);
- is.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- is.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("menu", fMenu);
- servletRequest.setAttribute("menuList", menuList);
- servletRequest.setAttribute("list", list);
- servletRequest.setAttribute("list2", list2);
- servletRequest.setAttribute("inf", inf);
- return actionMapping.findForward("OpenChirmanInfo");
- }
- }