Search in sources :

Example 56 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VMatch method tableChanged.

//  cmd_searchTo
/***************************************************************************
	 *  Table Model Listener - calculate matched Qty
	 *  @param e event
	 */
public void tableChanged(TableModelEvent e) {
    if (e.getColumn() != 0)
        return;
    log.config("Row=" + e.getFirstRow() + "-" + e.getLastRow() + ", Col=" + e.getColumn() + ", Type=" + e.getType());
    panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    //  Matched From
    int matchedRow = xMatchedTable.getSelectedRow();
    KeyNamePair Product = (KeyNamePair) xMatchedTable.getValueAt(matchedRow, 5);
    //  Matched To
    double qty = 0.0;
    int noRows = 0;
    for (int row = 0; row < xMatchedToTable.getRowCount(); row++) {
        IDColumn id = (IDColumn) xMatchedToTable.getValueAt(row, 0);
        if (id != null && id.isSelected()) {
            KeyNamePair ProductCompare = (KeyNamePair) xMatchedToTable.getValueAt(row, 5);
            if (Product.getKey() != ProductCompare.getKey()) {
                id.setSelected(false);
            } else {
                if (matchMode.getSelectedIndex() == MODE_NOTMATCHED)
                    //  doc
                    qty += ((Double) xMatchedToTable.getValueAt(row, I_QTY)).doubleValue();
                //  matched
                qty -= ((Double) xMatchedToTable.getValueAt(row, I_MATCHED)).doubleValue();
                noRows++;
            }
        }
    }
    //  update quantities
    m_xMatchedTo = new BigDecimal(qty);
    xMatchedTo.setValue(m_xMatchedTo);
    difference.setValue(m_xMatched.subtract(m_xMatchedTo));
    bProcess.setEnabled(noRows != 0);
    panel.setCursor(Cursor.getDefaultCursor());
    //  Status
    statusBar.setStatusDB(noRows);
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Example 57 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VSetup method dynInit.

//	jbInit
/**
	 *	Dynamic Init
	 */
private void dynInit() {
    // Using current locale for default values - teo_sarca [ 1691388 ] 
    Locale locale = Locale.getDefault();
    Currency currency = Currency.getInstance(locale);
    //	Currency
    // teo_sarca [ 1691388 ]
    String sql = "SELECT C_Currency_ID, Description, ISO_Code FROM C_Currency ORDER BY 2";
    Statement stmt = null;
    ResultSet rs = null;
    try {
        stmt = DB.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            fCurrency.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
            // Currency from locale will be the default currency - teo_sarca [ 1691388 ]
            if (currency != null && currency.getCurrencyCode().equals(rs.getString(3)))
                fCurrency.setSelectedIndex(fCurrency.getItemCount() - 1);
        }
    } catch (SQLException e1) {
        log.log(Level.SEVERE, "VSetup.dynInit -currency", e1);
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
    //	Country
    int C_Country_ID = 0;
    // teo_sarca [ 1691388 ]
    sql = "SELECT C_Country_ID, Name, CountryCode FROM C_Country ORDER BY 2";
    try {
        stmt = DB.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            fCountry.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
            // Country from locale will be the default country - teo_sarca [ 1691388 ]
            if (locale.getCountry().equals(rs.getString(3))) {
                fCountry.setSelectedIndex(fCountry.getItemCount() - 1);
                C_Country_ID = rs.getInt(1);
            }
        }
    } catch (SQLException e1) {
        log.log(Level.SEVERE, "VSetup.dynInit -country", e1);
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
    //	Region (optional)
    sql = "SELECT C_Region_ID, Name, C_Country_ID FROM C_Region ORDER BY C_Country_ID, Name";
    boolean isSelected = false;
    try {
        fRegion.addItem(new KeyNamePair(0, " "));
        stmt = DB.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            fRegion.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
            // First region for selected country will be the default - teo_sarca [ 1691388 ]
            if (!isSelected && rs.getInt(3) == C_Country_ID) {
                fRegion.setSelectedIndex(fRegion.getItemCount() - 1);
                isSelected = true;
            }
        }
    } catch (SQLException e1) {
        log.log(Level.SEVERE, "VSetup.dynInit -region", e1);
    } finally {
        DB.close(rs, stmt);
        rs = null;
        stmt = null;
    }
    //  General Listeners
    confirmPanel.addActionListener(this);
    buttonLoadAcct.addActionListener(this);
    confirmPanel.getOKButton().setEnabled(false);
}
Also used : Locale(java.util.Locale) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Currency(java.util.Currency) ResultSet(java.sql.ResultSet) KeyNamePair(org.compiere.util.KeyNamePair)

Example 58 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VSetup method run.

//	createSetup
/**
	 * 	Create Setup Batch Part.
	 * 	if done - disposes window
	 */
public void run() {
    MSetup ms = new MSetup(Env.getCtx(), m_WindowNo);
    m_frame.setBusyTimer(45);
    //  Step 1
    boolean ok = ms.createClient(fClientName.getText(), fOrgValue.getText(), fOrgName.getText(), fUserClient.getText(), fUserOrg.getText(), null, null, null, null, null, null, null, 0);
    String info = ms.getInfo();
    if (ok) {
        //  Generate Accounting
        KeyNamePair currency = (KeyNamePair) fCurrency.getSelectedItem();
        if (!ms.createAccounting(currency, fProduct.isSelected(), fBPartner.isSelected(), fProject.isSelected(), fMCampaign.isSelected(), fSRegion.isSelected(), null, 0, m_file)) {
            ADialog.error(m_WindowNo, this, "AccountSetupError");
            dispose();
        } else {
            //  Generate Entities
            KeyNamePair p = (KeyNamePair) fCountry.getSelectedItem();
            int C_Country_ID = p.getKey();
            p = (KeyNamePair) fRegion.getSelectedItem();
            int C_Region_ID = p.getKey();
            ms.createEntities(C_Country_ID, fCity.getText(), C_Region_ID, currency.getKey(), null, null);
            info += ms.getInfo();
            //	Create Print Documents
            PrintUtil.setupPrintForm(ms.getAD_Client_ID());
        }
    }
    ADialog.info(m_WindowNo, this, "VSetup", info);
    dispose();
}
Also used : MSetup(org.compiere.model.MSetup) KeyNamePair(org.compiere.util.KeyNamePair)

Example 59 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VPaySelect method loadTableInfo.

//  loadBankInfo
/**
	 *  Query and create TableInfo
	 */
private void loadTableInfo() {
    Timestamp payDate = (Timestamp) fieldPayDate.getValue();
    miniTable.setColorCompare(payDate);
    log.config("PayDate=" + payDate);
    BankInfo bi = (BankInfo) fieldBankAccount.getSelectedItem();
    ValueNamePair paymentRule = (ValueNamePair) fieldPaymentRule.getSelectedItem();
    KeyNamePair docType = (KeyNamePair) fieldDtype.getSelectedItem();
    int c_bpartner_id = 0;
    if (fieldBPartner.getValue() != null)
        c_bpartner_id = ((Integer) fieldBPartner.getValue()).intValue();
    loadTableInfo(bi, payDate, paymentRule, onlyDue.isSelected(), c_bpartner_id, docType, miniTable);
    calculateSelection();
}
Also used : ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) Timestamp(java.sql.Timestamp)

Example 60 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VCreateFromShipmentUI method findProductRow.

/**
	 * Finds the row where a given product is. If the product is not found
	 * in the table -1 is returned.
	 * @param M_Product_ID
	 * @return  Row of the product or -1 if non existing.
	 * 
	 */
private int findProductRow(int M_Product_ID) {
    DefaultTableModel model = (DefaultTableModel) v_CreateFromPanel.getMiniTable().getModel();
    KeyNamePair kp;
    for (int i = 0; i < model.getRowCount(); i++) {
        kp = (KeyNamePair) model.getValueAt(i, 4);
        if (kp.getKey() == M_Product_ID) {
            return (i);
        }
    }
    return (-1);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) KeyNamePair(org.compiere.util.KeyNamePair)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7