From 4896450966d1a55b5ca1a646054e1617149a071f Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Tue, 27 Jan 2009 04:25:42 +0000 Subject: [PATCH] FR#2538335 Swing POS: terminal selection Refactoring to debug and solve easier. Issue is rs returns only POS_IDs. Why? Anyone knows? https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2538335&group_id=176962 --- base/src/org/compiere/model/MPOS.java | 19 +++++++++- client/src/org/compiere/pos/PosPanel.java | 46 +++++------------------ 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/base/src/org/compiere/model/MPOS.java b/base/src/org/compiere/model/MPOS.java index e1f8c00840..60da8ae9d9 100644 --- a/base/src/org/compiere/model/MPOS.java +++ b/base/src/org/compiere/model/MPOS.java @@ -18,7 +18,7 @@ package org.compiere.model; import java.sql.ResultSet; import java.util.Properties; - +import java.util.List; import org.compiere.util.CCache; import org.compiere.util.Msg; @@ -49,6 +49,23 @@ public class MPOS extends X_C_POS return retValue; } // get + /** + * Get POSes for passed argument + * @param ctx context + * @param C_POS_ID id + * @return POSes + */ + public static MPOS[] getAll (Properties ctx, String field, int ID) + { + String whereClause = field+"=?"; + List list = new Query(ctx, Table_Name, whereClause, null) + .setParameters(new Object[]{ID}) + .setOnlyActiveRecords(true) + .setOrderBy(COLUMNNAME_Name) + .list(); + return list.toArray(new MPOS[list.size()]); + } // get + /** Cache */ private static CCache s_cache = new CCache("C_POS", 20); diff --git a/client/src/org/compiere/pos/PosPanel.java b/client/src/org/compiere/pos/PosPanel.java index 7baa730103..4e278247ce 100644 --- a/client/src/org/compiere/pos/PosPanel.java +++ b/client/src/org/compiere/pos/PosPanel.java @@ -294,44 +294,16 @@ public class PosPanel extends CPanel */ private MPOS[] getPOSs (int SalesRep_ID) { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_POS WHERE SalesRep_ID=?"; - if (SalesRep_ID == 0) - sql = "SELECT * FROM C_POS WHERE AD_Client_ID=?"; - PreparedStatement pstmt = null; - try - { - pstmt = DB.prepareStatement (sql, null); - if (SalesRep_ID != 0) - pstmt.setInt (1, m_SalesRep_ID); - else - pstmt.setInt (1, Env.getAD_Client_ID(m_ctx)); - ResultSet rs = pstmt.executeQuery (); - while (rs.next ()) - list.add(new MPOS(m_ctx, rs, null)); - rs.close (); - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - log.log(Level.SEVERE, sql, e); - } - try - { - if (pstmt != null) - pstmt.close (); - pstmt = null; - } - catch (Exception e) - { - pstmt = null; - } - MPOS[] retValue = new MPOS[list.size ()]; - list.toArray (retValue); - return retValue; + String pass_field = "SalesRep_ID"; + int pass_ID = 0; + if (SalesRep_ID==0) + { + pass_field = "AD_Client_ID"; + pass_ID = Env.getAD_Client_ID(m_ctx); + } + MPOS[] allPOSes = MPOS.getAll(m_ctx, pass_field, pass_ID); + return allPOSes; } // getPOSs - /** * Set Visible