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

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

开发平台:

JavaScript

  1. package com.chinacannel.xlchemical.struts.Action;
  2. import org.apache.struts.actions.DispatchAction;
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.apache.struts.action.ActionForward;
  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.CategoryService;
  9. import com.chinacannel.xlchemical.struts.ActionForm.CategoryActionForm;
  10. import com.chinacannel.entity.Category;
  11. import java.util.List;
  12. public class CategoryAction extends DispatchAction {
  13.     CategoryService cs = new CategoryService();
  14.     public ActionForward EditCategory(ActionMapping actionMapping,
  15.                                       ActionForm actionForm,
  16.                                       HttpServletRequest servletRequest,
  17.                                       HttpServletResponse servletResponse) {
  18.         CategoryActionForm caf = (CategoryActionForm) actionForm;
  19.         Category cat = new Category();
  20.         String Language = "CN";
  21.         boolean b = false;
  22.         String Message = "";
  23.         try {
  24.             if (servletRequest.getSession().getAttribute("Language") != null) {
  25.                 Language = servletRequest.getSession().getAttribute("Language").
  26.                            toString();
  27.             }
  28.             cs.beginTran();
  29.             if (!caf.getId().equals(new Long(0))) {
  30.                 cat = cs.GetCategoryById(caf.getId());
  31.             }
  32.             cat.setCat_Key(caf.getKey());
  33.             cat.setCat_Name(caf.getName());
  34.             cat.setCat_Language(Language);
  35.             cat.setCat_Order(caf.getOrder());
  36.             if (!caf.getId().equals(new Long(0))) {
  37.                 cat.setCat_ID(caf.getId());
  38.                 b = cs.UpdateCategory(cat);
  39.                 Message = "更新成功,请返回!";
  40.             } else {
  41.                 b = cs.AddCategory(cat);
  42.                 Message = "添加成功,请返回!";
  43.             }
  44.             cs.commit();
  45.         } catch (Exception ex) {
  46.             log.error(ex.getMessage(), ex);
  47.             try {
  48.                 cs.rollback();
  49.             } catch (Exception ex2) {
  50.                 log.error(ex2.getMessage(), ex2);
  51.             }
  52.         }
  53.         if (b == false) {
  54.             Message = "操作失败,请返回!";
  55.         }
  56.         servletRequest.setAttribute("Message", Message);
  57.         servletRequest.setAttribute("Url",
  58.                                     "/Manage/Category.do?todo=OpenCategory");
  59.         return actionMapping.findForward("EditCategory");
  60.     }
  61.     public ActionForward OpenCategory(ActionMapping actionMapping,
  62.                                       ActionForm actionForm,
  63.                                       HttpServletRequest servletRequest,
  64.                                       HttpServletResponse servletResponse) {
  65.         String key = "";
  66.         List list = null;
  67.         Long catID = new Long(0);
  68.         Category cat = null;
  69.         String Language = "CN";
  70.         try {
  71.             if (servletRequest.getSession().getAttribute("Language") != null) {
  72.                 Language = servletRequest.getSession().getAttribute("Language").
  73.                            toString();
  74.             }
  75.             if (servletRequest.getParameter("key") != null) {
  76.                 key = servletRequest.getParameter("key");
  77.             }
  78.             if (servletRequest.getParameter("catID") != null) {
  79.                 catID = new Long(servletRequest.getParameter("catID"));
  80.             }
  81.             cs.beginTran();
  82.             if (!catID.equals(new Long(0))) {
  83.                 cat = cs.GetCategoryById(catID);
  84.             }
  85.             list = cs.getCategoryListByKey(key, Language);
  86.             cs.commit();
  87.         } catch (Exception ex) {
  88.             log.error(ex.getMessage(), ex);
  89.             try {
  90.                 cs.rollback();
  91.             } catch (Exception ex2) {
  92.                 log.error(ex2.getMessage(), ex2);
  93.             }
  94.         }
  95.         servletRequest.setAttribute("cat", cat);
  96.         servletRequest.setAttribute("key", key);
  97.         servletRequest.setAttribute("list", list);
  98.         return actionMapping.findForward("OpenCategory");
  99.     }
  100.     public ActionForward DeleteCategory(ActionMapping actionMapping,
  101.                                         ActionForm actionForm,
  102.                                         HttpServletRequest servletRequest,
  103.                                         HttpServletResponse servletResponse) {
  104.         Category cat = null;
  105.         boolean b = false;
  106.         String Message = "";
  107.         String key = "";
  108.         try {
  109.             if(servletRequest.getParameter("key") != null){
  110.                 key = servletRequest.getParameter("key");l
  111.             }
  112.             cs.beginTran();
  113.             cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
  114.                     "catID")));
  115.             b = cs.DeleteCategory(cat);
  116.             Message = "删除成功,请返回!";
  117.             cs.commit();
  118.         } catch (Exception ex) {
  119.             log.error(ex.getMessage(), ex);
  120.             try {
  121.                 cs.rollback();
  122.             } catch (Exception ex2) {
  123.                 log.error(ex2.getMessage(), ex2);
  124.             }
  125.         }
  126.         if (b == false) {
  127.             Message = "删除失败,请返回!";
  128.         }
  129.         servletRequest.setAttribute("Message", Message);
  130.         servletRequest.setAttribute("Url", "/Manage/Category.do?todo=OpenCategory&key=QYRY");
  131.         return actionMapping.findForward("DeleteCategory");
  132.     }
  133. }