Search in sources :

Example 66 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InvoiceGenFromShipment method executeQuery.

/**
	 *  Query Info
	 */
public void executeQuery(KeyNamePair docTypeKNPair, IMiniTable miniTable) {
    log.info("");
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    String sql = "";
    if (docTypeKNPair.getKey() == MInOut.Table_ID) {
        //@Trifon old: MOrder.Table_ID
        sql = getInOutSQL();
    } else {
    //            sql = getRMASql();
    }
    //  reset table
    int row = 0;
    miniTable.setRowCount(row);
    //  Execute
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql.toString(), null);
        pstmt.setInt(1, AD_Client_ID);
        rs = pstmt.executeQuery();
        //
        while (rs.next()) {
            //  extend table
            miniTable.setRowCount(row + 1);
            int i = 0;
            //  set values
            //  M_InOut_ID @Trifon
            miniTable.setValueAt(new IDColumn(rs.getInt(1)), row, i++);
            //				miniTable.setValueAt(rs.getBigDecimal(7), row, i++);          //  TotalQty @Trifon
            //  Doc No
            miniTable.setValueAt(rs.getString(4), row, i++);
            //  BPartner
            miniTable.setValueAt(rs.getString(5), row, i++);
            //  MovementDate @Trifon
            miniTable.setValueAt(rs.getTimestamp(6), row, i++);
            //				miniTable.setValueAt(rs.getString(2), row, i++);              //  Org
            //				miniTable.setValueAt(rs.getString(3), row, i++);              //  DocType
            //  Description
            miniTable.setValueAt(rs.getString(8), row, i++);
            //  prepare next
            row++;
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql.toString(), e);
    } finally {
        DB.close(rs, pstmt);
    }
    //
    miniTable.autoSize();
//statusBar.setStatusDB(String.valueOf(miniTable.getRowCount()));
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 67 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class VFactReconcile method generateReconciliation.

//  calculateSelection
/**
	 *  Generate Reconciliation record
	 */
private void generateReconciliation() {
    log.info("");
    //
    miniTable.stopEditor(true);
    if (miniTable.getRowCount() == 0)
        return;
    miniTable.setRowSelectionInterval(0, 0);
    calculateSelection();
    if (m_noSelected == 0)
        return;
    String format = "yyyy-MM-dd HH:mm:ss.SSS";
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    String time = sdf.format(cal.getTime());
    String matchcode = "Manual: " + Env.getContext(Env.getCtx(), "#AD_User_Name") + " " + time;
    for (int r = 0; r < miniTable.getModel().getRowCount(); r++) {
        if (((IDColumn) miniTable.getModel().getValueAt(r, idColIndex)).isSelected()) {
            int factId = ((IDColumn) miniTable.getModel().getValueAt(r, idColIndex)).getRecord_ID();
            MFactReconciliation rec = new Query(Env.getCtx(), MFactReconciliation.Table_Name, "Fact_Acct_ID = ?", null).setParameters(new Object[] { factId }).first();
            if (rec == null) {
                rec = new MFactReconciliation(Env.getCtx(), 0, null);
                rec.setFact_Acct_ID(factId);
            }
            rec.setMatchCode(matchcode);
            rec.setIsDirectLoad(true);
            rec.saveEx();
            ((DefaultTableModel) miniTable.getModel()).removeRow(r--);
        }
    }
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) Query(org.compiere.model.Query) MFactReconciliation(org.compiere.model.MFactReconciliation) Calendar(java.util.Calendar) DefaultTableModel(javax.swing.table.DefaultTableModel) SimpleDateFormat(java.text.SimpleDateFormat)

Example 68 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class VFactReconcile method calculateSelection.

//  valueChanged
/**
	 *  Calculate selected rows.
	 *  - add up selected rows
	 */
public void calculateSelection() {
    m_noSelected = 0;
    BigDecimal selectedAmt = new BigDecimal(0.0);
    int rows = miniTable.getRowCount();
    for (int i = 0; i < rows; i++) {
        IDColumn id = (IDColumn) miniTable.getModel().getValueAt(i, idColIndex);
        if (id.isSelected()) {
            BigDecimal amt = (BigDecimal) miniTable.getModel().getValueAt(i, amtColIndex);
            if (amt != null)
                selectedAmt = selectedAmt.add(amt);
            m_noSelected++;
        }
    }
    //  Information
    StringBuffer info = new StringBuffer();
    info.append(m_noSelected).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected")).append(" / ").append(miniTable.getRowCount());
    differenceField.setText(m_format.format(selectedAmt));
    dataStatus.setText(info.toString());
    //
    bGenerate.setEnabled(m_noSelected != 0 && Env.ZERO.compareTo(selectedAmt) == 0 && !isReconciled.isSelected());
    bReset.setEnabled(m_noSelected > 0 && isReconciled.isSelected());
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) BigDecimal(java.math.BigDecimal)

Example 69 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class VOrderDistributionReceipt method tableChanged.

//	stateChanged
/**
	 *  Table Model Listener
	 *  @param e event
	 */
public void tableChanged(TableModelEvent e) {
    int rowsSelected = 0;
    int rows = miniTable.getRowCount();
    for (int i = 0; i < rows; i++) {
        //  ID in column 0
        IDColumn id = (IDColumn) miniTable.getValueAt(i, 0);
        if (id != null && id.isSelected())
            rowsSelected++;
    }
    statusBar.setStatusDB(" " + rowsSelected + " ");
}
Also used : IDColumn(org.compiere.minigrid.IDColumn)

Example 70 with IDColumn

use of org.compiere.minigrid.IDColumn in project adempiere by adempiere.

the class InfoBPartnerPanel method refresh.

/**
	 * 	Refresh Query
	 */
protected void refresh() {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int leadRowKey = 0;
    if (p_table != null || p_table.getRowCount() > 0)
        leadRowKey = p_table.getLeadRowKey();
    if (m_C_BPartner_ID != leadRowKey) {
        //  From the main table
        m_C_BPartner_ID = leadRowKey;
    }
    if (detailTabBox.getSelectedIndex() == 0) {
        //  Contact tab	
        log.finest(m_sqlContact);
        try {
            pstmt = DB.prepareStatement(m_sqlContact, null);
            pstmt.setInt(1, m_C_BPartner_ID);
            rs = pstmt.executeQuery();
            contactTbl.loadTable(rs);
            rs.close();
        } catch (Exception e) {
            log.log(Level.WARNING, m_sqlContact, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
    } else {
        //  Address tab	
        log.finest(m_sqlAddress);
        try {
            pstmt = DB.prepareStatement(m_sqlAddress, null);
            pstmt.setInt(1, m_C_BPartner_ID);
            rs = pstmt.executeQuery();
            addressTbl.loadTable(rs);
            rs.close();
        } catch (Exception e) {
            log.log(Level.WARNING, m_sqlContact, e);
        } finally {
            DB.close(rs, pstmt);
            rs = null;
            pstmt = null;
        }
        String trxName = Trx.createTrxName();
        for (int row = 0; row < addressTbl.getRowCount(); row++) {
            int loc_id = 0;
            Object loc_data = addressTbl.getValueAt(row, addressTbl.getKeyColumnIndex());
            if (loc_data != null && loc_data instanceof IDColumn) {
                IDColumn dataColumn = (IDColumn) loc_data;
                loc_id = dataColumn.getRecord_ID();
            }
            MLocation loc = MLocation.getBPLocation(Env.getCtx(), loc_id, trxName);
            addressTbl.setValueAt(loc.toString(), row, ADDRESS_INDEX);
        }
        Trx.get(trxName, false).close();
        addressTbl.autoSize();
    }
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MLocation(org.compiere.model.MLocation) SQLException(java.sql.SQLException)

Aggregations

IDColumn (org.compiere.minigrid.IDColumn)79 SQLException (java.sql.SQLException)25 BigDecimal (java.math.BigDecimal)20 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)20 ArrayList (java.util.ArrayList)16 KeyNamePair (org.compiere.util.KeyNamePair)13 Timestamp (java.sql.Timestamp)8 Vector (java.util.Vector)5 GridField (org.compiere.model.GridField)5 MBrowseField (org.adempiere.model.MBrowseField)4 ApplicationException (org.adempiere.webui.exception.ApplicationException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 DefaultTableModel (javax.swing.table.DefaultTableModel)3 PO (org.compiere.model.PO)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 ChangeEvent (javax.swing.event.ChangeEvent)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2