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

📄 planinfoaction.java

📁 该项目采用Struts框架
💻 JAVA
字号:
package com.cattsoft.plan.action;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;

import com.cattsoft.DAOFactory.DAOFactory;
import com.cattsoft.vo.Plan;
import com.cattsoft.vo.Task;

public class PlanInfoAction extends DispatchAction {
	
	////根据任务id查询其名称
	public ActionForward queryTaskName(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int tId = Integer.parseInt(request.getParameter("t_id"));
		String taskName = null;
		try {
			 taskName = DAOFactory.getPlanInstance().selectBy(tId);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("t_id",tId);
		request.setAttribute("t_name",taskName);
		return mapping.findForward("queryTaskName");
	}
	//删除计划Action
	public ActionForward delPlan(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String path=null;
		DynaActionForm dyform =(DynaActionForm) form;
		//得到计划id
		String[] p_id =request.getParameterValues("p_id");		
		//判断计划id是否为空
		if(p_id==null || p_id.equals("")){
			request.setAttribute("error","请选择要删除的计划信息!");
			path="deleteFailed";
		}else{
			for(int i=0;i<p_id.length;i++){				
				int pId = Integer.parseInt(p_id[i]);	
				Plan mp = new Plan();
				mp.setP_id(pId);
				//根据计划id去删除对应的计划			
				try {
					DAOFactory.getPlanInstance().delPlan(pId);
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}			
			path="deleteSuccessed";
		}		
		//得到任务id
		int tId = (Integer)dyform.get("t_id");
		//根据任务id查询对应的计划详细信息	
		List<Plan> list2 = new ArrayList<Plan>();
			try {
				list2 = DAOFactory.getPlanInstance().query(tId);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			//判断计划是否为空,若为空则更新任务状态为'未实施'
			if(list2.size()==0){
				try {
					DAOFactory.getPlanInstance().updateTask(tId);
				} catch (ClassNotFoundException e) {
					e.printStackTrace();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		//根据任务id查询任务详细信息
		List<Task> list1 = new ArrayList<Task>();			
				try {
					list1 = DAOFactory.getPlanInstance().queryTask(tId);
				} catch (ClassNotFoundException e1) {
					e1.printStackTrace();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
		
		
		request.setAttribute("tId", tId);
		request.setAttribute("list1",list1);
		request.setAttribute("list2", list2);
		return mapping.findForward(path);
	}
	
	//计划反馈前Action
	public ActionForward feedbackPlan1(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//得到计划id
		int pId = Integer.parseInt(request.getParameter("p_id"));
		Plan mp = new Plan();
		mp.setP_id(pId);
		//根据计划id去查询对应计划的详细信息
		List<Plan> list = new ArrayList<Plan>();
		try {
			list =DAOFactory.getPlanInstance().queryBy(pId);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list",list);
		return mapping.findForward("feedbackSuccessed1");
	}
	
	//计划反馈后Action
	public ActionForward feedbackPlan2(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm dyform = (DynaActionForm) form;
		//得到计划id
		int pId = (Integer)dyform.get("p_id");
		//得到任务id
		int tId =(Integer)dyform.get("t_id");
		//得到反馈信息的值
		String fInfo =(String)dyform.get("f_info");
		//得到计划状态值
		String pState = (String)dyform.get("p_state");
		//得到反馈状态值
		String fState = (String)dyform.get("f_state");
		FormFile theFile =(FormFile)dyform.get("file");					
		String filePath = request.getSession().getServletContext().getRealPath("/");				
		String fileName = theFile.getFileName();
		String fileType = theFile.getContentType();
		try {
			byte[] fileData = theFile.getFileData();			
			FileOutputStream fos = new FileOutputStream(new File(filePath+fileName));
			fos.write(fileData);
			fos.flush();
			fos.close();
		} catch (FileNotFoundException e2) {
			e2.printStackTrace();
		} catch (IOException e2) {
			e2.printStackTrace();
		}										

		Plan mp = new Plan();
		mp.setT_id(tId);
		mp.setP_id(pId);
		mp.setP_state(pState);
		mp.setF_state(fState);
		mp.setF_info(fInfo);
		//更新计划表数据
		try {
			DAOFactory.getPlanInstance().updatePlan(pId,pState,fState,fInfo,fileName,fileType);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		//根据任务id查询对应任务的详细信息
		Task mt = new Task();
		mt.setT_id(tId);
		List<Task> list1 = new ArrayList<Task>();
		
			try {
				list1 = DAOFactory.getPlanInstance().queryTask(tId);
			} catch (ClassNotFoundException e1) {				
				e1.printStackTrace();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}

		//根据任务id查询对应的计划信息	
		List<Plan> list2 = new ArrayList<Plan>();
		try {
			list2 = DAOFactory.getPlanInstance().query(tId);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("tId", tId);
		request.setAttribute("list1",list1);
		request.setAttribute("list2", list2);
		return mapping.findForward("feedbackSuccessed2");
	}	
	
	//根据查询得到的计划id去查询其对应的计划详细信息
	public ActionForward planDetailed(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int pId = Integer.parseInt(request.getParameter("p_id"));
		List<Plan> list = new ArrayList<Plan>();
		try {
			list = DAOFactory.getPlanInstance().queryBy(pId);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.setAttribute("list",list);
		return mapping.findForward("planDetailed");
	}
}

⌨️ 快捷键说明

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