BPP 相关——01
1、InputPageUtil
2、EditPageUtil
----------------------------------------------------------------------------------------------------------
1、InputPageUtil
功能簡述:在輸入畫面中,總是顯示最后一頁,本頁輸入滿了則自動跳到下一頁(如果還有)。
參數:
int ?recordsOfPage —— 每頁顯示的記錄條數(不能小于1,默認10)
int ?inputtedCount —— 已經輸入產品的個數(不能小于 0)
int ?totalCount —— 訂單關聯的產品總個數(不能小于 1)
各方法描述:
a、計算總頁數
int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}b、計算當前頁數
注意:如果 inputtedCount 剛好滿頁。則要繼續判斷 --->?
b-1、如果全部輸入完了,那么當前頁就是本頁
b-2、如果沒有全部輸入完,那么當前頁就為 (本頁+1)
特殊值,inputtedCount 為 0 。計算結果為1,也正確。
int currentPageCount(){ if( inputtedCount % recordsOfPage == 0 ){if( inputtedCount == totalCount ){return inputtedCount / recordsOfPage;}else{return inputtedCount / recordsOfPage + 1;}}return inputtedCount / recordsOfPage + 1;}c、計算最后頁的第一行對應已經輸入的 products (List)的索引(用來將最后部分數據 Copy 出來)顯然這個起始索引只能是,0、10、20、30....
int startIndexForLastPage( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}d、最后頁的 Number 數(轉換成List,方便strut2 的循環標簽使用)
d、判斷是否已經全部輸入
boolean isAllProductsInputted(){return inputtedCount == totalCount;}完整代碼:
package jp.co.snjp.kddi.ht.util;public class InputPageUtil {private static final int DEFAULT_RECORDS_OF_PAGE = 10;private final int recordsOfPage;private final int inputtedCount;private final int totalCount;private InputPageUtil( int inputtedCount, int totalCount ){this( inputtedCount, totalCount, DEFAULT_RECORDS_OF_PAGE );}private InputPageUtil( int inputtedCount, int totalCount, int recordsOfPage ){if( isInvalidParams( inputtedCount, totalCount, recordsOfPage ) ){throw new IllegalStateException("Parameters state error.");}this.inputtedCount = inputtedCount;this.totalCount = totalCount;this.recordsOfPage = recordsOfPage;}private boolean isInvalidParams( int inputtedCount, int totalCount, int recordsOfPage ){if( inputtedCount < 0 || totalCount < 1 || recordsOfPage < 1){return true;}if( totalCount < inputtedCount){return true;}return false;}public int getRecordsOfPage(){return recordsOfPage;}public int getInputtedCount() {return inputtedCount;}public int getTotalCount() {return totalCount;}public static InputPageUtil newInstanceDefaultRecordsOfPage( int inputtedCount, int totalCount ){return new InputPageUtil( inputtedCount, totalCount );}public static InputPageUtil newInstanceSetRecordsOfPage( int inputtedCount, int totalCount, int recordsOfPage ){return new InputPageUtil( inputtedCount, totalCount, recordsOfPage );}boolean isAllProductsInputted(){return inputtedCount == totalCount;}int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}int currentPageCount(){ if( inputtedCount % recordsOfPage == 0 ){if( inputtedCount == totalCount ){return inputtedCount / recordsOfPage;}else{return inputtedCount / recordsOfPage + 1;}}return inputtedCount / recordsOfPage + 1;}int startIndexForLastPage( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}int lastPageNumberCount( int currentPageCount, int totalPageCount ){if( currentPageCount < totalPageCount ){return recordsOfPage;}else if( currentPageCount == totalPageCount ){if( totalCount % recordsOfPage == 0 ){return recordsOfPage;}return totalCount % recordsOfPage;}else{// this can't happenreturn -1;}}public Status computeAllStatus(){int totalPageCount = totalPageCount();int currentPageCount = currentPageCount();int startIndexForLastPage = startIndexForLastPage( currentPageCount );int lastPageNumberCount = lastPageNumberCount( currentPageCount, totalPageCount );boolean allProductsInputted = isAllProductsInputted();return new Status( currentPageCount, totalPageCount, startIndexForLastPage, lastPageNumberCount, allProductsInputted );}public static class Status{private final int totalPageCount;private final int currentPageCount;private final int startIndexForLastPage;private final int lastPageNumberCount;private final boolean allProductsInputted;private Status( int currentPageCount, int totalPageCount, int startIndexForLastPage, int lastPageNumberCount, boolean allProductsInputted ){this.currentPageCount = currentPageCount;this.totalPageCount = totalPageCount;this.startIndexForLastPage =startIndexForLastPage;this.lastPageNumberCount = lastPageNumberCount;this.allProductsInputted = allProductsInputted;}public int getCurrentPageCount() {return currentPageCount;}public int getLastPageNumberCount() {return lastPageNumberCount;}public int getStartIndexForLastPage() {return startIndexForLastPage;}public int getTotalPageCount() {return totalPageCount;}public boolean isAllProductsInputted() {return allProductsInputted;}}}使用示例:
void initContinueManualInputParam( T03SlipWk orderForm, List<T04CaseDtlWk> products ){assert orderForm != null;assert products != null;assert products.size() != 0;productName = orderForm.getProdNm1();productCount = orderForm.getShpVol1().intValue();InputPageUtil.Status inputPageStatus = InputPageUtil.newInstanceDefaultRecordsOfPage( products.size(), productCount ).computeAllStatus();allProductsInput = inputPageStatus.isAllProductsInputted();totalPageCount = inputPageStatus.getTotalPageCount();currentPageCount = inputPageStatus.getCurrentPageCount();int startIndexForLastPage = inputPageStatus.getStartIndexForLastPage();int lastPageNumberCount = inputPageStatus.getLastPageNumberCount();lastPageProducts = lastPageProducts( startIndexForLastPage, products );lastPageRecords = lastPageRecords( lastPageNumberCount );}// 相關的兩個方法List<String> lastPageProducts( int startIndexForLastPage, List<T04CaseDtlWk> products ){List<String> result = new ArrayList<String>();while( startIndexForLastPage < products.size() ){T04CaseDtlWk product = (T04CaseDtlWk)products.get( startIndexForLastPage );result.add( formatNumber( product.getShpWt2() ) );startIndexForLastPage++;}return result;}List<Integer> lastPageRecords( int lastPageNumberCount ){List<Integer> result = new ArrayList<Integer>();for( int i = 0 ; i < lastPageNumberCount ; i++ ){result.add( i );}return result;}2、EditPageUtil
功能簡述:
進入編輯頁面,根據 page_line 參數來確定顯示的“當前頁”和 選中狀態的“當前行”,如果 page_line 為 null (從輸入頁面進入編輯頁面),則默認顯示第一頁,選中第一行。
參數:
int recordsOfPage —— 頁面記錄條數(不能小于1,默認為10)
int inputtedCount —— 已經輸入產品個數(不能小于1,這里如果一個都沒有輸入會構造一個 BlankProduct,這樣進入編輯頁就可以直接輸入)
int totalCount ——?訂單關聯的產品總個數(不能小于 1)
String page_line —— JSP 頁面傳遞的參數,用來確定頁和行
各方法描述:
a、計算總頁數
int totalPageCount(){if( totalCount % recordsOfPage == 0 ){return totalCount / recordsOfPage;}return totalCount / recordsOfPage + 1;}b、計算當前頁 // 1. 第一次從輸入頁面->編輯頁面 ( page_line為null, 默認第一頁面)// 2. 編輯修改保存后->再次進入 (根據 page_line 參數解析)int currentPageCount(){// 1if( page_line == null ){return 1;}// 2int page = parsePage();if( page < 1){return 1;}else if( maxEditablePageCount() < page ){return maxEditablePageCount();}else{return page;}}c、計算當前行 int currentLine( int currentPageCount ){// 1if( page_line == null ){return 1;}// 2int line = parseLine();if( line < 1 ){return 1;}else if( maxEditableLine( currentPageCount ) < line ){return maxEditableLine( currentPageCount );}else{return line;}}d、計算當前頁的記錄條數(也就是 JSP 頁面,HT 的 Select控件 option 的個數)// select 控件要用int productRecordCountOfCurrentPage( int currentPageCount ){if( inputtedCount < ( currentPageCount * recordsOfPage ) ){return inputtedCount - ( currentPageCount - 1 ) * recordsOfPage;}return recordsOfPage;}e、計算當前頁的第一行對應已經輸入的 products (List)的索引(用來將最后部分數據 Copy 出來)
顯然這個起始索引只能是,0、10、20、30....
int startIndexForCopy( int currentPageCount ){return ( currentPageCount - 1 ) * recordsOfPage;}f、判斷是否有上一頁 和是否有下一頁 boolean hasPrePage( int currentPageCount ){return 1 < currentPageCount ? true : false;}boolean hasNextPage( int currentPageCount ){return currentPageCount < maxEditablePageCount() ? true : false;}g、構造 page_line 參數 String pageLine( int currentPageCount, int currentLine ){return currentPageCount + "_" + currentLine;}
使用示例: void initEditJspParam( ){T03SlipWk orderForm = (T03SlipWk) session.get( "SLIP_WK" );List<T04CaseDtlWk> products = getEditableProducts( orderForm );LOG.info( "products.size()=" + products.size() );productName = orderForm.getProdNm1();productCount = orderForm.getShpVol1().intValue();String page_line = request.getParameter( "page_line" );EditPageUtil.Status editPageStatus = EditPageUtil.newInstanceDefaultRecordsOfPage( products.size(), productCount, page_line).computeAllStatus();totalPageCount = editPageStatus.getTotalPageCount();currentPageCount = editPageStatus.getCurrentPageCount();currentLine = editPageStatus.getCurrentLine();currentPageProductRecords = editPageStatus.getProductRecordCountOfCurrentPage();currentPageProducts = currentPageProducts( products, editPageStatus );hasPrePage = editPageStatus.getHasPrePage();hasNextPage = editPageStatus.getHasNextPage();pageLine = editPageStatus.getPageLine();LOG.info( "currentPageCount=" + currentPageCount );LOG.info( "currentLine=" + currentLine );LOG.info( "currentPageProductRecords=" + currentPageProductRecords );LOG.info( "hasPrePage=" + hasPrePage );LOG.info( "hasNextPage=" + hasNextPage );}// 計算顯示在當前頁面的商品List<String> currentPageProducts( List<T04CaseDtlWk> products, EditPageUtil.Status status ){List<String> results = new ArrayList<String>();int currentPageProductRecords = status.getProductRecordCountOfCurrentPage();int startIndexForCopy = status.getStartIndexForCopy();int copyedCount = 0;final String BLANK = " ";while( copyedCount < currentPageProductRecords ){T04CaseDtlWk product = products.get( startIndexForCopy );BigDecimal wt2 = product.getShpWt2();if( wt2 == null ){results.add( BLANK );}else{results.add( manualInputAction.formatNumber( wt2 ) );}startIndexForCopy++;copyedCount++;}return results;} // 獲取可編輯 的商品************************************ 注意這個方法對BlankProduct 的操作List<T04CaseDtlWk> getEditableProducts( T03SlipWk orderForm ){List<T04CaseDtlWk> products = manualInputAction.getProductsFromDB( orderForm );// 商品沒有完全輸入, 在最后加入一個 BlankProduct, 用于輸入if( products.size() < orderForm.getShpVol1().intValue() ){String slipId = orderForm.getSlipId();products.add( constructBlankProduct( slipId ) );}return products;}T04CaseDtlWk constructBlankProduct( String slipId ){T04CaseDtlWk product = new T04CaseDtlWk();product.setSlipId( slipId );// 要保證通過 page_line 計算出來的 caseId 找不到這個BlankProductproduct.setCaseId( -1 );product.setShpWt2( null );return product;}
總結
以上是生活随笔為你收集整理的BPP 相关——01的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据安全架构设计与实战~如何加密结构化数
- 下一篇: mousemove事件java,thre