📄 vbpartner.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.grid.ed;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import org.compiere.apps.*;
import org.compiere.util.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
/**
* Business Partner Editor
*
* @author Jorg Janke
* @version $Id: VBPartner.java,v 1.10 2003/04/28 04:19:10 jjanke Exp $
*/
public final class VBPartner extends JDialog implements ActionListener
{
/**
* Constructor.
* Requires LoadBPartner
* @param frame parent
* @param WindowNo Window No
*/
public VBPartner(Frame frame, int WindowNo)
{
super(frame, Msg.translate(Env.getCtx(), "C_BPartner_ID"), true);
Log.trace(Log.l1_User, "VBPartner");
m_WindowNo = WindowNo;
try
{
jbInit();
}
catch(Exception ex)
{
Log.error("VBPartner - " + ex.getMessage());
}
initBPartner();
//
AEnv.positionCenterWindow(frame, this);
} // VBPartner
private int m_WindowNo;
private int m_C_BPartner_ID = 0;
private Integer m_C_BPartner_Contact_ID = null;
private Integer m_C_BPartner_Location_ID = null;
private Insets m_labelInsets = new Insets(2,15,2,0); // top,left,bottom,right
private Insets m_fieldInsets = new Insets(2,5,2,10); // top,left,bottom,right
private GridBagConstraints m_gbc = new GridBagConstraints();
private int m_line;
private Object[] m_greeting;
//
private VString fValue, fName, fName2, fContact, fTitle, fPhone, fFax, fPhone2, fEMail;
private VLocation fAddress;
private String OldValue="", OldName="", OldName2="", OldContact="", OldTitle="",
OldPhone="", OldFax="", OldPhone2="", OldEMail="";
private JComboBox fGreetingBP, fGreetingC;
private int OldGreetingBP = -1, OldGreetingC = -1;
//
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel centerPanel = new CPanel();
private CPanel southPanel = new CPanel();
private GridBagLayout centerLayout = new GridBagLayout();
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
private BorderLayout southLayout = new BorderLayout();
/**
* Static Init
* @throws Exception
*/
void jbInit() throws Exception
{
mainPanel.setLayout(mainLayout);
southPanel.setLayout(southLayout);
centerPanel.setLayout(centerLayout);
mainLayout.setVgap(5);
getContentPane().add(mainPanel);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
southPanel.add(confirmPanel, BorderLayout.CENTER);
//
confirmPanel.addActionListener(this);
} // jbInit
/**
* Dynamic Init
*/
private void initBPartner()
{
// Get Data
m_greeting = fillGreeting();
// Display
m_gbc.anchor = GridBagConstraints.NORTHWEST;
m_gbc.gridx = 0;
m_gbc.gridy = 0;
m_gbc.gridwidth = 1;
m_gbc.weightx = 0;
m_gbc.weighty = 0;
m_gbc.fill = GridBagConstraints.NONE;
m_gbc.ipadx = 0;
m_gbc.ipady = 0;
m_line = 0;
// Value
fValue = new VString("Value", true, false, true, 30, 60, "");
createLine (fValue, "Value", true, false);
// Greeting Business Partner
fGreetingBP = new JComboBox (m_greeting);
createLine (fGreetingBP, "Greeting");
// Name
fName = new VString("Name", true, false, true, 30, 60, "");
createLine (fName, "Name");
//
fName2 = new VString("Name2", false, false, true, 30, 60, "");
createLine (fName2, "Name2");
// Greeting Contact
fGreetingC = new JComboBox (m_greeting);
createLine (fGreetingC, "Greeting", true, false);
// Contact
fContact = new VString("Contact", false, false, true, 30, 60, "");
createLine (fContact, "Contact");
//
fTitle = new VString("Title", false, false, true, 30, 60, "");
createLine(fTitle, "Title");
// Location
fAddress = new VLocation ("C_Location_ID", false, false, true, new MLocation (Env.getCtx(), m_WindowNo));
fAddress.setValue (null);
createLine (fAddress, "C_Location_ID", true, true);
// Phone
fPhone = new VString("Phone", false, false, true, 30, 40, "");
createLine (fPhone, "Phone", true, false);
//
fPhone2 = new VString("Phone2", false, false, true, 30, 40, "");
createLine (fPhone2, "Phone2");
//
fFax = new VString("Fax", false, false, true, 30, 40, "");
createLine (fFax, "Fax");
//
fEMail = new VString("EMail", false, false, true, 30, 40, "");
createLine (fEMail, "EMail");
} // initBPartner
/**
* Create Line
* @param field field
* @param title label value
*/
private void createLine (JComponent field, String title)
{
createLine (field, title, false, false);
}
/**
* Create Line
* @param field field
* @param title label value
* @param addSpace add more space
* @param fill fill horizontal
*/
private void createLine (JComponent field, String title, boolean addSpace, boolean fill)
{
if (addSpace)
{
m_gbc.gridy = m_line++;
m_gbc.gridx = 1;
m_gbc.insets = m_fieldInsets;
centerPanel.add (Box.createHorizontalStrut(6), m_gbc);
}
// Line
m_gbc.gridy = m_line++;
// Label
m_gbc.gridx = 0;
m_gbc.insets = m_labelInsets;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
VLabel label = new VLabel(Msg.translate(Env.getCtx(), title));
centerPanel.add(label, m_gbc);
// Field
m_gbc.gridx = 1;
m_gbc.insets = m_fieldInsets;
if (fill)
m_gbc.fill = GridBagConstraints.HORIZONTAL;
else
m_gbc.fill = GridBagConstraints.NONE;
centerPanel.add(field, m_gbc);
} // createLine
/**
* Fill Greeting
* @return KeyNamePair Array of Greetings
*/
private Object[] fillGreeting()
{
ArrayList list = new ArrayList();
// Optional
list.add (new KeyNamePair(-1, " "));
String SQL = "SELECT C_Greeting_ID, Name FROM C_Greeting";
try
{
Statement stmt = DB.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next())
{
int key = rs.getInt("C_Greeting_ID");
String name = rs.getString("Name");
list.add (new KeyNamePair(key, name));
}
rs.close();
stmt.close();
}
catch (SQLException e)
{
Log.error("VBPartner.fillGreeting", e);
}
return list.toArray();
} // fillGreeting
/**
* Search m_greeting for key
* @param key C_Greeting_ID
* @return Greeting
*/
private KeyNamePair getGreeting (int key)
{
for (int i = 0; i < m_greeting.length; i++)
{
KeyNamePair p = (KeyNamePair)m_greeting[i];
if (p.getKey() == key)
return p;
}
return new KeyNamePair(-1, " ");
} // getGreeting
/**
* Load BPartner
* @param C_BPartner_ID - existing BPartner or 0 for new
* @return true if loaded
*/
public boolean loadBPartner (int C_BPartner_ID)
{
Log.trace(Log.l3_Util, "VBPartner.load - " + C_BPartner_ID);
// we have it already
if (C_BPartner_ID == m_C_BPartner_ID)
return true;
// new bpartner
if (C_BPartner_ID == 0)
{
m_C_BPartner_ID = C_BPartner_ID;
return true;
}
m_C_BPartner_ID = C_BPartner_ID;
String SQL = "SELECT p.Value,p.C_Greeting_ID AS C_GreetingBP_ID,p.Name,p.Name2,"
+ "c.Name AS Contact,c.C_Greeting_ID,c.Title,"
+ "l.Phone,l.Phone2,l.Fax, c.EMail, l.C_Location_ID,"
+ "c.C_BPartner_Contact_ID, l.C_BPartner_Location_ID "
+ "FROM C_BPartner p, C_BPartner_Contact c, C_BPartner_Location l "
+ "WHERE p.C_BPartner_ID=c.C_BPartner_ID(+)"
+ " AND p.C_BPartner_ID=l.C_BPartner_ID(+)"
+ " AND p.C_BPartner_ID=?" // 1
+ " ORDER BY l.IsBillTo Desc"; // BillTo first
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, m_C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
if (!rs.next())
{
ADialog.error(m_WindowNo, this, "BPartnerNotFound");
rs.close();
pstmt.close();
return false;
}
// Load values
OldValue = rs.getString("Value");
if (OldValue == null)
OldValue = "";
fValue.setText(OldValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -