📄 vaccountdialog.java
字号:
m_gbc.gridy = m_line++;
m_gbc.gridx = 0;
m_gbc.gridwidth = 4;
m_gbc.insets = new Insets(5,15,2,0); // top,left,bottom,right
m_gbc.fill = GridBagConstraints.HORIZONTAL;
f_Description.setFont(f_Description.getFont().deriveFont(Font.ITALIC));
parameterPanel.add(f_Description, m_gbc);
// Finish
m_query = new MQuery();
m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
if (m_mAccount.C_ValidCombination_ID == 0)
m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
else
{
MQuery query = new MQuery();
query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
m_mTab.setQuery(query);
}
m_mTab.query(false);
m_gridController.getTable().addMouseListener(new VAccountDialog_mouseAdapter(this));
m_gridController.addDataStatusListener(this);
statusBar.setStatusLine(s_AcctSchema.toString());
statusBar.setStatusDB("?");
// Initial value
if (m_mAccount.C_ValidCombination_ID != 0)
m_mTab.navigate(0);
log.config("fini");
return true;
} // initAccount
/**
* Add Editor to parameterPanel alernative right/left depending on m_newRow.
* Field Value changes update Editors
* @param field field
* @param editor editor
* @param mandatory mandatory
*/
private void addLine (MField field, VEditor editor, boolean mandatory)
{
log.fine("Field=" + field);
JLabel label = VEditorFactory.getLabel(field);
label.setLabelFor((Component)editor);
editor.setReadWrite(true);
editor.setMandatory(mandatory);
// MField => VEditor
field.addPropertyChangeListener(editor);
// label
if (m_newRow)
{
m_gbc.gridy = m_line++;
m_gbc.gridx = 0;
}
else
m_gbc.gridx = 2;
m_gbc.insets = m_labelInsets;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
m_gbc.weightx = 0;
parameterPanel.add(label, m_gbc);
// Field
if (m_newRow)
m_gbc.gridx = 1;
else
m_gbc.gridx = 3;
m_gbc.insets = m_fieldInsets;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
m_gbc.weightx = 1;
parameterPanel.add((Component)editor, m_gbc);
//
m_newRow = !m_newRow;
} // addLine
/**
* Load Information
* @param C_ValidCombination_ID valid combination
* @param C_AcctSchema_ID acct schema
*/
private void loadInfo (int C_ValidCombination_ID, int C_AcctSchema_ID)
{
log.fine("C_ValidCombination_ID=" + C_ValidCombination_ID);
String sql = "SELECT * FROM C_ValidCombination WHERE C_ValidCombination_ID=? AND C_AcctSchema_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_ValidCombination_ID);
pstmt.setInt(2, C_AcctSchema_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
if (f_Alias != null)
f_Alias.setValue(rs.getString("Alias"));
f_Combination.setValue(rs.getString("Combination"));
//
loadInfoOf (rs, f_AD_Org_ID, "AD_Org_ID");
loadInfoOf (rs, f_Account_ID, "Account_ID");
loadInfoOf (rs, f_SubAcct_ID, "C_SubAcct_ID");
//
loadInfoOf (rs, f_M_Product_ID, "M_Product_ID");
loadInfoOf (rs, f_C_BPartner_ID, "C_BPartner_ID");
loadInfoOf (rs, f_C_Campaign_ID, "C_Campaign_ID");
loadInfoOf (rs, f_C_LocFrom_ID, "C_LocFrom_ID");
loadInfoOf (rs, f_C_LocTo_ID, "C_LocTo_ID");
loadInfoOf (rs, f_C_Project_ID, "C_Project_ID");
loadInfoOf (rs, f_C_SalesRegion_ID, "C_SalesRegion_ID");
loadInfoOf (rs, f_AD_OrgTrx_ID, "AD_OrgTrx_ID");
loadInfoOf (rs, f_C_Activity_ID, "C_Activity_ID");
loadInfoOf (rs, f_User1_ID, "User1_ID");
loadInfoOf (rs, f_User2_ID, "User2_ID");
//
f_Description.setText (rs.getString("Description"));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
} // loadInfo
/**
* Set Value of Editor
* @param rs result set
* @param editor editor
* @param name name
* @throws SQLException
*/
private void loadInfoOf (ResultSet rs, VEditor editor, String name) throws SQLException
{
if (editor == null)
return;
int intValue = rs.getInt(name);
if (rs.wasNull())
editor.setValue(null);
else
editor.setValue(new Integer (intValue));
} // loadInfoOf
/**
* dispose
*/
public void dispose()
{
saveSelection();
// GridController
if (m_gridController != null)
m_gridController.dispose();
m_gridController = null;
// Model
m_mTab = null;
if (m_mWindow != null)
m_mWindow.dispose();
m_mWindow = null;
removeAll();
Env.clearWinContext(m_WindowNo);
super.dispose();
} // dispose
/**
* Save Selection
*/
private void saveSelection()
{
if (m_changed && m_gridController != null)
{
int row = m_gridController.getTable().getSelectedRow();
if (row >= 0)
m_C_ValidCombination_ID = ((Integer)m_mTab.getValue(row, "C_ValidCombination_ID")).intValue();
log.config("(" + row + ") - " + m_C_ValidCombination_ID);
}
} // saveSelection
/**
* ActionListener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
m_changed = true;
dispose();
}
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
{
m_changed = false;
dispose();
}
//
else if (e.getSource() == bSave)
action_Save();
else if (e.getSource() == bIgnore)
action_Ignore();
// all other
else
action_Find (true);
} // actionPerformed
/**
* Status Change Listener
* @param e event
*/
public void dataStatusChanged (DataStatusEvent e)
{
log.config(e.toString());
String info = (String)m_mTab.getValue("Description");
f_Description.setText (info);
//
// log.info( ">> Field=" + m_mTab.getValue("AD_Org_ID"),
// "Editor=" + f_AD_Org_ID.getValue());
// if (f_AD_Org_ID.getValue() == null)
// f_AD_Org_ID.setValue(m_mTab.getValue("AD_Org_ID"));
} // statusChanged
/**
* Action Find.
* - create where clause
* - query database
* @param includeAliasCombination include alias combination
*/
private void action_Find (boolean includeAliasCombination)
{
log.info("");
setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// Create where Clause
MQuery query = null;
if (m_query != null)
query = m_query.deepCopy();
else
query = new MQuery();
// Alias
if (includeAliasCombination && f_Alias != null && f_Alias.getValue().toString().length() > 0)
{
String value = f_Alias.getValue().toString().toUpperCase();
if (!value.endsWith("%"))
value += "%";
query.addRestriction("UPPER(Alias)", MQuery.LIKE, value);
}
// Combination (mandatory)
if (includeAliasCombination && f_Combination.getValue().toString().length() > 0)
{
String value = f_Combination.getValue().toString().toUpperCase();
if (!value.endsWith("%"))
value += "%";
query.addRestriction("UPPER(Combination)", MQuery.LIKE, value);
}
// Org (mandatory)
if (f_AD_Org_ID != null && f_AD_Org_ID.getValue() != null)
query.addRestriction("AD_Org_ID", MQuery.EQUAL, f_AD_Org_ID.getValue());
// Account (mandatory)
if (f_Account_ID != null && f_Account_ID.getValue() != null)
query.addRestriction("Account_ID", MQuery.EQUAL, f_Account_ID.getValue());
if (f_SubAcct_ID != null && f_SubAcct_ID.getValue() != null)
query.addRestriction("C_SubAcct_ID", MQuery.EQUAL, f_SubAcct_ID.getValue());
// Product
if (f_M_Product_ID != null && f_M_Product_ID.getValue() != null)
query.addRestriction("M_Product_ID", MQuery.EQUAL, f_M_Product_ID.getValue());
// BPartner
if (f_C_BPartner_ID != null && f_C_BPartner_ID.getValue() != null)
query.addRestriction("C_BPartner_ID", MQuery.EQUAL, f_C_BPartner_ID.getValue());
// Campaign
if (f_C_Campaign_ID != null && f_C_Campaign_ID.getValue() != null)
query.addRestriction("C_Campaign_ID", MQuery.EQUAL, f_C_Campaign_ID.getValue());
// Loc From
if (f_C_LocFrom_ID != null && f_C_LocFrom_ID.getValue() != null)
query.addRestriction("C_LocFrom_ID", MQuery.EQUAL, f_C_LocFrom_ID.getValue());
// Loc To
if (f_C_LocTo_ID != null && f_C_LocTo_ID.getValue() != null)
query.addRestriction("C_LocTo_ID", MQuery.EQUAL, f_C_LocTo_ID.getValue());
// Project
if (f_C_Project_ID != null && f_C_Project_ID.getValue() != null)
query.addRestriction("C_Project_ID", MQuery.EQUAL, f_C_Project_ID.getValue());
// SRegion
if (f_C_SalesRegion_ID != null && f_C_SalesRegion_ID.getValue() != null)
query.addRestriction("C_SalesRegion_ID", MQuery.EQUAL, f_C_SalesRegion_ID.getValue());
// Org Trx
if (f_AD_OrgTrx_ID != null && f_AD_OrgTrx_ID.getValue() != null)
query.addRestriction("AD_OrgTrx_ID", MQuery.EQUAL, f_AD_OrgTrx_ID.getValue());
// Activity
if (f_C_Activity_ID != null && f_C_Activity_ID.getValue() != null)
query.addRestriction("C_Activity_ID", MQuery.EQUAL, f_C_Activity_ID.getValue());
// User 1
if (f_User1_ID != null && f_User1_ID.getValue() != null)
query.addRestriction("User1_ID", MQuery.EQUAL, f_User1_ID.getValue());
// User 2
if (f_User2_ID != null && f_User2_ID.getValue() != null)
query.addRestriction("User2_ID", MQuery.EQUAL, f_User2_ID.getValue());
// Query
m_mTab.setQuery(query);
m_mTab.query(false);
statusBar.setStatusDB(String.valueOf(m_mTab.getRowCount()));
setCursor (Cursor.getDefaultCursor());
} // action_Find
/**
* Create/Save Account
*/
private void action_Save()
{
log.info("");
/**
* Check completeness (mandatory fields) ... and for duplicates
*/
StringBuffer sb = new StringBuffer();
StringBuffer sql = new StringBuffer ("SELECT C_ValidCombination_ID, Alias FROM C_ValidCombination WHERE ");
Object value = null;
if (s_AcctSchema.isHasAlias())
{
value = f_Alias.getValue().toString();
if (value == null)
sb.append(Msg.translate(Env.getCtx(), "Alias")).append(", ");
}
MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
for (int i = 0; i < elements.length; i++)
{
MAcctSchemaElement ase = elements[i];
String type = ase.getElementType();
//
if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization))
{
value = f_AD_Org_ID.getValue();
sql.append("AD_Org_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
}
else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account))
{
value = f_Account_ID.getValue();
sql.append("Account_ID");
if (value == null)
sql.append(" IS NULL AND ");
else
sql.append("=").append(value).append(" AND ");
}
else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount))
{
value = f_SubAcct_ID.getValue();
sql.append("C_SubAcct_ID");
if (value == null)
sql.append(" IS NULL AND ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -