POS管理系统之出入库单分页查询

时间:2023-03-09 15:26:03
POS管理系统之出入库单分页查询

JSP:

<html>
  <head>
    <title>My JSP 'inOutKuPage.jsp' starting page</title>
 <style type="text/css">
        table{
          border-color: blue;
        }
        .a{
         background-color: blue;
         text-align: center;
        }
    </style>
 <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.10.2.js"></script>
 <script type="text/javascript">
       $(function(){
        $("#query").click(function(){
           var url='<%=request.getContextPath()%>/inOutPage.do';
           $.post(url,
               {
                  inoutno:$("#no").val(),
                  people:$("#people").val()
               },
               function(data){
                 $("tr[id^='order']").remove();
                 $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
                 $.each(data.records,function(i,d){
                    var rows="<tr id='order'"+i+">";
                    rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
                 });
               },
               "json");
        });
        $("#pre").click(function(){
           var url='<%=request.getContextPath()%>/inOutPage.do';
           $.post(url,
                {
                 inoutno:$("#no").val(),
                 people:$("#people").val(),
                 pageNo:$("#prePage").val(),
                },
                function(data){
                $("tr[id^='order']").remove();
     $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
     $.each(data.records,function(i,d){
      var rows="<tr id='order'"+i+">";
        rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
     });
                },
           "json");
        });
        $("#next").click(function(){
              var url='<%=request.getContextPath()%>/inOutPage.do';
               $.post(url,
                {
                 inoutno:$("#no").val(),
                 people:$("#people").val(),
                 pageNo:$("#nextPage").val(),
                },
                  function(data){
                $("tr[id^='order']").remove();
     $("#prePage").val(data.prePage);
     $("#nextPage").val(data.nextPage);
     $("#total").html(data.totalRecords);
     $.each(data.records,function(i,d){
      var rows="<tr id='order'"+i+">";
        rows+="<td>"+d.inoutno+"</td>";
                    rows+="<td>"+d.username+"</td>";
                    rows+="<td>"+d.people+"</td>";
                    rows+="<td>"+d.inout+"</td>";
                    rows+="<td>"+d.ctime+"</td>";
                    rows+="</tr>";
                    $("#show").append(rows);
     });
                },
                "json");
        });
      });
 </script>
  </head>
 
  <body>
        <table border="1px">
        <tr>
           <input type="hidden" id="prePage">
     <input type="hidden" id="nextPage">
           <td class="a">入出库单编号</td>
           <td><input type="text" name="no" id="no"></td>
           <td class="a">入/出库</td>
           <td><input type="radio" name="a" value="入库" id="a">入库
               <input type="radio" name="a" value="出库" id="a">出库
           </td>
        </tr>
        <tr>
           <td class="a">经办人</td>
           <td><input type="text" name="people" id="people"></td>
           <td class="a">日期</td>
           <td><input type="text" name="date" id="date"></td>
        </tr>
        <tr>
           <td colspan="4" align="center"><input type="button" value="查询" id="query">
           <input type="submit" value="清空">
           <input type="button" id="pre" value="上一页">
     <input type="button" id="next" value="下一页">
     <span id="total"></span></td>
        </tr>
     </table>
     <table border="1px" id="show">
         <tr>
           <td>入出库单编号</td>
           <td>客户名称</td>
           <td>经办人</td>
           <td>入/出库</td>
           <td>操作时间</td>
           <td>操作</td>
         </tr>
                  </table>
  </body>
</html>

DAO:

public class InOutPageDao extends BaseDao {
 public List<InOut> findCusinfosByPageNo(InOut condition,PageUtitily<InOut> page) {
  List<InOut> list =new ArrayList<InOut>();
  String select="select * from inout where 1=1";
  StringBuilder sb = new StringBuilder(select);
  List<Object> params = new ArrayList<Object>();
  if(condition!=null){
   if(condition.getInoutno()!=null&& !"".equals(condition.getInoutno())){
   sb.append(" AND INOUTNO LIKE ?");
   params.add("%"+condition.getInoutno()+"%");
  }
      if(condition.getPeople()!=null &&!"".equals(condition.getPeople())){
       sb.append(" AND PEOPLE LIKE ?");
       params.add("%"+condition.getPeople()+"%");
  }
  }
  params.add(page.getStartRecord());
  params.add(page.getEndRecord());
  ResultSet rs = this.executeQueryForPage(sb.toString(), params);
  try {
   while(rs.next()){
     InOut cus=new InOut();
     cus.setInoutno(rs.getString("INOUTNO"));
     cus.setUsername(rs.getString("USERNAME"));
     cus.setPeople(rs.getString("PEOPLE"));
     cus.setInout(rs.getString("INOUT"));
     cus.setCtime(rs.getString("CTIME"));
    list.add(cus);
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }finally{
   this.closeAll();
  }
  return list;
 }
 public int findCusinfosCount(InOut condition) {
  String select ="SELECT * FROM INOUT C where 1=1";
  StringBuilder sb = new StringBuilder(select);
  List<Object> params = new ArrayList<Object>();
  if(condition!=null){
   if(condition.getInoutno()!=null&& !"".equals(condition.getInoutno())){
   sb.append(" AND INOUTNO LIKE ?");
   params.add("%"+condition.getInoutno()+"%");
  }
      if(condition.getPeople()!=null &&!"".equals(condition.getPeople())){
       sb.append(" AND PEOPLE LIKE ?");
       params.add("%"+condition.getPeople()+"%");
  }
  }
  return this.executeQueryForTatalCount(sb.toString(), params);
  
 }
}

实体类:

public class PageUtitily<T> {
  private List<T> records;
  private int curPage=1;//当前页码
  private int totalRecords;//符合条件的总记录数
  private int totalPages;//总页码数
  private int pageSize=3;//页面大小
  private int nextPage;//下一页
  private int prePage;//上一页
 
  private int startRecord;
  private int endRecord;
 
  public List<T> getRecords() {
  return records;
 }

public void setRecords(List<T> records) {
  this.records = records;
 }

public int getPageSize() {
  return pageSize;
 }

public void setPageSize(int pageSize) {
  this.pageSize = pageSize;
 }

public int getCurPage() {
  return curPage;
 }

public int getNextPage() {
  return nextPage;
 }

public int getPrePage() {
  return prePage;
 }

public int getStartRecord() {
  return startRecord;
 }

public int getEndRecord() {
  return endRecord;
 }
 
 public PageUtitily(int pageNo){
  this.curPage=pageNo;
  this.startRecord=(this.curPage-1)*pageSize+1;
  this.endRecord=this.curPage*pageSize;
  this.prePage=this.curPage-1;
  if(this.prePage<=0){
   this.prePage=1;
  }
 }
 
 public void setTotalRecords(int totalRecords) {
  this.totalRecords = totalRecords;
  //计算总页码
  this.totalPages=this.totalRecords%pageSize==0?this.totalRecords/this.pageSize:this.totalRecords/this.pageSize+1;
  
  //计算下一页
  this.nextPage=this.curPage+1;
  if(this.nextPage>totalPages){
   this.nextPage=totalPages;
  }
 }
}

SERVICE:

public class InOutPageService {
 InOutPageDao iod=new InOutPageDao();
 public PageUtitily<InOut> findCusOrderByPage(InOut condition,int pageNo) {
  PageUtitily<InOut> pageObj = new PageUtitily<InOut>(pageNo);
  pageObj.setTotalRecords(iod.findCusinfosCount(condition));
  
  List<InOut> list = iod.findCusinfosByPageNo(condition, pageObj);
  pageObj.setRecords(list);
  return pageObj;
 }

}

SERVLET:

public class InOutPageServlet extends HttpServlet {
    InOutPageService iops=new InOutPageService();
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  doPost(req, resp);
 }

@Override
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
   throws ServletException, IOException {
  req.setCharacterEncoding("utf-8");
   String inoutno=req.getParameter("inoutno");
    String inout=req.getParameter("a");
    String people=req.getParameter("people");
    String ctime=req.getParameter("date");
   
          String curPage=req.getParameter("pageNo");
          if(curPage==null||"".equals(curPage)){
           curPage="1";
          }
    InOut io=new InOut(inoutno, people, inout, ctime);
    PageUtitily<InOut> page=iops.findCusOrderByPage(io, Integer.valueOf(curPage));
    JSONObject array=JSONObject.fromObject(page);
    resp.setContentType("text/html;charset=utf-8");
    PrintWriter out=resp.getWriter();
    out.print(array.toString());
    out.close();
 }
}