Business Java Example
private void btn_Print_Click_Process(boolean confirm) throws Exception { // input validation. txt_LastRetrievalDate.validate(this, true); // get locale. DfkUserInfo ui = (DfkUserInfo)getUserInfo(); Locale locale = httpRequest.getLocale(); Connection conn = null; DeadStockInquiryDASCH dasch = null; PrintExporter exporter = null; try { // open connection. conn = ConnectionManager.getRequestConnection(this); dasch = new DeadStockInquiryDASCH(conn, this.getClass(), locale, ui); dasch.setForwardOnly(true); // set input parameters. DeadStockInquiryDASCHParams inparam = new DeadStockInquiryDASCHParams(); inparam.set(DeadStockInquiryDASCHParams.LAST_RETRIEVAL_DATE, txt_LastRetrievalDate.getValue()); // check count. int count = dasch.count(inparam); if (confirm && count > 0) { // show confirm message. this.setConfirm("MSG-W0018\t" + Formatter.getNumFormat(count), false, true); viewState.setString(_KEY_CONFIRMSOURCE, "btn_Print_Click"); return; } else if (count == 0) { message.setMsgResourceKey("6003011"); return; } // DASCH call. dasch.search(inparam); // open exporter. ExporterFactory factory = new WmsExporterFactory(locale, ui); exporter = factory.newPrinterExporter("DeadStockInqList", false); exporter.open(); // export. while (dasch.next()) { Params outparam = dasch.get(); DeadStockInqListParams expparam = new DeadStockInqListParams(); expparam.set(DeadStockInqListParams.DFK_DS_NO, outparam.get(DeadStockInquiryDASCHParams.DFK_DS_NO)); expparam.set(DeadStockInqListParams.DFK_USER_ID, outparam.get(DeadStockInquiryDASCHParams.DFK_USER_ID)); expparam.set(DeadStockInqListParams.DFK_USER_NAME, outparam.get(DeadStockInquiryDASCHParams.DFK_USER_NAME)); expparam.set(DeadStockInqListParams.TO_RETRIEVAL_DAY, inparam.get(DeadStockInquiryDASCHParams.LAST_RETRIEVAL_DATE)); expparam.set(DeadStockInqListParams.SYS_DAY, outparam.get(DeadStockInquiryDASCHParams.SYS_DAY)); expparam.set(DeadStockInqListParams.SYS_TIME, outparam.get(DeadStockInquiryDASCHParams.SYS_TIME)); expparam.set(DeadStockInqListParams.RETRIEVAL_DAY, outparam.get(DeadStockInquiryDASCHParams.RETRIEVAL_DAY)); expparam.set(DeadStockInqListParams.ITEM_CODE, outparam.get(DeadStockInquiryDASCHParams.ITEM_CODE)); expparam.set(DeadStockInqListParams.ITEM_NAME, outparam.get(DeadStockInquiryDASCHParams.ITEM_NAME)); if (!exporter.write(expparam)) { break; } } // execute print. try { exporter.print(); message.setMsgResourceKey("6001010"); } catch (Exception ex) { ex.printStackTrace(); message.setMsgResourceKey("6007034"); return; } } catch (Exception ex) { ex.printStackTrace(); message.setMsgResourceKey(ExceptionHandler.getDisplayMessage(ex, this)); } finally { if (dasch != null) { dasch.close(); } if (exporter != null) { exporter.close(); } DBUtil.close(conn); } }
// $Id: DeadStockInquiryDASCH.java 4690 2009-07-16 00:24:27Z okayama $ package jp.co.daifuku.wms.stock.dasch; /* * Copyright(c) 2000-2007 DAIFUKU Co.,Ltd. All Rights Reserved. * * This software is the proprietary information of DAIFUKU Co.,Ltd. * Use is subject to license terms. */ import static jp.co.daifuku.wms.stock.dasch.DeadStockInquiryDASCHParams.*; import java.sql.Connection; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import java.util.Locale; import jp.co.daifuku.authentication.DfkUserInfo; import jp.co.daifuku.common.CommonException; import jp.co.daifuku.foundation.common.Params; import jp.co.daifuku.wms.base.dbhandler.StockFinder; import jp.co.daifuku.wms.base.dbhandler.StockHandler; import jp.co.daifuku.wms.base.dbhandler.StockSearchKey; import jp.co.daifuku.wms.base.entity.Item; import jp.co.daifuku.wms.base.entity.Stock; import jp.co.daifuku.wms.base.report.AbstractWmsDASCH; import jp.co.daifuku.wms.base.util.DisplayUtil; import jp.co.daifuku.wms.base.util.WmsFormatter; import jp.co.daifuku.wms.handler.SearchKey; import jp.co.daifuku.wms.handler.db.AbstractDBFinder; /** * * @version $Revision: 4690 $, $Date: 2009-07-16 09:24:27 +0900 (木, 16 7 2009) $ * @author BusiTune 1.0 Generator. * @author Last commit: $Author: okayama $ */ public class DeadStockInquiryDASCH extends AbstractWmsDASCH { //------------------------------------------------------------ // fields (upper case only) //------------------------------------------------------------ //------------------------------------------------------------ // class variables (prefix '$') //------------------------------------------------------------ //------------------------------------------------------------ // instance variables (prefix '_') //------------------------------------------------------------ /** * DB Finder */ private AbstractDBFinder _finder = null; /** * Current row */ private int _current = -1; /** * Total number of available records */ private int _total = -1; //------------------------------------------------------------ // constructors //------------------------------------------------------------ /** * Constructor to create DASCH object * @param conn Database Connection * @param parent Caller Class * @param locale Browser Locale * @param ui DfkUserInfo */ public DeadStockInquiryDASCH(Connection conn, Class parent, Locale locale, DfkUserInfo ui) { super(conn, parent, locale, ui); } //------------------------------------------------------------ // public methods //------------------------------------------------------------ /** * Fetches data from Database for given search parametres. * @param p Params search parametres * @throws CommonException Reports all exceptions of the User definition. */ public void search(Params p) throws CommonException { // Create Finder Object _finder = new StockFinder(getConnection()); // Initialize record counts _finder.open(isForwardOnly()); // Create Search Key and search for Records _finder.search(createSearchKey(p, true)); _current = -1; } /** * Returns true if next DB entity is available * Uses when reports are output. * @return returns true if next DB entity is available. else false * @throws CommonException Reports all exceptions of the User definition. */ public boolean next() throws CommonException { _current++; return _total > _current; } /** * Returns next DB entity * This is used when the report is output. * @return DB entity as Param object * @throws CommonException Reports all exceptions of the User definition. */ public Params get() throws CommonException { // get Next entity from finder class Stock[] stocks = (Stock[])_finder.getEntities(1); Params p = new Params(); // conver Entity to Param object for (Stock stock : stocks) { p.set(RETRIEVAL_DAY, WmsFormatter.toDate(stock.getRetrievalDay())); p.set(ITEM_CODE, stock.getItemCode()); p.set(ITEM_NAME, (String)stock.getValue(Item.ITEM_NAME, "")); p.set(DFK_DS_NO, getDsNumber()); p.set(DFK_USER_ID, getUserId()); p.set(DFK_USER_NAME, getUserName()); p.set(SYS_DAY, getPrintDate()); p.set(SYS_TIME, getPrintDate()); break; } // return Pram objstc return p; } /** * * finder,Connection close */ public void close() { if (_finder != null) { _finder.close(); } super.close(); } //------------------------------------------------------------ // accessor methods //------------------------------------------------------------ //------------------------------------------------------------ // package methods //------------------------------------------------------------ //------------------------------------------------------------ // protected methods //------------------------------------------------------------ /** * Returns number of available entities for given search conditions * Uses when reports are output and when the list is shown. * @param p Params , search parameters * @return count , number of available entities * @throws CommonException Reports all exceptions of the User definition. */ protected int actualCount(Params p) throws CommonException { StockHandler handler = new StockHandler(getConnection()); // find count _total = handler.count(createSearchKey(p, false)); return _total; } /** * Returns DB entities for given range * Uses when reports are output. * * @param start , start * @param cnt, end * @return List, Returns the entities as List * @throws CommonException Reports all exceptions of the User definition. */ protected List<Params> rangeGet(int start, int cnt) throws CommonException { List<Params> params = new ArrayList<Params>(); Stock[] stocks = (Stock[])_finder.getEntities(start, start + cnt); for (Stock stock : stocks) { Params p = new Params(); p.set(RETRIEVAL_DAY, WmsFormatter.toDate(stock.getRetrievalDay())); p.set(ITEM_CODE, stock.getItemCode()); p.set(ITEM_NAME, (String)stock.getValue(Item.ITEM_NAME, "")); params.add(p); } return params; } //------------------------------------------------------------ // private methods //------------------------------------------------------------ /** * Sets the search conditions.<BR> * @param param A parameter including the search conditions. * @param isSet Sets false to confirm the number and sets true to get the data to output. * @return SearchKey SearchKey * @throws CommonException Reports all exceptions of the User definition. */ private SearchKey createSearchKey(Params param, boolean isSet) throws CommonException { StockSearchKey key = new StockSearchKey(); // where, group by String retrieval_day = WmsFormatter.toParamDate(param.getDate(LAST_RETRIEVAL_DATE)); key.setRetrievalDay(retrieval_day, "<="); key.setJoin(Stock.CONSIGNOR_CODE, Item.CONSIGNOR_CODE); key.setJoin(Stock.ITEM_CODE, Item.ITEM_CODE); key.setStockIdCollect(); key.setRetrievalDayCollect(); key.setItemCodeCollect(); key.setCollect(Item.ITEM_NAME); key.setRetrievalDayOrder(true); key.setItemCodeOrder(true); key.setLotNoOrder(true); key.setAreaNoOrder(true); key.setLocationNoOrder(true); return key; } //------------------------------------------------------------ // utility methods //------------------------------------------------------------ /** * Returns current repository info for this class * @return version */ public static String getVersion() { return ""; } } //end of class