📄 vcharge.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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.form;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import org.compiere.apps.*;
import org.compiere.minigrid.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Create Charge from Accounts
*
* @author Jorg Janke
* @version $Id: VCharge.java,v 1.28 2005/12/27 06:18:37 jjanke Exp $
*/
public class VCharge extends CPanel
implements FormPanel, ActionListener
{
/**
* Initialize Panel
* @param WindowNo window
* @param frame parent frame
*/
public void init (int WindowNo, FormFrame frame)
{
log.info("");
m_WindowNo = WindowNo;
m_frame = frame;
try
{
jbInit();
dynInit();
frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
frame.getContentPane().add(confirmPanel, BorderLayout.SOUTH);
}
catch(Exception e)
{
log.log(Level.SEVERE, "", e);
}
} // init
/** Window No */
private int m_WindowNo = 0;
/** FormFrame */
private FormFrame m_frame;
/** Account Element */
private int m_C_Element_ID = 0;
/** AccountSchema */
private int m_C_AcctSchema_ID = 0;
/** Default Charge Tax Category */
private int m_C_TaxCategory_ID = 0;
private int m_AD_Client_ID = 0;
private int m_AD_Org_ID = 0;
private int m_CreatedBy = 0;
private MAcctSchema m_acctSchema = null;
/** Logger */
private static CLogger log = CLogger.getCLogger(VCharge.class);
//
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel newPanel = new CPanel();
private TitledBorder newBorder;
private GridBagLayout newLayout = new GridBagLayout();
private JLabel valueLabel = new JLabel();
private JTextField valueField = new JTextField();
private JCheckBox isExpense = new JCheckBox();
private JLabel nameLabel = new JLabel();
private JTextField nameField = new JTextField();
private JButton newButton = new JButton();
private CPanel accountPanel = new CPanel();
private TitledBorder accountBorder;
private BorderLayout accountLayout = new BorderLayout();
private CPanel accountOKPanel = new CPanel();
private JButton accountButton = new JButton();
private FlowLayout accountOKLayout = new FlowLayout();
private JScrollPane dataPane = new JScrollPane();
private MiniTable dataTable = new MiniTable();
private ConfirmPanel confirmPanel = new ConfirmPanel();
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
CompiereColor.setBackground(this);
newBorder = new TitledBorder("");
accountBorder = new TitledBorder("");
mainPanel.setLayout(mainLayout);
newPanel.setBorder(newBorder);
newPanel.setLayout(newLayout);
newBorder.setTitle(Msg.getMsg(Env.getCtx(), "ChargeNewAccount"));
valueLabel.setText(Msg.translate(Env.getCtx(), "Value"));
isExpense.setSelected(true);
isExpense.setText(Msg.getMsg(Env.getCtx(), "Expense"));
nameLabel.setText(Msg.translate(Env.getCtx(), "Name"));
nameField.setColumns(20);
valueField.setColumns(10);
newButton.setText(Msg.getMsg(Env.getCtx(), "Create"));
newButton.addActionListener(this);
accountPanel.setBorder(accountBorder);
accountPanel.setLayout(accountLayout);
accountBorder.setTitle(Msg.getMsg(Env.getCtx(), "ChargeFromAccount"));
accountButton.setText(Msg.getMsg(Env.getCtx(), "Create"));
accountButton.addActionListener(this);
accountOKPanel.setLayout(accountOKLayout);
accountOKLayout.setAlignment(FlowLayout.RIGHT);
confirmPanel.addActionListener(this);
//
mainPanel.add(newPanel, BorderLayout.NORTH);
newPanel.add(valueLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
newPanel.add(valueField, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
newPanel.add(nameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
newPanel.add(nameField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
newPanel.add(isExpense, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
newPanel.add(newButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.add(accountPanel, BorderLayout.CENTER);
accountPanel.add(accountOKPanel, BorderLayout.SOUTH);
accountOKPanel.add(accountButton, null);
accountPanel.add(dataPane, BorderLayout.CENTER);
dataPane.getViewport().add(dataTable, null);
} // jbInit
/**
* Dynamic Init
* - Get defaults for primary AcctSchema
* - Create Table with Accounts
*/
private void dynInit()
{
m_C_AcctSchema_ID = Env.getContextAsInt(Env.getCtx(), "$C_AcctSchema_ID");
// get Element
String sql = "SELECT C_Element_ID FROM C_AcctSchema_Element "
+ "WHERE ElementType='AC' AND C_AcctSchema_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_C_AcctSchema_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
m_C_Element_ID = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
if (m_C_Element_ID == 0)
return;
// Table
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
sql = "SELECT C_ElementValue_ID,Value, Name, AccountType "
+ "FROM C_ElementValue "
+ "WHERE AccountType IN ('R','E')"
+ " AND IsSummary='N'"
+ " AND C_Element_ID=? "
+ "ORDER BY 2";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_C_Element_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(4);
line.add(new Boolean(false)); // 0-Selection
KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
line.add(pp); // 1-Value
line.add(rs.getString(3)); // 2-Name
boolean isExpenseType = rs.getString(4).equals("E");
line.add(new Boolean(isExpenseType)); // 3-Expense
data.add(line);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
// Header Info
Vector<String> columnNames = new Vector<String>(4);
columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));
columnNames.add(Msg.translate(Env.getCtx(), "Value"));
columnNames.add(Msg.translate(Env.getCtx(), "Name"));
columnNames.add(Msg.getMsg(Env.getCtx(), "Expense"));
// Set Model
DefaultTableModel model = new DefaultTableModel(data, columnNames);
dataTable.setModel(model);
//
dataTable.setColumnClass(0, Boolean.class, false); // 0-Selection
dataTable.setColumnClass(1, String.class, true); // 1-Value
dataTable.setColumnClass(2, String.class, true); // 2-Name
dataTable.setColumnClass(3, Boolean.class, true); // 3-Expense
// Table UI
dataTable.autoSize();
// Other Defaults
m_AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
m_AD_Org_ID = Env.getAD_Org_ID(Env.getCtx());
m_CreatedBy = Env.getAD_User_ID(Env.getCtx());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -