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

📄 queryexamineeaction.java

📁 中应用程序的访问权限对Java Web Console 中应用程序的访问权限 成功登录 Web 控制台后,可能无法自动访问在该控制台中注册的所有应用程序。通常,必须安装应用程序,才能让所有的用户在控制
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package edu.yinhe.mis.control;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URLDecoder;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

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 org.apache.struts.upload.FormFile;

import edu.yinhe.mis.dto.CheckInfoDTO;
import edu.yinhe.mis.dto.DemoDTO;
import edu.yinhe.mis.dto.ExamineeDTO;
import edu.yinhe.mis.util.DownLoadFile;
import edu.yinhe.mis.vo.CheckInfoVO;


import edu.yinhe.mis.vo.ExamineeVO;
import edu.yinhe.system.common.AppException;

import edu.yinhe.system.control.BaseAction;
import edu.yinhe.system.vo.PaginationVO;
/**
 * 
 * @author 刘洲
 *
 */
public class QueryExamineeAction extends BaseAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method query
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	  public ActionForward query(ActionMapping mapping, ActionForm form,
				                 HttpServletRequest request, HttpServletResponse response) {
		   
			QueryExamineeForm queryExamineeForm=(QueryExamineeForm)form;
			ActionForward forward=null;
			ExamineeDTO examineeDTO=null;
			Object[] object=null;
			String currentPage=request.getParameter("currentPage");
			String type=request.getParameter("type");
			try {
				PaginationVO paginationVO = new PaginationVO();
				examineeDTO=new ExamineeDTO();
				BeanUtils.copyProperties(examineeDTO, queryExamineeForm);
				examineeDTO.setExam_NO(URLDecoder.decode(queryExamineeForm.getExam_NO()));
				examineeDTO.setObject_name(URLDecoder.decode(queryExamineeForm.getObject_name()));
				if(type==null||type.equals("")||type.equals("0")){
					currentPage = "1";
				}else if(type.equals("1")){
					currentPage = String.valueOf(Integer.parseInt(examineeDTO.getCurrentPage())-1);
				}else if(type.equals("2")){
					currentPage = String.valueOf(Integer.parseInt(examineeDTO.getCurrentPage())+1);
				}else if(type.equals("3")){
					currentPage = request.getParameter("allPage");
				}
				examineeDTO.setRowPerPage("6");
				examineeDTO.setCurrentPage(currentPage);
				
				service.setDataSource(getDataSource(request,"mydatasource"));
				object=(Object[])service.alllist(examineeDTO);
				if(object==null){
					object=new Object[2];
				}
				int count=((Integer) object[0]).intValue();
				ArrayList alist=(ArrayList) object[1];
				paginationVO.setRowsPerPage(6);
				paginationVO.setCurrentPage(Integer.parseInt(currentPage));
				paginationVO.setResultsNumber(count);
				paginationVO.setAllPages((count/paginationVO.getRowsPerPage())+(count%paginationVO.getRowsPerPage()>0?1:0));
				if(alist!=null){
					request.setAttribute("paginationVO", paginationVO);
					request.setAttribute("examineeDTO", examineeDTO);
					request.setAttribute("examineelist", alist);
					forward=mapping.findForward("queryexaminee");
				}
				
			}catch (AppException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				
				e.printStackTrace();
			}  

			return forward;
		}
	  
	  public ActionForward queryExaminee (ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response){
			ActionForward forward=null; 
			ExamineeVO examineeVO=null;
			Integer ID=0;
			String IDStr=request.getParameter("examineeid");
			boolean isTrue=false;
			try {
				if(IDStr!=null){
					ID=new Integer(IDStr);
				}
				service.setDataSource(getDataSource(request,"mydatasource"));
				examineeVO=(ExamineeVO) service.load(ID);
				if(examineeVO!=null){
					request.setAttribute("examineeVO", examineeVO);
					forward=mapping.findForward("load");
				}else{
					forward=mapping.findForward("faile");
				}
				
			} catch (AppException e) {
				e.printStackTrace();
			}
			return forward;
		  
	  }
	  
	  public ActionForward updatePage (ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response){
			ActionForward forward=null; 
			ExamineeVO examineeVO=null;
			ArrayList alist=null;
			Integer ID=0;
			String IDStr=request.getParameter("examineeid");
			boolean isTrue=false;
			try {
				if(IDStr!=null){
					ID=new Integer(IDStr);
				}
				service.setDataSource(getDataSource(request,"mydatasource"));
				alist=(ArrayList) service.findAll();
				examineeVO=(ExamineeVO) service.load(ID);
				if(examineeVO!=null){
					request.setAttribute("objectNameList", alist);
					request.setAttribute("examineeVO", examineeVO);
					forward=mapping.findForward("update");
				}else{
					forward=mapping.findForward("faile");
				}
				
			} catch (AppException e) {
				e.printStackTrace();
			}
			return forward;
		  
	  }
	  
	  public ActionForward updateExaminee (ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response){
			ActionForward forward=null; 
			ExamineeDTO examineeDTO=null;
			String IDStr=request.getParameter("id");
			String subjectStr=request.getParameter("subject");
			String checkStr=request.getParameter("check");
			Integer ID=0;
			Integer check_ID=0;
			boolean isTrue=false;
			try {
				if(IDStr!=null){
					ID=new Integer(IDStr);
				}
				if(check_ID!=null){
					check_ID=new Integer(checkStr);
				}
				
				service.setDataSource(getDataSource(request,"mydatasource"));
				isTrue=(Boolean) service.modify(examineeDTO);
				if(isTrue){
					forward=mapping.findForward("update");
				}else{
					forward=mapping.findForward("faile");
				}
			} catch (AppException e) {
				e.printStackTrace();
			}
			return forward;
		  
	  }
	  
	  public ActionForward deleteExaminee (ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response){
			ActionForward forward=null; 
			String IDStr=request.getParameter("examineeid");
			Integer ID=0;
			boolean isTrue=false;
			try {
				if(IDStr!=null){
					ID=new Integer(IDStr);
				}
				service.setDataSource(getDataSource(request,"mydatasource"));
				isTrue=(Boolean) service.remove(ID);
				if(isTrue){
					forward=mapping.findForward("delete");
				}else{
					forward=mapping.findForward("faile");
				}
			} catch (AppException e) {
				e.printStackTrace();
			}
			return forward;
		  
	  }
	  
	  public ActionForward getCheck (ActionMapping mapping, ActionForm form,
              HttpServletRequest request, HttpServletResponse response){
			ArrayList alist=null;
			CheckInfoDTO checkInfoDTO=null;
			CheckInfoVO checkInfoVO=null;
			StringBuffer sb=new StringBuffer();
			String objectName=request.getParameter("s");
			

			try {
				if(objectName!=null){
					try {
						objectName=new String(objectName.getBytes("iso-8859-1"),"gbk");
					} catch (UnsupportedEncodingException e) {
						e.printStackTrace();
					}
				}
System.out.println(objectName);
				checkInfoDTO=new CheckInfoDTO();
				checkInfoDTO.setObject_name(objectName);
				service.setDataSource(getDataSource(request,"mydatasource"));
				alist=(ArrayList) service.list(checkInfoDTO);
				if(alist!=null){
					Iterator it=alist.iterator();
					int n=0;
					while(it.hasNext()){
						checkInfoVO=(CheckInfoVO) it.next();
						if(n>0){
							sb.append(":");
						}
						sb.append(checkInfoVO.getCheck_id());
						n++;
					}
				}
				
			} catch (AppException e) {
				e.printStackTrace();
			}
			try {
				PrintWriter out=response.getWriter();
				out.println(sb);
				out.flush();
				out.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			
			return null;
		  
	  }
	  
	  
	  public ActionForward forwardPage(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response) {
			  ActionForward forward=null;
			  ArrayList alist=null;
			  try {
				service.setDataSource(getDataSource(request,"mydatasource"));
				
				alist=(ArrayList) service.findAll();
				request.setAttribute("subjectList", alist);
				forward=mapping.findForward("importdata");
			} catch (AppException e) {
				
				e.printStackTrace();
			}
			  
			  return forward;
		}
	  
	 
	  
	  public ActionForward importData(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response) {
		  QueryExamineeForm queryExamineeForm=(QueryExamineeForm)form;
System.out.println("ok");
		   String subject=request.getParameter("subject");
	       String checkStr=request.getParameter("check_ID").trim();
System.out.println(subject);
System.out.println(checkStr);

		   Integer checkID=1;
		   if(checkStr!=null&&!"".equals(checkStr)){
			   checkID=Integer.parseInt(checkStr);
		   }
System.out.println(checkID);
		   String[] arr=null;
		
		   ActionForward forward=null;
		   Connection conn =(Connection) getDataSource(request,"mydatasource");
		   String dir=request.getRealPath("/upload");
		   String fileName=null;
		   String fileSize=null;
	       FormFile file=queryExamineeForm.getFile();  
	       InputStream in=null;
	       OutputStream out=null;
	       try {
			fileName=file.getFileName();
			   fileSize=new Integer(file.getFileSize()).toString()+"字节";
				in=file.getInputStream();
				out=new FileOutputStream(dir+"/"+fileName);
				int readed=0;
				byte[] buffer=new byte[1024];
				while((readed=in.read(buffer,0,1024))!=-1){
					out.write(buffer,0,readed);
				}
				if(in != null){
						in.close();
					}
				if(out != null){
						out.close();
					}
System.out.println("文件"+fileName+"已经上传成功了");
System.out.println(dir);
System.out.println(dir+"\\"+fileName);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		DownLoadFile dlf=null;
		try {
			dlf = new DownLoadFile(dir+"\\"+fileName);
			dlf.setSheet("Sheet1");
			String[][] nameArr=dlf.beginUpload();
			arr=new String[nameArr[0].length]; 
			for(int i = 0;i<nameArr.length;i++){
				for(int j = 0;j<nameArr[0].length;j++){
			//		System.out.print(i+"    "+j+"    ");
			//		System.out.print(nameArr[i][j]+"    ");
					arr[j]=nameArr[0][j];
		//		System.out.println(arr[i]);
				}
			//	System.out.println(" ");
			}

		} catch (AppException e) {
			forward = mapping.findForward("uploadFailure");
		
	   }
			
				ExamineeDTO examineeDTO=null;
				for(int j=0;j<arr.length;j++){
					System.out.println(arr[j]);
					examineeDTO =new ExamineeDTO();
					examineeDTO.setName(arr[j]);
					examineeDTO.setExam_NO(this.getRandom());
					examineeDTO.setPassword(this.getRandom());
					examineeDTO.setCheck_ID(checkID);
					examineeDTO.setObject_name(subject);
				
				try {
					service.setDataSource(getDataSource(request,"mydatasource"));
					boolean isTrue=(Boolean) service.create(examineeDTO);
				} catch (AppException e) {
			
					e.printStackTrace();
				}
		
		}

				return mapping.findForward("importsuccess");
		}
	  
	  
	  public String getRandom(){
		  String s="";
		  Random r=new Random();
		  for(int i=0;i<6;i++){
			  int n=r.nextInt(10);
			  s+=n;
		  }
		  return s;
		  
	  }
}

⌨️ 快捷键说明

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