⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictionaryaction.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package edu.yinhe.mis.control;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import edu.yinhe.mis.dto.DictionaryDTO;
import edu.yinhe.mis.vo.DictionaryVO;

import edu.yinhe.system.common.AppException;

import edu.yinhe.system.control.BaseAction;
import edu.yinhe.system.vo.PaginationVO;

/**
 * 
 * @author 马少华
 * 
 */
public class DictionaryAction extends BaseAction {
	/**
	 * @author 马少华
	 *         <p>
	 *         Creation date:04-30-2008 此方法是用来查询所有的记录
	 * @param form
	 *            要与SchoolForm中的变量对应
	 * @param request
	 *            请求数据时所用的变量
	 * @param response
	 *            返回数据时用的变量
	 * @param mapping
	 * @return 返回值是转发的页面
	 * @throws IOException
	 */
	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DictionaryForm dictionaryForm = (DictionaryForm) form;
		ActionForward forward = mapping.getInputForward();
		String currentPage = (String) request.getParameter("currentPage");
		List list = null;
		Object[] objs = null;
		String type = request.getParameter("type");
		try {
			DictionaryDTO dictionaryDto = new DictionaryDTO();
			BeanUtils.copyProperties(dictionaryDto, dictionaryForm);

			dictionaryDto.setName(URLDecoder.decode(dictionaryForm.getName()));
			service.setDataSource(getDataSource(request, "mydatasource"));

			PaginationVO paginationVO = new PaginationVO();
			if (type == null || type.equals("") || type.equals("0")) {
				currentPage = "1";
			} else if (type.equals("1")) {
				currentPage = String.valueOf(Integer.parseInt(dictionaryDto
						.getCurrentPage()) - 1);
			} else if (type.equals("2")) {
				currentPage = String.valueOf(Integer.parseInt(dictionaryDto
						.getCurrentPage()) + 1);
			} else if (type.equals("3")) {
				currentPage = request.getParameter("allPage");
			}
			paginationVO.setCurrentPage(Integer.parseInt(currentPage));

			dictionaryDto.setRowPerPage("8");
			dictionaryDto.setCurrentPage(String.valueOf(paginationVO
					.getCurrentPage()));
			objs = (Object[]) service.alllist(dictionaryDto);
			int count = ((Integer) objs[1]).intValue();

			paginationVO.setResultsNumber(count);
			paginationVO.setRowsPerPage(8);
			paginationVO.setAllPages((count / paginationVO.getRowsPerPage())
					+ (count % paginationVO.getRowsPerPage() > 0 ? 1 : 0));

			list = (List) objs[0];
			if (list != null && count != 0) {
				request.setAttribute("list", list);
				request.setAttribute("paginationVO", paginationVO);
				request.setAttribute("dto", dictionaryDto);
				forward = mapping.findForward("queryDictionary");
			} else {
				forward = mapping.findForward("failingQuery");
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (AppException e) {
			e.printStackTrace();
		}

		return forward;

	}

	/**
	 * @author 马少华
	 *         <p>
	 *         Creation date:04-30-2008 此方法是用来增加一条记录
	 * @param form
	 *            要与SchoolForm中的变量对应
	 * @param request
	 *            请求数据时所用的变量
	 * @param response
	 *            返回数据时用的变量
	 * @param mapping
	 * @return 返回值是转发的页面
	 * @throws IOException
	 */
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DictionaryForm dictionaryForm = (DictionaryForm) form;
		ActionForward forward = mapping.getInputForward();
		DictionaryDTO dictionaryDto = new DictionaryDTO();
		boolean isTrue = false;
		try {
			if (dictionaryForm.getName() != null) {
				BeanUtils.copyProperties(dictionaryDto, dictionaryForm);
				dictionaryDto.filer();
				service.setDataSource(getDataSource(request, "mydatasource"));
				isTrue = (Boolean) service.create(dictionaryDto);
				if (isTrue) {
					request.setAttribute("dictionaryDto", dictionaryDto);
					forward = mapping.findForward("success");
				}
			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (AppException e) {
			e.printStackTrace();
		}
		return forward;

	}

	/**
	 * @author 马少华
	 *         <p>
	 *         Creation date:04-30-2008 此方法是用来删除一条数据
	 * @param form
	 *            要与SchoolForm中的变量对应
	 * @param request
	 *            请求数据时所用的变量
	 * @param response
	 *            返回数据时用的变量
	 * @param mappint
	 * @return 返回值是转发的页面
	 * @throws IOException
	 */
	public ActionForward remove(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ActionForward forward = mapping.getInputForward();
		String id = request.getParameter("did");
		try {
			service.setDataSource(getDataSource(request, "mydatasource"));
			boolean flag = (Boolean) service.remove(id);
			if (flag) {
				forward = new ActionForward(
						"/admins/core/dictionary.html?method=query");
			}
		} catch (AppException e) {
			e.printStackTrace();
		}
		return forward;
	}

	/**
	 * @author 马少华
	 *         <p>
	 *         Creation date:04-30-2008 此方法是用来修改一条数据
	 * @param form
	 *            要与SchoolForm中的变量对应
	 * @param request
	 *            请求数据时所用的变量
	 * @param response
	 *            返回数据时用的变量
	 * @param mappint
	 * @return 返回值是转发的页面
	 * @throws IOException
	 */
	public ActionForward modify(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DictionaryForm dictionaryForm = (DictionaryForm) form;
		DictionaryDTO dictionaryDto = new DictionaryDTO();
		String did = request.getParameter("modid");
		// int id = Integer.getInteger(did);
		dictionaryDto.setId(did);
		ActionForward forward = mapping.getInputForward();
		try {
			BeanUtils.copyProperties(dictionaryDto, dictionaryForm);
			service.setDataSource(getDataSource(request, "mydatasource"));
			boolean flag = (Boolean) service.modify(dictionaryDto);
			if (flag) {
				dictionaryForm.setName(null);
				dictionaryForm.setValue(null);
				dictionaryForm.setScope(null);
				dictionaryDto = null;
				forward = new ActionForward(
						"/admins/core/dictionary.html?method=query");

			}
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (AppException e) {
			e.printStackTrace();
		}
		return forward;

	}

	/**
	 * @author 马少华
	 *         <p>
	 *         Creation date:04-30-2008 此方法是用来根据指定的ID来查询记录
	 * @param form
	 *            要与SchoolForm中的变量对应
	 * @param request
	 *            请求数据时所用的变量
	 * @param response
	 *            返回数据时用的变量
	 * @param mapping
	 * @return 返回值是转发的页面
	 * @throws IOException
	 */
	public ActionForward toEdit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		ActionForward forward = mapping.getInputForward();
		String did = request.getParameter("did");
		int flag = Integer.parseInt(request.getParameter("flag"));
		List list = null;
		Object[] objs = null;
		DictionaryDTO dictionaryDto = new DictionaryDTO();
		dictionaryDto.setId(did);
		try {

			service.setDataSource(getDataSource(request, "mydatasource"));
			objs = (Object[]) service.alllist(dictionaryDto);
			list = (List) objs[0];
			if (list != null) {
				request.setAttribute("list", list);
				if (flag == 0) {
					forward = mapping.findForward("edit");
				}
				if (flag == 1) {
					forward = mapping.findForward("view");
				}
			}
		} catch (AppException e) {
			e.printStackTrace();
		}

		return forward;

	}

	/**
	 * @author 马少华
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return 无反回值 查询一级数据字典
	 */
	public ActionForward cascade(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -