parent
35911d8163
commit
230073b2d8
|
@ -16,20 +16,66 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.grid.ed;
|
package org.compiere.grid.ed;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import java.awt.Color;
|
||||||
import java.beans.*;
|
import java.awt.Component;
|
||||||
import java.sql.*;
|
import java.awt.Cursor;
|
||||||
import java.util.logging.*;
|
import java.awt.Dimension;
|
||||||
import javax.swing.*;
|
import java.awt.Frame;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.beans.PropertyVetoException;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.apps.*;
|
import javax.swing.Action;
|
||||||
import org.compiere.apps.search.*;
|
import javax.swing.ActionMap;
|
||||||
import org.compiere.model.*;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import org.compiere.swing.*;
|
import javax.swing.InputMap;
|
||||||
import org.compiere.util.*;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.LookAndFeel;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import org.eevolution.model.*;
|
import org.compiere.apps.ADialog;
|
||||||
|
import org.compiere.apps.AEnv;
|
||||||
|
import org.compiere.apps.AWindow;
|
||||||
|
import org.compiere.apps.search.Info;
|
||||||
|
import org.compiere.apps.search.InfoBPartner;
|
||||||
|
import org.compiere.apps.search.InfoFactory;
|
||||||
|
import org.compiere.apps.search.InfoProduct;
|
||||||
|
import org.compiere.model.GridField;
|
||||||
|
import org.compiere.model.Lookup;
|
||||||
|
import org.compiere.model.MColumn;
|
||||||
|
import org.compiere.model.MInvoiceLine;
|
||||||
|
import org.compiere.model.MLookup;
|
||||||
|
import org.compiere.model.MLookupFactory;
|
||||||
|
import org.compiere.model.MOrderLine;
|
||||||
|
import org.compiere.model.MProductPrice;
|
||||||
|
import org.compiere.model.MQuery;
|
||||||
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.swing.CButton;
|
||||||
|
import org.compiere.swing.CMenuItem;
|
||||||
|
import org.compiere.swing.CTextField;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.DisplayType;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Ini;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
import org.compiere.util.NamePair;
|
||||||
|
import org.compiere.util.ValueNamePair;
|
||||||
|
import org.eevolution.model.MPPProductBOMLine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup Visual Field.
|
* Lookup Visual Field.
|
||||||
|
@ -930,26 +976,29 @@ public class VLookup extends JComponent
|
||||||
|
|
||||||
// Exact first
|
// Exact first
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
String finalSQL = Msg.parseTranslation(Env.getCtx(), getDirectAccessSQL(text));
|
String finalSQL = Msg.parseTranslation(Env.getCtx(), getDirectAccessSQL(text));
|
||||||
int id = -3;
|
int id = -3;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(finalSQL, null);
|
pstmt = DB.prepareStatement(finalSQL, null);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
id = rs.getInt(1); // first
|
id = rs.getInt(1); // first
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
id = -1; // only if unique
|
id = -1; // only if unique
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, finalSQL, e);
|
log.log(Level.SEVERE, finalSQL, e);
|
||||||
id = -2;
|
id = -2;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
// Try like
|
// Try like
|
||||||
if (id == -3 && !text.endsWith("%"))
|
if (id == -3 && !text.endsWith("%"))
|
||||||
{
|
{
|
||||||
|
@ -958,29 +1007,24 @@ public class VLookup extends JComponent
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(finalSQL, null);
|
pstmt = DB.prepareStatement(finalSQL, null);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
id = rs.getInt(1); // first
|
id = rs.getInt(1); // first
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
id = -1; // only if unique
|
id = -1; // only if unique
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, finalSQL, e);
|
log.log(Level.SEVERE, finalSQL, e);
|
||||||
id = -2;
|
id = -2;
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
try
|
{
|
||||||
{
|
DB.close(rs, pstmt);
|
||||||
if (pstmt != null)
|
rs = null; pstmt = null;
|
||||||
pstmt.close();
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No (unique) result
|
// No (unique) result
|
||||||
|
@ -1097,34 +1141,27 @@ public class VLookup extends JComponent
|
||||||
+ "WHERE rt.AD_Reference_ID=?";
|
+ "WHERE rt.AD_Reference_ID=?";
|
||||||
String displayColumnName = null;
|
String displayColumnName = null;
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(query, null);
|
pstmt = DB.prepareStatement(query, null);
|
||||||
pstmt.setInt(1, AD_Reference_ID);
|
pstmt.setInt(1, AD_Reference_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
m_keyColumnName = rs.getString(1);
|
m_keyColumnName = rs.getString(1);
|
||||||
displayColumnName = rs.getString(2);
|
displayColumnName = rs.getString(2);
|
||||||
m_tableName = rs.getString(3);
|
m_tableName = rs.getString(3);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, query, e);
|
log.log(Level.SEVERE, query, e);
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
if (displayColumnName != null)
|
if (displayColumnName != null)
|
||||||
{
|
{
|
||||||
|
@ -1155,11 +1192,12 @@ public class VLookup extends JComponent
|
||||||
+ " AND cc.IsKey='Y' AND cc.ColumnName=?)";
|
+ " AND cc.IsKey='Y' AND cc.ColumnName=?)";
|
||||||
sql = new StringBuffer();
|
sql = new StringBuffer();
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(query, null);
|
pstmt = DB.prepareStatement(query, null);
|
||||||
pstmt.setString(1, m_keyColumnName);
|
pstmt.setString(1, m_keyColumnName);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
if (sql.length() != 0)
|
if (sql.length() != 0)
|
||||||
|
@ -1167,23 +1205,16 @@ public class VLookup extends JComponent
|
||||||
m_tableName = rs.getString(1);
|
m_tableName = rs.getString(1);
|
||||||
sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
|
sql.append("UPPER(").append(rs.getString(2)).append(") LIKE ").append(DB.TO_STRING(text));
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, query, ex);
|
log.log(Level.SEVERE, query, ex);
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
catch (SQLException ex1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
pstmt = null;
|
|
||||||
//
|
//
|
||||||
if (sql.length() == 0)
|
if (sql.length() == 0)
|
||||||
{
|
{
|
||||||
|
@ -1265,32 +1296,25 @@ public class VLookup extends JComponent
|
||||||
+ "WHERE rt.AD_Reference_ID=?";
|
+ "WHERE rt.AD_Reference_ID=?";
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(query, null);
|
pstmt = DB.prepareStatement(query, null);
|
||||||
pstmt.setInt(1, AD_Reference_ID);
|
pstmt.setInt(1, AD_Reference_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
keyColumnName = rs.getString(1);
|
keyColumnName = rs.getString(1);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, query, e);
|
log.log(Level.SEVERE, query, e);
|
||||||
}
|
}
|
||||||
try
|
finally
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
DB.close(rs, pstmt);
|
||||||
pstmt.close();
|
rs = null; pstmt = null;
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
} // Table Reference
|
} // Table Reference
|
||||||
} // MLookup
|
} // MLookup
|
||||||
|
|
Loading…
Reference in New Issue