package com.cwkj.util;
/**
* Pagination Util(include Object)
* @author JayXia
*/
public class Pagination<T> {
private final static int DEFAULT_ROW_SIZE = 6 ;
// private final static int DEFAULT_MAX_SIZE = 9999;
private int totalCount ; //总行数
private int pageSize ; //每页行数
private int currentPage ; //当前页码
private int currentRow ; //当前开始行数
private int maxPage ; //最大页码
private T data ; //分类对象
// private String url ;
/**
* @param totalCount
* @param pageSize
* @param data
* @param currentPage
*/
public Pagination(int totalCount ,int pageSize ,T data ,int currentPage ){
this.totalCount = totalCount;
this.pageSize = pageSize ;
this.maxPage = (totalCount%pageSize==0)?(totalCount/pageSize):(totalCount/pageSize+1);
this.currentPage= currentPage;
this.currentRow = ((this.currentPage - 1) * pageSize)<0?0:(this.currentPage - 1) * pageSize ;
this.data = data;
}
public Pagination(int totalCount ,int pageSize ,T data ){
this(totalCount, pageSize, data, 1);
}
public Pagination(int totalCount ,T data ,int currentPage ){
this(totalCount, DEFAULT_ROW_SIZE, data, currentPage);
}
public Pagination(int totalCount ,T data ){
this(totalCount, DEFAULT_ROW_SIZE, data);
}
//=================Getter/Setter==================
public int getTotalCount() {
return totalCount;
}
public int getPageSize() {
return pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
if (this.currentPage <= 0)
this.currentPage = 1;
if (this.currentPage > this.maxPage)
this.currentPage = this.maxPage;
this.currentRow = (this.currentPage - 1) * this.pageSize ;
}
public int getCurrentRow() {
return currentRow;
}
public int getMaxPage() {
return maxPage;
}
public T getData() {
return data;
}
//====================Method======================
public void nextPage(){
setCurrentPage(getCurrentPage()+1);
}
public void perPage(){
setCurrentPage(getCurrentPage()-1);
}
}
action
package com.cwkj.jxc.action;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cwkj.back.entity.Company;
import com.cwkj.back.entity.User;
import com.cwkj.exception.BizException;
import com.cwkj.jxc.biz.CostAdjustBillItemService;
import com.cwkj.jxc.biz.CostAdjustBillService;
import com.cwkj.jxc.biz.IProductService;
import com.cwkj.jxc.entity.CostAdjustBill;
import com.cwkj.jxc.entity.CostAdjustBillItem;
import com.cwkj.jxc.entity.PdfEntity;
import com.cwkj.util.BaseAction;
import com.cwkj.util.BeanFactory;
import com.cwkj.util.ExportPdfUtil;
import com.cwkj.util.MyJSONUtil;
import com.cwkj.util.Pagination;
import com.opensymphony.xwork2.ModelDriven;
/**
* 成本调整
* @author wzy
*
*/
@SuppressWarnings("unchecked")
public class CostAdjustBillAction extends BaseAction implements ModelDriven<CostAdjustBill>{
/**
*
*/
public final String BIZ_TYPE="成本调整";
private static final long serialVersionUID = 1L;
private CostAdjustBill costAdjustBill;
//上一页还是下一页标识
private int pn;
private IProductService iProductService;
private CostAdjustBillService costAdjustBillService;
private CostAdjustBillItemService costAdjustBillItemService;
private String jsonData;
public static final int PAGE_SIZE=5;
private int currentPage = 1;
/**
* 分页
*/
private Pagination<CostAdjustBill> pagination;
//查询起止日期
private Date startDate;
private Date endDate;
//查询的仓库id
private Integer warehouseId;
private InputStream inputStream;
//生成返回的文件名
private String fileName;
{
iProductService=(IProductService) BeanFactory.getInstance(IProductService.class);
costAdjustBillService=(CostAdjustBillService) BeanFactory.getInstance(CostAdjustBillService.class);
costAdjustBillItemService=(CostAdjustBillItemService) BeanFactory.getInstance(CostAdjustBillItemService.class);
}
//下载pdf返回的name
public String getFileName() {
return returnName();
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public int getPn() {
return pn;
}
public void setPn(int pn) {
this.pn = pn;
}
public Integer getWarehouseId() {
return warehouseId;
}
public void setWarehouseId(Integer warehouseId) {
this.warehouseId = warehouseId;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Pagination<CostAdjustBill> getPagination() {
return pagination;
}
public void setPagination(Pagination<CostAdjustBill> pagination) {
this.pagination = pagination;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public String getJsonData() {
return jsonData;
}
public void setJsonData(String jsonData) {
this.jsonData = jsonData;
}
public CostAdjustBill getCostAdjustBill() {
return costAdjustBill;
}
public void setCostAdjustBill(CostAdjustBill costAdjustBill) {
this.costAdjustBill = costAdjustBill;
}
/**
* 模型驅動
*/
public CostAdjustBill getModel() {
if(costAdjustBill==null){
costAdjustBill = new CostAdjustBill();
}
return costAdjustBill;
}
/**
* 添加明细页面
* @return
*/
public String addUI(){
String jsonString = null;
try {
jsonString = MyJSONUtil.getJSONString(iProductService.products());
} catch (BizException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
requestMap.put("productList",jsonString);
return "addUI";
}
public String add(){
try {
costAdjustBill.setBizType(BIZ_TYPE);
User user = (User) session.get("user1");
costAdjustBill.setCreator(user.getName());
Map map=new HashMap();
for (CostAdjustBillItem cab :costAdjustBill.getCostAdjustBillItem()) {
map.put(cab.getProduct().getId()+cab.getWareHouse().getId(),"");
}
System.out.println(map.size());
if(map.size()<costAdjustBill.getCostAdjustBillItem().size()){
throw new BizException("不能添加重复的商品仓库!");
}
costAdjustBillService.addCostAdjustBill(costAdjustBill);
jsonData="true";
map=null;
} catch (BizException e) {
e.printStackTrace();
jsonData=e.getMessage();
}
return SUCCESS;
}
/**
* 调整单记录
*/
public String list(){
Map<String,Object> map=new HashMap<String, Object>();
map.put("startDate", startDate);
// map.put("startDate",startDate);
map.put("endDate",endDate);
map.put("warehouseId",warehouseId);
int totalCount=costAdjustBillService.selectCostAdjustBillCount(map);
pagination=new Pagination<CostAdjustBill>(totalCount,PAGE_SIZE,costAdjustBill,currentPage);
map.put("pagination",pagination);
List<CostAdjustBill> list=costAdjustBillService.pagCostAdjustBill(map);
requestMap.put("costAdjustBillList",list);
map=null;
return "list";
}
/**
* 分页
* @return
*/
public String pagList(){
Map<String,Object> map=new HashMap<String, Object>();
map.put("startDate", startDate);
// map.put("startDate",startDate);
map.put("endDate",endDate);
map.put("warehouseId",warehouseId);
int totalCount=costAdjustBillService.selectCostAdjustBillCount(map);
pagination=new Pagination<CostAdjustBill>(totalCount,PAGE_SIZE,costAdjustBill,currentPage);
map.put("pagination",pagination);
List<CostAdjustBill> list=costAdjustBillService.pagCostAdjustBill(map);
requestMap.put("costAdjustBillList",list);
map=null;
return "pagList";
}
/**
* 详细页面
* @return
*/
public String detailInfo(){
// List <CostAdjustBillItem> list=costAdjustBillItemService.list(costAdjustBill);
// System.out.println(list);
// requestMap.put("itemList",list);
CostAdjustBill cab=costAdjustBillService.selectCostAndItem(costAdjustBill);
requestMap.put("cab",cab);
return "itemList";
}
/**
* 上下页详细页面
* @return
*/
public String prvOrNextdetailInfo(){
if(pn==0){
CostAdjustBill cab=costAdjustBillService.selectPrvCostAndItem(costAdjustBill); requestMap.put("cab",cab);
}else{
CostAdjustBill cab=costAdjustBillService.selectNextCostAndItem(costAdjustBill);
requestMap.put("cab",cab);
}
return "pONitemList";
}
/**
* 是否有上一页下一页
* @return
*/
public String pnIsExists(){
Map<String,Object> map=new HashMap<String, Object>();
map.put("costAdjustBill", costAdjustBill);
map.put("pn",pn);
jsonData=costAdjustBillService.pnExists(map)+"";
return SUCCESS;
}
public String exportPdf(){
try {
CostAdjustBill cab=costAdjustBillService.selectCostAndItem(costAdjustBill);
PdfEntity<CostAdjustBill> pdfEntity=new PdfEntity<CostAdjustBill>();
Company company=(Company) session.get("company");
pdfEntity.setDataSet(cab);
pdfEntity.setCompanyName(company.getName());
pdfEntity.setTitile("成本调整单");
pdfEntity.setHeaders(new String[]{"序号","商品","单位","调整金额","仓库"});
this.inputStream=ExportPdfUtil.fillData(pdfEntity);
// System.out.println(inputStream);
} catch (BizException e) {
e.printStackTrace();
}
return "Exppdf";
}
private String returnName() {
Date datenow=new Date();
SimpleDateFormat dateFormatNow=new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss");
String dateNow=dateFormatNow.format(datenow);
String s="成本调整单"+dateNow.toString()+".pdf";
try {
return new String(s.getBytes("utf-8"),"iso8859-1");
} catch (UnsupportedEncodingException e) {
return dateNow+".pdf";
}
}
}
js
/*
成本调整单列表的js
*/
var adjustmentlist={
init:{
initEvent:function(){
//移动获得焦点
$("#getHover").wipe({defaultValue:"请输入单据号或备注"});
$("#checkall").controlCheckBox({chname:'checkProduct'});//全选
adjustmentlist.pFunction.search();
adjustmentlist.pFunction.paging();
adjustmentlist.pFunction.detailInfo();
// adjustmentlist.init.initData();
},
//需要组装参数时,调用它,这里是点击查询时组织,有需要则在init时组织
initData:function(){
var word=$("#getHover").val();
if(word=="请输入单据号或备注"){
word="";
}else{
word=$.trim(word);
}
var startDate=$("input[name='startDate']").val();
var endDate=$("input[name='endDate']").val();
var warehouseId=$("#wareHouseType").val();
var billId=$(this).parent().prev().find("input[type='hidden']").val();
adjustmentlist.data.queryData.keyword=word;
adjustmentlist.data.queryData.startDate=startDate;
adjustmentlist.data.queryData.endDate=endDate;
adjustmentlist.data.queryData.warehouseId=warehouseId;
adjustmentlist.data.queryData.billId=billId;
}
},
pFunction:{
//查询
search:function(){
$("#No4 a").each(function(){
if($(this).text()=="查询"){
$(this).unbind("click");
$(this).bind("click",function(){
adjustmentlist.init.initData();
var parameter={
"keyword":adjustmentlist.data.queryData.keyword,
"startDate":adjustmentlist.data.queryData.startDate,
"endDate":adjustmentlist.data.queryData.endDate,
"warehouseId":adjustmentlist.data.queryData.warehouseId
};
// $.post("costAdjustmentAction_pagList.php",parameter,function(data){
//
// });
$("#tableContainer").load("costAdjustmentAction_pagList.php",parameter);
});
}
}
);
},
//分页按钮
paging:function(){
var tableContainer = $("#tableContainer");
var word=$("#getHover").val();
if (word == "请输入单据号或备注") {
word="";
}else{
word=$.trim(word);
}
var startDate=$("input[name='startDate']").val();
var endDate=$("input[name='endDate']").val();
var warehouseId=$("#wareHouseType").val();
// $("#perPageEvent").die("click");
$("#perPageEvent").live("click",function(){
tableContainer.load("costAdjustmentAction_pagList.php",{'currentPage':current-1,'keyword':adjustmentlist.data.queryData.keyword,'startDate':adjustmentlist.data.queryData.startDate,'endDate':adjustmentlist.data.queryData.endDate,'warehouseId':adjustmentlist.data.queryData.warehouseId});
});
// $("#nextPageEvent").die("click");
$("#nextPageEvent").live("click",function(){
tableContainer.load("costAdjustmentAction_pagList.php",{'currentPage':current+1,'keyword':adjustmentlist.data.queryData.keyword,'startDate':adjustmentlist.data.queryData.startDate,'endDate':adjustmentlist.data.queryData.endDate,'warehouseId':adjustmentlist.data.queryData.warehouseId});
});
},
//discard
detailInfo:function(){
$("#detailInfo").live("click",function(){
// adjustmentlist.init.initData.call(this);
// alert(adjustmentlist.data.queryData.billId);
$
});
}
},
data:{
queryData:{
keyword:"",
startDate:"",
endDate:"",
warehouseId:"",
billId:""
}
}
}
$(function(){
// ToolUtil.getBillNo('addCostAdjustment',{tabName:'t_cost_adjust_bill',len:4,prefix:'CBTZ'});
adjustmentlist.init.initEvent();
});
jsp:
<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@taglib uri="/struts-tags" prefix="s" %>
<%@taglib uri="http://cwkj.com/core" prefix="cwkj"%>
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="tablestyle3">
<tr>
<th class="one"><input type="checkbox" id="checkall" value="" class="checkbox"/></th>
<th>单据日期</th>
<th>单据编号</th>
<th>业务类别</th>
<th>金额</th>
<th>备注</th>
<th><span>操作</span></th>
</tr>
<s:iterator value="#request.costAdjustBillList" var="c" status="s">
<tr class="${s.count%2==0?'':'first'}">
<td><input type="checkbox" name="checkProduct" value="${id}" class="checkbox"/></td>
<td><s:date name="billDate" format="yyyy年MM月dd日"/> </td>
<td><s:property value="billNo"/></td>
<td><s:property value="bizType"/></td>
<td><cwkj:showPrice value="${totalAmount}"></cwkj:showPrice></td>
<td><s:property value="remark"/>
<input type="hidden" id="billId" value="${id}" />
</td>
<td><s:a href="costAdjustmentAction_detailInfo.php?id=%{id}" id="detailInfo" title="详细" cssClass="ML5"><img src="${ pageContext.request.contextPath }/images/ico/archives.png"/></s:a>
</td>
</tr>
</s:iterator>
<tr>
<td colspan="13" class="last">
<p class="page">
<s:if test="%{pagination.currentPage <= 1 }">
◀上一页</s:if><s:else>
<a href="javascript:void(0);" id="perPageEvent">
◀上一页</a></s:else>
<span style="padding: 5px">
<span>每页</span><font>${ pagination.pageSize }</font>
<span>条共</span><font>${ pagination.maxPage }</font><span>页</span>
</span>
<s:if test="%{pagination.maxPage <= pagination.currentPage}">
下一页▶</s:if><s:else>
<a href="javascript:void(0);" id="nextPageEvent">
下一页▶</a></s:else>
<a href="javascript:void(0);" id="turnPageEvent">跳转</a>到第
<input type="text" style="width: 15px;text-align: center;" id="turnPage" class="text" value="${ pagination.currentPage }"/>页
</p>
</td>
</tr>
</table>
<script type="text/javascript">
var current = ${pagination.currentPage},
max = ${pagination.maxPage};
//alert(current);
</script>
<script type="text/javascript">
$("#checkall").controlCheckBox({chname:'checkProduct'});
</script>