Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1002542
  • 博文数量: 152
  • 博客积分: 4937
  • 博客等级: 上校
  • 技术积分: 1662
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-05 16:55
文章分类

全部博文(152)

文章存档

2013年(12)

2012年(6)

2011年(58)

2010年(43)

2009年(1)

2008年(15)

2007年(17)

我的朋友

分类: Java

2010-07-06 10:14:22

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.newspager.struts.action;
import java.util.Calendar;
import java.util.Date;
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.displaytag.tags.TableTagParameters;
import org.displaytag.util.ParamEncoder;
import com.newspager.dao.PagerDAO;
import com.newspager.dao.ProviderDAO;
import com.newspager.dao.UserDAO;
import com.newspager.dao.impl.PagerDAOImpl;
import com.newspager.dao.impl.ProviderDAOImpl;
import com.newspager.dao.impl.UserImpl;
import com.newspager.model.Pager;
import com.newspager.model.Provider;
import com.newspager.struts.form.PagerForm;
import com.newspager.vo.VOpager;

public class PagerAction extends BaseAction {
 public ActionForward unspecified(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  PagerForm f = (PagerForm)form;
  
  int pageSize=f.getPageCount();
  int pweek = f.getPweek();
  String searchStr = "";
  if(f.getSearchStr() != null){
   searchStr = f.getSearchStr().trim();
  }
  if(pageSize == 0){
   pageSize = 10;
  }

  //首次打开本系统页面时pweek值是null
  if(pweek==0){
   Calendar cd = Calendar.getInstance();
   cd.setTime(new Date());
   pweek = cd.get(Calendar.DAY_OF_WEEK);
   request.setAttribute("pweek", pweek);
  }else if(pweek==-1){
   pweek=0;
   request.setAttribute("pweek", -1);
  }else{
   request.setAttribute("pweek", pweek);
  }
  
  String name =new ParamEncoder("gridlist").encodeParameterName(TableTagParameters.PARAMETER_PAGE);
  int pageNo = 0;
  try{
    pageNo = Integer.parseInt(request.getParameter(name));
  }catch(Exception e){
    pageNo =1;
  }
  
  PagerDAO dao = new PagerDAOImpl();
  List pagers = dao.SearchByName(pweek, pageSize, pageNo, searchStr);
  //total是分页总记录数
  int total = dao.getTotal(pweek,searchStr);
  request.setAttribute("pagerList", pagers);
  request.setAttribute("total", total);
  request.setAttribute("pageSize", pageSize);
  
  return mapping.findForward("pagerlist");
 }
 public ActionForward updateinput(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  PagerForm f = (PagerForm)form;
  
  //所有供货商列表,显示在页面给用户选择
  UserDAO dao = new UserImpl();
  List u = dao.getUserByDealer();
  request.setAttribute("userType", u);
  
  //要更新的报纸信息
  PagerDAO pdao = new PagerDAOImpl();
  VOpager pager = pdao.getById(f.getId());
  
  
  //报纸已设置有的供货商
  ProviderDAO pdDAO = new ProviderDAOImpl();
  pager.setProvider(pdDAO.getListByPagerId(pager.getId()));
  
  
  request.setAttribute("u", pdDAO.getNoFixUser(pager.getId()));
  request.setAttribute("pager", pager);
  
  return mapping.findForward("updateinput");
 }
 public ActionForward update(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  PagerForm f = (PagerForm)form;
  int[] userId=f.getUserIdList();//供货商id列表
  String message="";
  
  //字符串转日期
  //Date stopDate = DateUtilly.String2Date(f.getStopDate());
  Pager p = new Pager();
  //BeanUtils.copyProperties(p, f);
  p.setName(f.getName().trim());
  p.setPweek(f.getPweek());
  p.setTempWeek(f.getTempWeek());
  p.setOrderNo(f.getOrderNo());
  p.setCanReturn(f.getCanReturn());
  p.setStopDate(f.getStopDate());
  p.setPrice(f.getPrice());
  p.setId(f.getId());
  p.setInvalidation(f.getInvalidation());
  p.setMessageName(f.getMessageName());
  
  if(p.getCanReturn().equals("是")){
   p.setStopDate("");
  }
  
  PagerDAO dao = new PagerDAOImpl();
  if(dao.isExistPager(p)){
   message = "该报纸已经存在,请选用另外名称!!";
  }else{
   if(dao.update(p,userId,f.getNoFixUID())){
    message = "报纸修改成功!!";
   }else{
    message = "报纸修改失败!!";
   }
  }
  request.setAttribute("message", message);
//  return mapping.findForward("pub_update_succes");
  return updateinput(mapping,form,request,response);
 }
 public ActionForward addinput(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  UserDAO dao = new UserImpl();
  request.setAttribute("userType", dao.getUserByDealer());
  return mapping.findForward("addinput");
 }
 public ActionForward add(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  PagerForm f = (PagerForm)form;
  
  int[] userId=f.getUserIdList();
  String message = "";
  
  Pager p = new Pager();
  p.setName(f.getName().trim());
  p.setPweek(f.getPweek());
  p.setOrderNo(f.getOrderNo());
  p.setCanReturn(f.getCanReturn());
  p.setStopDate(f.getStopDate());
  //p.setUserId(f.getUserId());
  p.setPrice(f.getPrice());
  
  PagerDAO dao = new PagerDAOImpl();
  if(dao.isExistPager(p)){
   message = "该报纸已经存在,请选用另外名称!!";
  }else{
   if(dao.add(p,userId)){
    message = "添加成功";
   }else{
    message = "添加失败";
   }
  }
  request.setAttribute("message", message);
  
  return addinput(mapping,form,request,response);
 }
 public ActionForward del(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  PagerForm f = (PagerForm)form;
  
  int[] chkDelete =f.getChkDelete();
  PagerDAO dao = new PagerDAOImpl();
  for(int i=0;i   dao.delete(chkDelete[i]);
  }
  
  request.setAttribute("message", "删除成功");
  return unspecified(mapping,form,request,response);
 }
}
阅读(909) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~