文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>pagerAction(displaytag)

pagerAction(displaytag)

时间:2010-07-06  来源:mozhx

/*
 * 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<chkDelete.length;i++){
   dao.delete(chkDelete[i]);
  }
  
  request.setAttribute("message", "删除成功");
  return unspecified(mapping,form,request,response);
 }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载