📄 classaction.java
字号:
package edu.yinhe.mis.control;
/**
* @author 李亭 <p>
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Iterator;
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.ClassesDTO;
import edu.yinhe.mis.dto.DictionaryDTO;
import edu.yinhe.mis.dto.SchoolDTO;
import edu.yinhe.mis.vo.ClassesVO;
import edu.yinhe.mis.vo.RoomVO;
import edu.yinhe.mis.vo.SchoolVO;
import edu.yinhe.system.common.AppException;
import edu.yinhe.system.control.BaseAction;
import edu.yinhe.system.vo.PaginationVO;
public class ClassAction extends BaseAction {
/**
* @author 李亭 <p>
* Creation date:05-04-2008
* 新增校区方法
* @param mapping 用来响应转发变量
* @param form 要与ClassForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param schooldto 接收SchoolForm中的变量
* @return forward 指定成功后转发的页面
*/
public ActionForward addClasses(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClassForm classForm = (ClassForm) form;
ClassesDTO classdto = new ClassesDTO();
ActionForward forward=mapping.findForward("input");
try {
BeanUtils.copyProperties(classdto, classForm);
classdto.filer();
service.setDataSource(getDataSource(request,"mydatasource"));
Integer i=(Integer) service.create(classdto);
if(i==1){
forward = mapping.findForward("addclasses");
}
} catch (IllegalAccessException e){
e.printStackTrace();
} catch (InvocationTargetException e){
e.printStackTrace();
} catch (AppException e){
e.printStackTrace();
}
return forward;
}
/**
* @author 李亭 <p>
* Creation date:05-04-2008
* 新增校区方法
* @param mapping 用来响应转发变量
* @param form 要与ClassForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param schooldto 接收SchoolForm中的变量
* @return forward 指定成功后转发的页面
*/
public ActionForward delClasses(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionForward forward=mapping.findForward("input");
String classNo = request.getParameter("classNo");
try {
service.setDataSource(getDataSource(request,"mydatasource"));
Integer i=(Integer) service.remove(classNo);
if(i==1){
forward = mapping.findForward("delclasses");
}
} catch (AppException e){
e.printStackTrace();
}
return forward;
}
/**
* @author 李亭 <p>
* Creation date:05-04-2008
* 浏览校区列表信息
* @param mapping 用来响应转发变量
* @param form 要与SchoolForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param schooldto 接收从SchoolForm中传过来的变量
* @return forward 指定成功后转发的页面
*/
public ActionForward allClasses(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClassForm classForm = (ClassForm) form;
ActionForward forward=mapping.findForward("input");
String type = request.getParameter("type");
String currentPage = request.getParameter("currentPage");
if(currentPage!=null&&"".equals("currentPage")){
currentPage = "1";
}
Object[] objs = null;
try {
ClassesDTO classdto = new ClassesDTO();
BeanUtils.copyProperties(classdto, classForm);
if(classForm.getClassType()!=null&&!"".equals(classForm.getClassType())){
classdto.setClassType(URLDecoder.decode(classForm.getClassType()));
}
if(classForm.getClassState()!=null&&!"".equals(classForm.getClassState())){
classdto.setClassState(URLDecoder.decode(classForm.getClassState()));
}
PaginationVO pvo = new PaginationVO();
if(type==null||type.equals("")||type.equals("0")){
currentPage="1";
}else if(type.equals("1")){
currentPage=String.valueOf(Integer.parseInt(classdto.getCurrentPage())-1);
}else if(type.equals("2")){
currentPage=String.valueOf(Integer.parseInt(classdto.getCurrentPage())+1);
}else if(type.equals("3")){
currentPage= request.getParameter("allPage");
}
pvo.setCurrentPage(Integer.parseInt(currentPage));
classdto.setRowPerPage("6");
classdto.setCurrentPage(String.valueOf(pvo.getCurrentPage()));
service.setDataSource(getDataSource(request,"mydatasource"));
objs = (Object[]) service.alllist(classdto);
int count = ((Integer)objs[1]).intValue();
pvo.setResultsNumber(count);
pvo.setRowsPerPage(6);
pvo.setAllPages((count/pvo.getRowsPerPage())+(count%pvo.getRowsPerPage()>0?1:0));
ArrayList Clist = (ArrayList) objs[0];
if(Clist.size()!=0){
request.setAttribute("Clist", Clist);
request.setAttribute("pvo", pvo);
request.setAttribute("classdto", classdto);
forward = mapping.findForward("allclasses");
}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:05-05-2008
* 从数据字典中获得班级类型
* @param form 要与ClassForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param DictionaryDTO 设置参数到DictionaryDTO对象中
*/
public ActionForward findClassType(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DictionaryDTO dnadto = new DictionaryDTO();
ActionForward forward = mapping.getInputForward();
ArrayList list1=null;
Object[] objs=null;
dnadto.setScope("7");
try {
service.setDataSource(getDataSource(request,"mydatasource"));
objs = (Object[]) service.list(dnadto);
list1 =(ArrayList)objs[0];
if(list1.size()!=0){
request.setAttribute("list1", list1);
}
} catch (AppException e) {
e.printStackTrace();
}
return null;
}
/**
* @author 李亭 <p>
* Creation date:05-05-2008
* 从数据字典中获得班级名称
* @param form 要与ClassForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param DictionaryDTO 设置参数到DictionaryDTO对象中
*/
public ActionForward findClassName(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DictionaryDTO dnadto = new DictionaryDTO();
ActionForward forward = mapping.getInputForward();
ArrayList list3=null;
Object[] objs=null;
dnadto.setScope("8");
try {
service.setDataSource(getDataSource(request,"mydatasource"));
objs = (Object[]) service.list(dnadto);
list3 =(ArrayList)objs[0];
if(list3.size()!=0){
request.setAttribute("list3", list3);
}
} catch (AppException e) {
e.printStackTrace();
}
return null;
}
/**
* @author 李亭 <p>
* Creation date:05-05-2008
* 从数据字典中获得班级类型
* @param form 要与ClassForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param DictionaryDTO 设置参数到DictionaryDTO对象中
*/
public ActionForward findClassState(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DictionaryDTO dnadto = new DictionaryDTO();
ActionForward forward = mapping.getInputForward();
ArrayList list2=null;
Object[] objs=null;
dnadto.setPid("308");
try {
service.setDataSource(getDataSource(request,"mydatasource"));
objs = (Object[]) service.list(dnadto);
list2 =(ArrayList)objs[0];
if(list2.size()!=0){
request.setAttribute("list2", list2);
}
} catch (AppException e) {
e.printStackTrace();
}
return null;
}
/**
* @author 李亭 <p>
* Creation date:04-30-2008
* 根据ID 获得班级信息
* @param form 要与SchoolForm中的变量对应
* @param request 请求数据时所用的变量
* @param response 返回数据时用的变量
* @param schooldto 接收从SchoolForm中传过来的变量
* @return forward 指定成功后转发的页面
*/
public ActionForward load(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ClassForm classForm = (ClassForm) form;
ActionForward forward = mapping.getInputForward();
String id = request.getParameter("id");
int lid = Integer.parseInt(id);
ClassesVO cvo = null;
try {
service.setDataSource(getDataSource(request,"mydatasource"));
cvo = (ClassesVO) service.findById(lid);
if(cvo != null){
request.setAttribute("cvo", cvo);
forward = mapping.findForward("load");
}
} catch (AppException e) {
e.printStackTrace();
}
return forward;
}
/**
* @author 李亭 <p>
* Creation date:04-30-2008
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -