📄 infobpartner.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.search;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.math.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.minigrid.*;
import org.compiere.util.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.model.*;
/**
* Search Business Partner and return selection
*
* @author Jorg Janke
* @version $Id: InfoBPartner.java,v 1.14 2003/04/24 06:11:10 jjanke Exp $
*/
public final class InfoBPartner extends Info
{
/**
* Standard Constructor
* @param frame frame
* @param modal modal
* @param WindowNo WindowNo
* @param value Query value Name or Value if contains numbers
* @param isSOTrx if false, query vendors only
* @param multiSelection multiple selection
* @param whereClause where clause
*/
public InfoBPartner(Frame frame, boolean modal, int WindowNo,
String value, boolean isSOTrx,
boolean multiSelection, String whereClause)
{
super(frame, modal, WindowNo, "bp", "C_BPartner_ID", multiSelection, whereClause);
Log.trace(Log.l1_User, "InfoBPartner", value);
setTitle(Msg.getMsg(Env.getCtx(), "InfoBPartner"));
m_isSOTrx = isSOTrx;
//
statInit();
initInfo (value, whereClause);
//
int no = m_table.getRowCount();
setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
setStatusDB(Integer.toString(no));
// AutoQuery
if (value != null && value.length() > 0)
executeQuery();
m_loadedOK = true;
// Focus
fieldValue.requestFocus();
AEnv.positionCenterWindow(frame, this);
} // InfoBPartner
/** SalesOrder Trx */
private boolean m_isSOTrx = false;
private int m_C_BPartner_Contact_ID_index = -1;
private int m_C_BPartner_Location_ID_index = -1;
/** From Clause */
private static String s_partnerFROM = "C_BPartner bp"
+ " LEFT OUTER JOIN C_BPartner_Contact c ON (bp.C_BPartner_ID=c.C_BPartner_ID AND c.IsActive='Y')"
+ " LEFT OUTER JOIN C_BPartner_Location l ON (bp.C_BPartner_ID=l.C_BPartner_ID AND l.IsActive='Y')"
+ " LEFT OUTER JOIN C_Location a ON (l.C_Location_ID=a.C_Location_ID)";
/** Array of Column Info */
private static Info_Column[] s_partnerLayout = {
new Info_Column(" ", "bp.C_BPartner_ID", IDColumn.class),
new Info_Column(Msg.translate(Env.getCtx(), "Value"), "bp.Value", String.class),
new Info_Column(Msg.translate(Env.getCtx(), "Name"), "bp.Name", String.class),
new Info_Column(Msg.translate(Env.getCtx(), "SO_CreditAvailable"), "bp.SO_CreditLimit-bp.SO_CreditUsed AS SO_CreditAvailable", BigDecimal.class, true, true, null),
new Info_Column(Msg.translate(Env.getCtx(), "SO_CreditUsed"), "bp.SO_CreditUsed", BigDecimal.class),
new Info_Column(Msg.translate(Env.getCtx(), "Contact"), "c.Name AS Contact", KeyNamePair.class, "c.C_BPartner_Contact_ID"),
new Info_Column(Msg.translate(Env.getCtx(), "Phone"), "c.Phone", String.class),
new Info_Column(Msg.translate(Env.getCtx(), "Postal"), "a.Postal", KeyNamePair.class, "l.C_BPartner_Location_ID"),
new Info_Column(Msg.translate(Env.getCtx(), "City"), "a.City", String.class),
new Info_Column(Msg.translate(Env.getCtx(), "Revenue"), "bp.ActualLifetimeValue", BigDecimal.class)
};
//
private CLabel labelValue = new CLabel();
private CTextField fieldValue = new CTextField(10);
private CLabel labelName = new CLabel();
private CTextField fieldName = new CTextField(10);
private CLabel labelContact = new CLabel();
private CTextField fieldContact = new CTextField(10);
private CLabel labelPostal = new CLabel();
private CTextField fieldPostal = new CTextField(10);
private CLabel labelPhone = new CLabel();
private CTextField fieldPhone = new CTextField(10);
private VCheckBox checkAND = new VCheckBox();
private VCheckBox checkCustomer = new VCheckBox();
/**
* Static Setup - add fields to parameterPanel
*/
private void statInit()
{
labelValue.setText(Msg.getMsg(Env.getCtx(), "Value"));
labelValue.setHorizontalAlignment(JLabel.LEADING);
fieldValue.setBackground(CompierePLAF.getInfoBackground());
fieldValue.addActionListener(this);
labelName.setText(Msg.getMsg(Env.getCtx(), "Name"));
labelName.setHorizontalAlignment(JLabel.LEADING);
fieldName.setBackground(CompierePLAF.getInfoBackground());
fieldName.addActionListener(this);
labelContact.setText(Msg.getMsg(Env.getCtx(), "Contact"));
labelContact.setHorizontalAlignment(JLabel.LEADING);
fieldContact.setBackground(CompierePLAF.getInfoBackground());
fieldContact.addActionListener(this);
labelPostal.setText(Msg.getMsg(Env.getCtx(), "Postal"));
labelPostal.setHorizontalAlignment(JLabel.LEADING);
fieldPostal.setBackground(CompierePLAF.getInfoBackground());
fieldPostal.addActionListener(this);
labelPhone.setText(Msg.translate(Env.getCtx(), "Phone"));
labelPhone.setHorizontalAlignment(JLabel.LEADING);
fieldPhone.setBackground(CompierePLAF.getInfoBackground());
fieldPhone.addActionListener(this);
checkAND.setText(Msg.getMsg(Env.getCtx(), "SearchAND"));
checkAND.setToolTipText(Msg.getMsg(Env.getCtx(), "SearchANDInfo"));
checkAND.setSelected(true);
checkAND.addActionListener(this);
if (m_isSOTrx)
checkCustomer.setText(Msg.getMsg(Env.getCtx(), "OnlyCustomers"));
else
checkCustomer.setText(Msg.getMsg(Env.getCtx(), "OnlyVendors"));
checkCustomer.setSelected(true);
checkCustomer.setFocusable(false);
checkCustomer.setRequestFocusEnabled(false);
checkCustomer.addActionListener(this);
//
parameterPanel.setLayout(new ALayout());
parameterPanel.add(labelValue, new ALayoutConstraint(0,0));
parameterPanel.add(labelName, null);
parameterPanel.add(labelContact, null);
parameterPanel.add(labelPostal, null);
parameterPanel.add(labelPhone, null);
parameterPanel.add(checkCustomer, null);
//
parameterPanel.add(fieldValue, new ALayoutConstraint(1,0));
parameterPanel.add(fieldName, null);
parameterPanel.add(fieldContact, null);
parameterPanel.add(fieldPostal, null);
parameterPanel.add(fieldPhone, null);
parameterPanel.add(checkAND, null);
} // statInit
/**
* Dynamic Init
* @param value value
* @param whereClause where clause
*/
private void initInfo(String value, String whereClause)
{
/** From
C_BPartner bp
LEFT OUTER JOIN C_BPartner_Contact c ON (bp.C_BPartner_ID=c.C_BPartner_ID AND c.IsActive='Y')
LEFT OUTER JOIN C_BPartner_Location l ON (bp.C_BPartner_ID=l.C_BPartner_ID AND l.IsActive='Y')
LEFT OUTER JOIN C_Location a ON (l.C_Location_ID=a.C_Location_ID)
**/
// Create Grid
StringBuffer where = new StringBuffer();
where.append("bp.IsSummary='N' AND bp.IsActive='Y'");
if (whereClause != null && whereClause.length() > 0)
where.append(" AND ").append(whereClause);
//
prepareTable(s_partnerLayout, s_partnerFROM,
where.toString(),
"bp.Value");
// Get indexes
for (int i = 0; i < m_layout.length; i++)
{
if (m_layout[i].getIDcolSQL().indexOf("C_BPartner_Contact_ID") != -1)
m_C_BPartner_Contact_ID_index = i;
if (m_layout[i].getIDcolSQL().indexOf("C_BPartner_Location_ID") != -1)
m_C_BPartner_Location_ID_index = i;
}
// Set Value
if (value == null)
value = "%";
if (!value.endsWith("%"))
value += "%";
// Put query string in Name if not numeric
if (value.equals("%"))
fieldName.setText(value);
// No Numbers entered
else if ((value.indexOf("0")+value.indexOf("1")+value.indexOf("2")+value.indexOf("3")+value.indexOf("4") +value.indexOf("5")
+value.indexOf("6")+value.indexOf("7")+value.indexOf("8")+value.indexOf("9")) == -10)
{
if (value.startsWith("%"))
fieldName.setText(value);
else
fieldName.setText("%" + value);
}
// Number entered
else
fieldValue.setText(value);
} // initInfo
/*************************************************************************/
/**
* Construct SQL Where Clause and define parameters.
* (setParameters needs to set parameters)
* Includes first AND
* @return WHERE clause
*/
String getSQLWhere()
{
ArrayList list = new ArrayList();
// => Value
String value = fieldValue.getText().toUpperCase();
if (!(value.equals("") || value.equals("%")))
list.add ("UPPER(bp.Value) LIKE ?");
// => Name
String name = fieldName.getText().toUpperCase();
if (!(name.equals("") || name.equals("%")))
list.add ("UPPER(bp.Name) LIKE ?");
// => Contact
String contact = fieldContact.getText().toUpperCase();
if (!(contact.equals("") || contact.equals("%")))
list.add ("UPPER(c.Name) LIKE ?");
// => Phone
String phone = fieldPhone.getText().toUpperCase();
if (!(phone.equals("") || phone.equals("%")))
list.add ("UPPER(c.Phone) LIKE ?");
// => Postal
String postal = fieldPostal.getText().toUpperCase();
if (!(postal.equals("") || postal.equals("%")))
list.add ("UPPER(a.Postal) LIKE ?");
StringBuffer sql = new StringBuffer();
int size = list.size();
// Just one
if (size == 1)
sql.append(" AND ").append(list.get(0));
else if (size > 1)
{
boolean AND = checkAND.isSelected();
sql.append(" AND ");
if (!AND)
sql.append("(");
for (int i = 0; i < size; i++)
{
if (i > 0)
sql.append(AND ? " AND " : " OR ");
sql.append(list.get(i));
}
if (!AND)
sql.append(")");
}
// Static SQL
if (checkCustomer.isSelected())
{
sql.append(" AND ");
if (m_isSOTrx)
sql.append ("IsCustomer='Y'");
else
sql.append ("IsVendor='Y'");
}
return sql.toString();
} // getSQLWhere
/**
* Set Parameters for Query.
* (as defined in getSQLWhere)
* @param pstmt pstmt
* @throws SQLException
*/
void setParameters(PreparedStatement pstmt) throws SQLException
{
int index = 1;
// => Value
String value = fieldValue.getText().toUpperCase();
if (!(value.equals("") || value.equals("%")))
{
if (!value.endsWith("%"))
value += "%";
pstmt.setString(index++, value);
Log.trace(Log.l5_DData, "InfoBPartner.setParameters", "Value: " + value);
}
// => Name
String name = fieldName.getText().toUpperCase();
if (!(name.equals("") || name.equals("%")))
{
if (!name.endsWith("%"))
name += "%";
pstmt.setString(index++, name);
Log.trace(Log.l5_DData, "InfoBPartner.setParameters", "Name: " + name);
}
// => Contact
String contact = fieldContact.getText().toUpperCase();
if (!(contact.equals("") || contact.equals("%")))
{
if (!contact.endsWith("%"))
contact += "%";
pstmt.setString(index++, contact);
Log.trace(Log.l5_DData, "InfoBPartner.setParameters", "Contact: " + contact);
}
// => Phone
String phone = fieldPhone.getText().toUpperCase();
if (!(phone.equals("") || phone.equals("%")))
{
if (!phone.endsWith("%"))
phone += "%";
pstmt.setString(index++, phone);
Log.trace(Log.l5_DData, "InfoBPartner.setParameters", "Phone: " + phone);
}
// => Postal
String postal = fieldPostal.getText().toUpperCase();
if (!(postal.equals("") || postal.equals("%")))
{
if (!postal.endsWith("%"))
postal += "%";
pstmt.setString(index++, postal);
Log.trace(Log.l5_DData, "InfoBPartner.setParameters", "Postal: " + postal);
}
} // setParameters
/*************************************************************************/
/**
* Save Selection Details
* Get Location/Partner Info
*/
public void saveSelectionDetail()
{
int row = m_table.getSelectedRow();
if (row == -1)
return;
int C_BPartner_Contact_ID = 0;
int C_BPartner_Location_ID = 0;
if (m_C_BPartner_Contact_ID_index != -1)
{
Object data = m_table.getModel().getValueAt(row, m_C_BPartner_Contact_ID_index);
if (data instanceof KeyNamePair)
C_BPartner_Contact_ID = ((KeyNamePair)data).getKey();
}
if (m_C_BPartner_Location_ID_index != -1)
{
Object data = m_table.getModel().getValueAt(row, m_C_BPartner_Location_ID_index);
if (data instanceof KeyNamePair)
C_BPartner_Location_ID = ((KeyNamePair)data).getKey();
}
// publish for Callout to read
Integer ID = getSelectedRowKey();
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_BPartner_ID", ID == null ? "0" : ID.toString());
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_BPartner_Contact_ID", String.valueOf(C_BPartner_Contact_ID));
Env.setContext(Env.getCtx(), m_WindowNo, Env.TAB_INFO, "C_BPartner_Location_ID", String.valueOf(C_BPartner_Location_ID));
} // saveSelectionDetail
/*************************************************************************/
/**
* Show History
*/
void showHistory()
{
Log.trace(Log.l1_User, "InfoBPartner.showHistory");
Integer C_BPartner_ID = getSelectedRowKey();
if (C_BPartner_ID == null)
return;
InvoiceHistory ih = new InvoiceHistory (this, C_BPartner_ID.intValue(), 0);
ih.setVisible(true);
ih = null;
} // showHistory
/**
* Has History
* @return true
*/
boolean hasHistory()
{
return true;
} // hasHistory
/**
* Zoom
*/
void zoom()
{
Log.trace(Log.l1_User, "InfoBPartner.zoom");
Integer C_BPartner_ID = getSelectedRowKey();
if (C_BPartner_ID == null)
return;
MQuery query = new MQuery("C_BPartner");
query.addRestriction("C_BPartner_ID", MQuery.EQUAL, C_BPartner_ID);
zoom (123, query);
} // zoom
/**
* Has Zoom
* @return true
*/
boolean hasZoom()
{
return true;
} // hasZoom
/**
* Customize
*/
void customize()
{
Log.trace(Log.l1_User, "InfoBPartner.customize");
} // customize
/**
* Has Customize
* @return false
*/
boolean hasCustomize()
{
return false; // for now
} // hasCustomize
} // InfoBPartner
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -