Info, InfoProduct:
* fix db connection * organized imports
This commit is contained in:
parent
cb8d903768
commit
5126b0bf02
|
@ -16,20 +16,48 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.apps.search;
|
package org.compiere.apps.search;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import java.awt.Cursor;
|
||||||
import java.math.*;
|
import java.awt.Dimension;
|
||||||
import java.sql.*;
|
import java.awt.Frame;
|
||||||
import java.util.*;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.logging.*;
|
import java.awt.event.MouseEvent;
|
||||||
import javax.swing.*;
|
import java.math.BigDecimal;
|
||||||
import javax.swing.event.*;
|
import java.sql.PreparedStatement;
|
||||||
import org.compiere.apps.*;
|
import java.sql.ResultSet;
|
||||||
import org.compiere.grid.ed.*;
|
import java.sql.SQLException;
|
||||||
import org.compiere.minigrid.*;
|
import java.sql.Timestamp;
|
||||||
import org.compiere.model.*;
|
import java.util.ArrayList;
|
||||||
import org.compiere.swing.*;
|
import java.util.logging.Level;
|
||||||
import org.compiere.util.*;
|
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
|
|
||||||
|
import org.compiere.apps.ADialog;
|
||||||
|
import org.compiere.apps.AEnv;
|
||||||
|
import org.compiere.apps.AWindow;
|
||||||
|
import org.compiere.apps.ConfirmPanel;
|
||||||
|
import org.compiere.apps.PrintScreenPainter;
|
||||||
|
import org.compiere.apps.StatusBar;
|
||||||
|
import org.compiere.grid.ed.Calculator;
|
||||||
|
import org.compiere.minigrid.IDColumn;
|
||||||
|
import org.compiere.minigrid.MiniTable;
|
||||||
|
import org.compiere.model.MQuery;
|
||||||
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.swing.CDialog;
|
||||||
|
import org.compiere.swing.CMenuItem;
|
||||||
|
import org.compiere.swing.CPanel;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.KeyNamePair;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search Information and return selection - Base Class.
|
* Search Information and return selection - Base Class.
|
||||||
|
@ -483,22 +511,26 @@ public abstract class Info extends CDialog
|
||||||
countSql = MRole.getDefault().addAccessSQL(countSql, getTableName(),
|
countSql = MRole.getDefault().addAccessSQL(countSql, getTableName(),
|
||||||
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
|
MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
|
||||||
log.finer(countSql);
|
log.finer(countSql);
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
int no = -1;
|
int no = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(countSql, null);
|
pstmt = DB.prepareStatement(countSql, null);
|
||||||
setParameters (pstmt, true);
|
setParameters (pstmt, true);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
no = rs.getInt(1);
|
no = rs.getInt(1);
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, countSql, e);
|
log.log(Level.SEVERE, countSql, e);
|
||||||
no = -2;
|
no = -2;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
log.fine("#" + no + " - " + (System.currentTimeMillis()-start) + "ms");
|
log.fine("#" + no + " - " + (System.currentTimeMillis()-start) + "ms");
|
||||||
//Armen: add role checking (Patch #1694788 )
|
//Armen: add role checking (Patch #1694788 )
|
||||||
MRole role = MRole.getDefault();
|
MRole role = MRole.getDefault();
|
||||||
|
@ -940,33 +972,25 @@ public abstract class Info extends CDialog
|
||||||
//
|
//
|
||||||
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
|
String sql = "SELECT AD_Window_ID, PO_Window_ID FROM AD_Table WHERE TableName=?";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setString(1, tableName);
|
pstmt.setString(1, tableName);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
m_SO_Window_ID = rs.getInt(1);
|
m_SO_Window_ID = rs.getInt(1);
|
||||||
m_PO_Window_ID = rs.getInt(2);
|
m_PO_Window_ID = rs.getInt(2);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql, e);
|
log.log(Level.SEVERE, sql, e);
|
||||||
}
|
}
|
||||||
try
|
finally {
|
||||||
{
|
DB.close(rs, pstmt);
|
||||||
if (pstmt != null)
|
rs = null; pstmt = null;
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (!isSOTrx && m_PO_Window_ID > 0)
|
if (!isSOTrx && m_PO_Window_ID > 0)
|
||||||
|
@ -1051,7 +1075,7 @@ public abstract class Info extends CDialog
|
||||||
for (int col = 0; col < p_layout.length; col++)
|
for (int col = 0; col < p_layout.length; col++)
|
||||||
{
|
{
|
||||||
Object data = null;
|
Object data = null;
|
||||||
Class c = p_layout[col].getColClass();
|
Class<?> c = p_layout[col].getColClass();
|
||||||
int colIndex = col + colOffset;
|
int colIndex = col + colOffset;
|
||||||
if (c == IDColumn.class)
|
if (c == IDColumn.class)
|
||||||
data = new IDColumn(m_rs.getInt(colIndex));
|
data = new IDColumn(m_rs.getInt(colIndex));
|
||||||
|
@ -1109,15 +1133,7 @@ public abstract class Info extends CDialog
|
||||||
* Close ResultSet and Statement
|
* Close ResultSet and Statement
|
||||||
*/
|
*/
|
||||||
private void close() {
|
private void close() {
|
||||||
try {
|
DB.close(m_rs, m_pstmt);
|
||||||
if (m_rs != null)
|
|
||||||
m_rs.close();
|
|
||||||
if (m_pstmt != null)
|
|
||||||
m_pstmt.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e) {
|
|
||||||
log.log(Level.SEVERE, "closeRS", e);
|
|
||||||
}
|
|
||||||
m_rs = null;
|
m_rs = null;
|
||||||
m_pstmt = null;
|
m_pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,24 +16,49 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.apps.search;
|
package org.compiere.apps.search;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.*;
|
import java.awt.Frame;
|
||||||
import java.math.*;
|
import java.awt.Insets;
|
||||||
import java.sql.*;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.*;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.logging.*;
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.plaf.ColorUIResource;
|
import javax.swing.plaf.ColorUIResource;
|
||||||
//
|
|
||||||
import org.adempiere.plaf.AdempierePLAF;
|
import org.adempiere.plaf.AdempierePLAF;
|
||||||
import org.adempiere.plaf.AdempiereTaskPaneUI;
|
import org.adempiere.plaf.AdempiereTaskPaneUI;
|
||||||
import org.compiere.apps.*;
|
import org.compiere.apps.AEnv;
|
||||||
import org.compiere.grid.ed.*;
|
import org.compiere.apps.ALayout;
|
||||||
import org.compiere.minigrid.*;
|
import org.compiere.apps.ALayoutConstraint;
|
||||||
import org.compiere.model.*;
|
import org.compiere.apps.ConfirmPanel;
|
||||||
import org.compiere.swing.*;
|
import org.compiere.grid.ed.VComboBox;
|
||||||
import org.compiere.util.*;
|
import org.compiere.minigrid.ColumnInfo;
|
||||||
|
import org.compiere.minigrid.IDColumn;
|
||||||
|
import org.compiere.minigrid.MiniTable;
|
||||||
|
import org.compiere.model.MQuery;
|
||||||
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.swing.CButton;
|
||||||
|
import org.compiere.swing.CLabel;
|
||||||
|
import org.compiere.swing.CPanel;
|
||||||
|
import org.compiere.swing.CTabbedPane;
|
||||||
|
import org.compiere.swing.CTextArea;
|
||||||
|
import org.compiere.swing.CTextField;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.KeyNamePair;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
import org.compiere.util.Util;
|
||||||
import org.jdesktop.swingx.JXTaskPane;
|
import org.jdesktop.swingx.JXTaskPane;
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,18 +346,18 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
sql = sql.replace(" FROM", ", DocumentNote FROM");
|
sql = sql.replace(" FROM", ", DocumentNote FROM");
|
||||||
log.finest(sql);
|
log.finest(sql);
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setString(1, (String)obj);
|
pstmt.setString(1, (String)obj);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
fieldDescription.setText("");
|
fieldDescription.setText("");
|
||||||
warehouseTbl.loadTable(rs);
|
warehouseTbl.loadTable(rs);
|
||||||
rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
if(rs.getString("DocumentNote") != null)
|
if(rs.getString("DocumentNote") != null)
|
||||||
fieldDescription.setText(rs.getString("DocumentNote"));
|
fieldDescription.setText(rs.getString("DocumentNote"));
|
||||||
rs.close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -340,15 +365,15 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null) DB.close(pstmt);
|
DB.close(rs, pstmt);
|
||||||
pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sql = "SELECT M_Product_ID FROM M_Product WHERE Value = ?";
|
sql = "SELECT M_Product_ID FROM M_Product WHERE Value = ?";
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setString(1, (String)obj);
|
pstmt.setString(1, (String)obj);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if(rs.next())
|
if(rs.next())
|
||||||
M_Product_ID = rs.getInt(1);
|
M_Product_ID = rs.getInt(1);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -356,8 +381,8 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null) DB.close(pstmt);
|
DB.close(rs, pstmt);
|
||||||
pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = m_sqlSubstitute;
|
sql = m_sqlSubstitute;
|
||||||
|
@ -366,7 +391,7 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, M_Product_ID);
|
pstmt.setInt(1, M_Product_ID);
|
||||||
pstmt.setInt(2, M_PriceList_Version_ID);
|
pstmt.setInt(2, M_PriceList_Version_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
substituteTbl.loadTable(rs);
|
substituteTbl.loadTable(rs);
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -374,8 +399,8 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null) DB.close(pstmt);
|
DB.close(rs, pstmt);
|
||||||
pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = m_sqlRelated;
|
sql = m_sqlRelated;
|
||||||
|
@ -384,7 +409,7 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, M_Product_ID);
|
pstmt.setInt(1, M_Product_ID);
|
||||||
pstmt.setInt(2, M_PriceList_Version_ID);
|
pstmt.setInt(2, M_PriceList_Version_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
relatedTbl.loadTable(rs);
|
relatedTbl.loadTable(rs);
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -392,8 +417,8 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null) DB.close(pstmt);
|
DB.close(rs, pstmt);
|
||||||
pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
} // refresh
|
} // refresh
|
||||||
//End - fer_luck @ centuryon
|
//End - fer_luck @ centuryon
|
||||||
|
@ -465,18 +490,19 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
// Add Access & Order
|
// Add Access & Order
|
||||||
SQL = MRole.getDefault().addAccessSQL (SQL, "M_PriceList_Version", true, false) // fully qualidfied - RO
|
SQL = MRole.getDefault().addAccessSQL (SQL, "M_PriceList_Version", true, false) // fully qualidfied - RO
|
||||||
+ " ORDER BY M_PriceList_Version.Name";
|
+ " ORDER BY M_PriceList_Version.Name";
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pickPriceList.addItem(new KeyNamePair (0, ""));
|
pickPriceList.addItem(new KeyNamePair (0, ""));
|
||||||
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
|
pstmt = DB.prepareStatement(SQL, null);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2));
|
KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2));
|
||||||
pickPriceList.addItem(kn);
|
pickPriceList.addItem(kn);
|
||||||
}
|
}
|
||||||
rs.close();
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
|
||||||
|
|
||||||
// Warehouse
|
// Warehouse
|
||||||
SQL = MRole.getDefault().addAccessSQL (
|
SQL = MRole.getDefault().addAccessSQL (
|
||||||
|
@ -494,14 +520,17 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
|
(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
|
||||||
pickWarehouse.addItem(kn);
|
pickWarehouse.addItem(kn);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, SQL, e);
|
log.log(Level.SEVERE, SQL, e);
|
||||||
setStatusLine(e.getLocalizedMessage(), true);
|
setStatusLine(e.getLocalizedMessage(), true);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
} // fillPicks
|
} // fillPicks
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -574,24 +603,28 @@ public final class InfoProduct extends Info implements ActionListener
|
||||||
+ " AND pl.M_PriceList_ID=? " // 1
|
+ " AND pl.M_PriceList_ID=? " // 1
|
||||||
+ "ORDER BY plv.ValidFrom DESC";
|
+ "ORDER BY plv.ValidFrom DESC";
|
||||||
// find newest one
|
// find newest one
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, M_PriceList_ID);
|
pstmt.setInt(1, M_PriceList_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
while (rs.next() && retValue == 0)
|
while (rs.next() && retValue == 0)
|
||||||
{
|
{
|
||||||
Timestamp plDate = rs.getTimestamp(2);
|
Timestamp plDate = rs.getTimestamp(2);
|
||||||
if (!priceDate.before(plDate))
|
if (!priceDate.before(plDate))
|
||||||
retValue = rs.getInt(1);
|
retValue = rs.getInt(1);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql, e);
|
log.log(Level.SEVERE, sql, e);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
Env.setContext(Env.getCtx(), p_WindowNo, "M_PriceList_Version_ID", retValue);
|
Env.setContext(Env.getCtx(), p_WindowNo, "M_PriceList_Version_ID", retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
} // findPLV
|
} // findPLV
|
||||||
|
|
Loading…
Reference in New Issue