CategoryAction.java~143~
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:5k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.xlchemical.struts.Action;
- import org.apache.struts.actions.DispatchAction;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.ActionForm;
- import com.chinacannel.xlchemical.service.CategoryService;
- import com.chinacannel.xlchemical.struts.ActionForm.CategoryActionForm;
- import com.chinacannel.entity.Category;
- import java.util.List;
- public class CategoryAction extends DispatchAction {
- CategoryService cs = new CategoryService();
- public ActionForward EditCategory(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- CategoryActionForm caf = (CategoryActionForm) actionForm;
- Category cat = new Category();
- String Language = "CN";
- boolean b = false;
- String Message = "";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- cs.beginTran();
- if (!caf.getId().equals(new Long(0))) {
- cat = cs.GetCategoryById(caf.getId());
- }
- cat.setCat_Key(caf.getKey());
- cat.setCat_Name(caf.getName());
- cat.setCat_Language(Language);
- cat.setCat_Order(caf.getOrder());
- if (!caf.getId().equals(new Long(0))) {
- cat.setCat_ID(caf.getId());
- b = cs.UpdateCategory(cat);
- Message = "更新成功,请返回!";
- } else {
- b = cs.AddCategory(cat);
- Message = "添加成功,请返回!";
- }
- cs.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- cs.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "操作失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url",
- "/Manage/Category.do?todo=OpenCategory");
- return actionMapping.findForward("EditCategory");
- }
- public ActionForward OpenCategory(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- String key = "";
- List list = null;
- Long catID = new Long(0);
- Category cat = null;
- String Language = "CN";
- try {
- if (servletRequest.getSession().getAttribute("Language") != null) {
- Language = servletRequest.getSession().getAttribute("Language").
- toString();
- }
- if (servletRequest.getParameter("key") != null) {
- key = servletRequest.getParameter("key");
- }
- if (servletRequest.getParameter("catID") != null) {
- catID = new Long(servletRequest.getParameter("catID"));
- }
- cs.beginTran();
- if (!catID.equals(new Long(0))) {
- cat = cs.GetCategoryById(catID);
- }
- list = cs.getCategoryListByKey(key, Language);
- cs.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- cs.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- servletRequest.setAttribute("cat", cat);
- servletRequest.setAttribute("key", key);
- servletRequest.setAttribute("list", list);
- return actionMapping.findForward("OpenCategory");
- }
- public ActionForward DeleteCategory(ActionMapping actionMapping,
- ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- Category cat = null;
- boolean b = false;
- String Message = "";
- String key = "";
- try {
- if(servletRequest.getParameter("key") != null){
- key = servletRequest.getParameter("key");l
- }
- cs.beginTran();
- cat = cs.GetCategoryById(new Long(servletRequest.getParameter(
- "catID")));
- b = cs.DeleteCategory(cat);
- Message = "删除成功,请返回!";
- cs.commit();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- try {
- cs.rollback();
- } catch (Exception ex2) {
- log.error(ex2.getMessage(), ex2);
- }
- }
- if (b == false) {
- Message = "删除失败,请返回!";
- }
- servletRequest.setAttribute("Message", Message);
- servletRequest.setAttribute("Url", "/Manage/Category.do?todo=OpenCategory&key=QYRY");
- return actionMapping.findForward("DeleteCategory");
- }
- }