Reader.java~12~
上传用户:toby828
上传日期:2015-06-26
资源大小:8558k
文件大小:6k
- package com.action;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.actionForm.ReaderForm;
- import org.apache.struts.action.*;
- import com.dao.ReaderDAO;
- import java.util.Date;
- public class Reader extends Action {
- private ReaderDAO readerDAO = null;
- public Reader() {
- this.readerDAO = new ReaderDAO();
- }
- public ActionForward perform(ActionMapping mapping, ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- String action =request.getParameter("action");
- System.out.println("nreader*********************action="+action);
- if(action==null||"".equals(action)){
- request.setAttribute("error","您的操作有误!");
- return mapping.findForward("error");
- }else if("readerAdd".equals(action)){
- return readerAdd(mapping,form,request,response);
- }else if("readerQuery".equals(action)){
- return readerQuery(mapping,form,request,response);
- }else if("readerModifyQuery".equals(action)){
- return readerModifyQuery(mapping,form,request,response);
- }else if("readerModify".equals(action)){
- return readerModify(mapping,form,request,response);
- }else if("readerDel".equals(action)){
- return readerDel(mapping,form,request,response);
- }
- request.setAttribute("error","操作失败!");
- return mapping.findForward("error");
- }
- /***********************添加读者类型信息**************************/
- private ActionForward readerAdd(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest servletRequest, HttpServletResponse servletResponse){
- ReaderForm readerForm = (ReaderForm) actionForm;
- readerForm.setName(readerForm.getName());
- readerForm.setSex(readerForm.getSex());
- readerForm.setBarcode(readerForm.getBarcode());
- readerForm.setVocation(readerForm.getVocation());
- readerForm.setBirthday(readerForm.getBirthday());
- readerForm.setPaperType(readerForm.getPaperType());
- readerForm.setPaperNO(readerForm.getPaperNO());
- readerForm.setTel(readerForm.getTel());
- readerForm.setEmail(readerForm.getEmail());
- //获取系统日期
- Date date1=new Date();
- java.sql.Date date=new java.sql.Date(date1.getTime());
- readerForm.setCreateDate(date.toString());
- readerForm.setOperator(readerForm.getOperator());
- readerForm.setRemark(readerForm.getRemark());
- readerForm.setTypeid(readerForm.getTypeid());
- int a=readerDAO.insert(readerForm);
- if(a==0){
- servletRequest.setAttribute("error","读者信息添加失败!");
- return actionMapping.findForward("error");
- }else if(a==2){
- servletRequest.setAttribute("error","该读者信息已经添加!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("readerAdd");
- }
- }
- /***********************查询全部读者信息**************************/
- private ActionForward readerQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- String str=null;
- servletRequest.setAttribute("reader",readerDAO.query(str));
- return actionMapping.findForward("readerQuery");
- }
- /***********************查询修改读者信息**************************/
- private ActionForward readerModifyQuery(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderForm readerForm=(ReaderForm)actionForm;
- readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- servletRequest.setAttribute("readerQueryif",readerDAO.queryM(readerForm));
- return actionMapping.findForward("readerQueryModify");
- }
- /***********************修改读者信息**************************/
- private ActionForward readerModify(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderForm readerForm=(ReaderForm)actionForm;
- readerForm.setName(readerForm.getName());
- readerForm.setSex(readerForm.getSex());
- readerForm.setBarcode(readerForm.getBarcode());
- readerForm.setVocation(readerForm.getVocation());
- readerForm.setBirthday(readerForm.getBirthday());
- readerForm.setPaperType(readerForm.getPaperType());
- readerForm.setPaperNO(readerForm.getPaperNO());
- readerForm.setTel(readerForm.getTel());
- readerForm.setEmail(readerForm.getEmail());
- readerForm.setOperator(readerForm.getOperator());
- readerForm.setRemark(readerForm.getRemark());
- readerForm.setTypeid(readerForm.getTypeid());
- int ret=readerDAO.update(readerForm);
- if(ret==0){
- servletRequest.setAttribute("error","修改读者信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("readerModify");
- }
- }
- /***********************删除读者信息**************************/
- private ActionForward readerDel(ActionMapping actionMapping,ActionForm actionForm,HttpServletRequest servletRequest,HttpServletResponse servletResponse){
- ReaderForm readerForm=(ReaderForm)actionForm;
- readerForm.setId(Integer.valueOf(servletRequest.getParameter("ID")));
- int ret=readerDAO.delete(readerForm);
- if(ret==0){
- servletRequest.setAttribute("error","删除读者信息失败!");
- return actionMapping.findForward("error");
- }else{
- return actionMapping.findForward("readerDel");
- }
- }
- }