1 14 package org.compiere.model; 15 16 import java.sql.*; 17 import java.util.*; 18 import java.math.*; 19 import java.io.Serializable ; 20 21 import org.compiere.util.NamePair; 22 import org.compiere.util.KeyNamePair; 23 import org.compiere.util.Env; 24 import org.compiere.util.DB; 25 26 32 public final class MAccount extends Lookup implements Serializable 33 { 34 39 public MAccount (Properties ctx, int WindowNo) 40 { 41 m_ctx = ctx; 42 m_WindowNo = WindowNo; 43 } 45 private int m_WindowNo; 46 private Properties m_ctx; 47 48 public int C_ValidCombination_ID; 49 private String Combination; 50 private String Description; 51 52 57 public String getDisplay (Object value) 58 { 59 if (!containsKey (value)) 60 return "<" + value.toString() + ">"; 61 return toString(); 62 } 64 69 public NamePair get (Object value) 70 { 71 if (value == null) 72 return null; 73 if (!containsKey (value)) 74 return null; 75 return new KeyNamePair (C_ValidCombination_ID, toString()); 76 } 78 83 public boolean containsKey (Object key) 84 { 85 int intValue = 0; 86 if (key instanceof Integer ) 87 intValue = ((Integer )key).intValue(); 88 else if (key != null) 89 intValue = Integer.parseInt(key.toString()); 90 return load (intValue); 92 } 94 98 public String getDescription() 99 { 100 return Description; 101 } 103 107 public String toString() 108 { 109 if (C_ValidCombination_ID == 0) 110 return ""; 111 return Combination; 112 } 114 119 public boolean load (int ID) 120 { 121 if (ID == 0) { 123 C_ValidCombination_ID = 0; 124 Combination = ""; 125 Description = ""; 126 return true; 127 } 128 if (ID == C_ValidCombination_ID) return true; 130 131 String SQL = "SELECT C_ValidCombination_ID, Combination, Description " 132 + "FROM C_ValidCombination WHERE C_ValidCombination_ID=?"; 133 try 134 { 135 PreparedStatement pstmt = DB.prepareStatement(SQL); 137 pstmt.setInt(1, ID); 138 ResultSet rs = pstmt.executeQuery(); 139 if (!rs.next()) 140 { 141 rs.close(); 142 pstmt.close(); 143 return false; 144 } 145 C_ValidCombination_ID = rs.getInt(1); 147 Combination = rs.getString(2); 148 Description = rs.getString(3); 149 rs.close(); 151 pstmt.close(); 152 153 } 154 catch (SQLException e) 155 { 156 return false; 157 } 158 return true; 159 } 161 165 public String getColumnName() 166 { 167 return ""; 168 } 170 179 public ArrayList getData (boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary) 180 { 181 ArrayList list = new ArrayList(); 182 if (!mandatory) 183 list.add(new KeyNamePair (-1, "")); 184 StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Combination, Description " 186 + "FROM C_ValidCombination WHERE AD_Client_ID=?"); 187 if (onlyActive) 188 sql.append(" AND IsActive='Y'"); 189 sql.append(" ORDER BY 2"); 190 try 191 { 192 PreparedStatement pstmt = DB.prepareStatement(sql.toString()); 193 pstmt.setInt(1, Env.getContextAsInt(m_ctx, "#AD_Client_ID")); 194 ResultSet rs = pstmt.executeQuery(); 195 while (rs.next()) 196 list.add (new KeyNamePair(rs.getInt(1), rs.getString(2) + " - " + rs.getString(3))); 197 rs.close(); 198 pstmt.close(); 199 } 200 catch (SQLException e) 201 { 202 log.error("getData", e); 203 } 204 205 return list; 207 } 209 } | Popular Tags |