Search in sources :

Example 81 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class Viewer method main.

//	cmd_translate
/*************************************************************************/
/**
	 * 	Test
	 * 	@param args args
	 */
public static void main(String[] args) {
    Login.initTest(true);
    MQuery q = new MQuery("C_Invoice");
    q.addRestriction("C_Invoice_ID", MQuery.EQUAL, new Integer(103));
    //	102 = Invoice - 100 = Order
    PrintInfo i = new PrintInfo("test", X_C_Invoice.Table_ID, 102, 0);
    MPrintFormat f = MPrintFormat.get(Env.getCtx(), 102, false);
    ReportEngine re = new ReportEngine(Env.getCtx(), f, q, i);
    //	MPrintFormat f = new MPrintFormat(Env.getCtx(), 101);
    //	ReportEngine re = new ReportEngine(f, null);
    new Viewer(re);
}
Also used : MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo)

Example 82 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class WWindow method executeCommand.

//  doPost
/**************************************************************************
	 *  Execute Command.
	 *
	 *  @param request request
	 *  @param p_cmd command
	 *  @param wsc session context
	 *  @param ws window status
	 */
private void executeCommand(HttpServletRequest request, String p_cmd, MobileSessionCtx wsc, WWindowStatus ws) {
    //  Get Parameter: Command and Tab changes
    String p_tab = MobileUtil.getParameter(request, P_Tab);
    //  MR Row Command
    String p_row = MobileUtil.getParameter(request, P_MR_RowNo);
    log.config(p_cmd + " - Tab=" + p_tab + " - Row=" + p_row);
    /**
		 *  Multi-Row Selection (i.e. display single row)
		 */
    if (p_row != null && p_row.length() > 0) {
        try {
            int newRowNo = Integer.parseInt(p_row);
            ws.curTab.navigate(newRowNo);
            ws.curTab.setSingleRow(true);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Parse RowNo=" + p_row, e);
        }
    } else /**
		 *  Tab Change
		 */
    if (p_tab != null && p_tab.length() > 0) {
        int newTabNo = 0;
        try {
            newTabNo = Integer.parseInt(p_tab);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Parse TabNo=" + p_tab, e);
        }
        //  move to detail
        if (newTabNo > ws.curTab.getTabNo()) {
            ws.mWindow.initTab(newTabNo);
            ws.curTab = ws.mWindow.getTab(newTabNo);
            ws.curTab.query(false);
            ws.curTab.navigate(0);
            //Modified by Rob Klein 6/01/07 create new record if no record exists
            if (ws.curTab.getRowCount() < 1) {
                if (!ws.curTab.dataNew(false))
                    ws.curTab.dataIgnore();
            }
        } else //  move back
        if (newTabNo < ws.curTab.getTabNo()) {
            ws.curTab = ws.mWindow.getTab(newTabNo);
            ws.curTab.dataRefresh();
        }
    } else /**
		 *  Multi-Row Toggle
		 */
    if (p_cmd.equals("Multi")) {
        boolean single = ws.curTab.isSingleRow();
        ws.curTab.setSingleRow(!single);
        if (single)
            ws.curTab.navigate(0);
    } else /**
		 *  Refresh
		 */
    if (p_cmd.equals("Refresh")) {
        ws.curTab.dataRefreshAll();
    } else /**
		 *  Attachment
		 */
    if (p_cmd.equals("Attachment")) {
    /** @todo Attachment */
    } else /**
		 *  New
		 */
    if (p_cmd.equals("New")) {
        if (!ws.curTab.dataNew(false))
            ws.curTab.dataIgnore();
    } else /**
		 *  Delete
		 */
    if (p_cmd.equals("Delete")) {
        ws.curTab.dataDelete();
    } else /**
		 *  Save - Check for changed values
		 */
    if (p_cmd.equals("Save")) {
        executeSave(request, wsc, ws);
    } else if (p_cmd.equals("Find")) {
        String strSearch = MobileUtil.getParameter(request, "txtSearch");
        if (strSearch != null) {
            MQuery query = new MQuery();
            if (strSearch.length() != 0)
                query.addRestriction(m_searchField, MQuery.LIKE, strSearch);
            ws.curTab.setQuery(query);
            ws.curTab.query(false);
            ws.curTab.navigate(0);
        }
    } else if (p_cmd.equals("FindAdv")) {
    }
}
Also used : MQuery(org.compiere.model.MQuery) ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 83 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class WAccountDialog method action_Find.

//	statusChanged
/**
	 *	Action Find.
	 *	- create where clause
	 *	- query database
	 *  @param includeAliasCombination include alias combination
	 */
private void action_Find(boolean includeAliasCombination) {
    log.info("");
    //	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());
    //	User 1
    if (f_User3_ID != null && f_User3_ID.getValue() != null)
        query.addRestriction("User3_ID", MQuery.EQUAL, f_User3_ID.getValue());
    //	User 2
    if (f_User4_ID != null && f_User4_ID.getValue() != null)
        query.addRestriction("User4_ID", MQuery.EQUAL, f_User4_ID.getValue());
    //	Query
    m_mTab.setQuery(query);
    m_mTab.query(false);
    statusBar.setStatusDB(String.valueOf(m_mTab.getRowCount()));
}
Also used : MQuery(org.compiere.model.MQuery)

Example 84 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class FindWindow method cmd_ok_Simple.

//  getTargetMField
/**
     *  Simple OK Button pressed
    **/
private void cmd_ok_Simple() {
    //  Create Query String
    m_query = new MQuery(m_tableName);
    if (hasValue && !fieldValue.getText().equals("%") && fieldValue.getText().length() != 0) {
        String value = fieldValue.getText().toUpperCase();
        if (!value.endsWith("%"))
            value += "%";
        m_query.addRestriction("UPPER(Value)", MQuery.LIKE, value, lblValue.getValue(), value);
    }
    //
    if (hasDocNo && !fieldDocumentNo.getText().equals("%") && fieldDocumentNo.getText().length() != 0) {
        String value = fieldDocumentNo.getText().toUpperCase();
        if (!value.endsWith("%"))
            value += "%";
        m_query.addRestriction("UPPER(DocumentNo)", MQuery.LIKE, value, lblDocumentNo.getValue(), value);
    }
    //
    if ((hasName) && !fieldName.getText().equals("%") && fieldName.getText().length() != 0) {
        String value = fieldName.getText().toUpperCase();
        if (!value.endsWith("%"))
            value += "%";
        m_query.addRestriction("UPPER(Name)", MQuery.LIKE, value, lblName.getValue(), value);
    }
    //
    if (hasDescription && !fieldDescription.getText().equals("%") && fieldDescription.getText().length() != 0) {
        String value = fieldDescription.getText().toUpperCase();
        if (!value.endsWith("%"))
            value += "%";
        m_query.addRestriction("UPPER(Description)", MQuery.LIKE, value, lblDescription.getValue(), value);
    }
    //  Special Editors
    for (int i = 0; i < m_sEditors.size(); i++) {
        WEditor wed = (WEditor) m_sEditors.get(i);
        Object value = wed.getValue();
        Object modifiedvalue = null;
        String ColumnSQL = null;
        String ColumnName = wed.getColumnName();
        GridField field = getTargetMField(ColumnName);
        if (value != null && value.toString().length() > 0) {
            log.fine(ColumnName + "=" + value);
            // globalqss - Carlos Ruiz - 20060711
            // fix a bug with virtualColumn + isSelectionColumn not yielding results
            field = getTargetMField(ColumnName);
            // add encryption here if the field is encrypted.
            if (field.isEncryptedColumn()) {
                value = SecureEngine.encrypt(value);
            }
            boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
            ColumnSQL = field.getColumnSQL(false);
            // Be more permissive for String columns
            if (isSearchLike(field)) {
                String valueStr = value.toString().toUpperCase();
                if (!valueStr.endsWith("%"))
                    valueStr += "%";
                //
                ColumnSQL = "UPPER(" + ColumnSQL + ")";
                modifiedvalue = valueStr;
            } else
                modifiedvalue = value;
            //
            if (modifiedvalue.toString().indexOf('%') != -1 && !field.isRangeLookup())
                m_query.addRestriction(ColumnSQL, MQuery.LIKE, modifiedvalue, ColumnName, wed.getDisplay());
            else if (isProductCategoryField && value instanceof Integer)
                m_query.addRestriction(getSubCategoryWhereClause(((Integer) value).intValue()));
            else if (//20121115
            !field.isRangeLookup())
                m_query.addRestriction(ColumnSQL, MQuery.EQUAL, value, ColumnName, wed.getDisplay());
        /*
                if (value.toString().indexOf('%') != -1)
                    m_query.addRestriction(ColumnName, MQuery.LIKE, value, ColumnName, ved.getDisplay());
                else
                    m_query.addRestriction(ColumnName, MQuery.EQUAL, value, ColumnName, ved.getDisplay());
                */
        // end globalqss patch
        }
        if (field.isRangeLookup()) {
            WEditor toRangeEditor = (WEditor) m_sEditors2.get(i);
            Object value2 = null;
            Object parsedValue = null;
            Object parsedValue2 = null;
            String infoDisplay_to = null;
            String infoDisplay = null;
            if (toRangeEditor != null)
                value2 = toRangeEditor.getValue();
            if ((value != null && !value.toString().isEmpty()) && (value2 != null && !value2.toString().isEmpty()) && value2.toString().length() > 0) {
                ColumnName = toRangeEditor.getColumnName();
                log.fine(ColumnName + "=" + value2);
                field = getTargetMField(ColumnName);
                infoDisplay = value.toString();
                parsedValue = parseValue(field, value);
                parsedValue2 = parseValue(field, value2);
                infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, ColumnSQL, infoDisplay, infoDisplay_to);
            } else //		   then get all the records after the First value
            if (value != null && !value.toString().isEmpty() && (value2 == null || value2.toString().isEmpty())) {
                ColumnName = wed.getColumnName();
                m_query.addRestriction(ColumnSQL, MQuery.GREATER_EQUAL, value, ColumnName, wed.getDisplay());
            } else //   	   then get all the records before the second value
            if ((value == null || value.toString().isEmpty()) && value2 != null && !value2.toString().isEmpty()) {
                ColumnName = toRangeEditor.getColumnName();
                field = getTargetMField(ColumnName);
                ColumnSQL = field.getColumnSQL(false);
                m_query.addRestriction(ColumnSQL, MQuery.LESS_EQUAL, value2, ColumnName, toRangeEditor.getDisplay());
            }
        }
    }
    //  editors
    // teo_sarca [ 1708717 ]
    m_isCancel = false;
    //  Test for no records
    if (getNoOfRecords(m_query, true) != 0)
        dispose();
}
Also used : MQuery(org.compiere.model.MQuery) WEditor(org.adempiere.webui.editor.WEditor) GridField(org.compiere.model.GridField)

Example 85 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class FindWindow method codeUserQuery.

//	cmd_save
/**
     * Code the query parameters entered in the table into a string that can be saved in the database.
     * This is the counterpart to {@link #parseUserQuery()}. Also updates the {@link #m_query} variable with 
     * the current query information.
     * @return a StringBuffer containing the coded query information.
     */
private StringBuffer codeUserQuery() {
    m_query = new MQuery(m_tableName);
    StringBuffer code = new StringBuffer();
    int openBrackets = 0;
    List<?> rowList = advancedPanel.getChildren();
    for (int rowIndex = 1; rowIndex < rowList.size(); rowIndex++) {
        //  Column
        ListItem row = (ListItem) rowList.get(rowIndex);
        Listbox column = (Listbox) row.getFellow("listColumn" + row.getId());
        if (column == null)
            continue;
        String ColumnName = column.getSelectedItem().getValue().toString();
        String infoName = column.toString();
        //
        GridField field = getTargetMField(ColumnName);
        if (field == null)
            // Elaine 2008/07/29
            continue;
        boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID());
        String ColumnSQL = field.getColumnSQL(false);
        // Left brackets
        Listbox listLeftBracket = (Listbox) row.getFellow("listLeftBracket" + row.getId());
        String lBrackets = listLeftBracket.getSelectedItem().getValue().toString();
        if (lBrackets != null)
            openBrackets += lBrackets.length();
        // Right brackets
        Listbox listRightBracket = (Listbox) row.getFellow("listRightBracket" + row.getId());
        String rBrackets = listRightBracket.getSelectedItem().getValue().toString();
        if (rBrackets != null)
            openBrackets -= rBrackets.length();
        // And Or
        Listbox listAndOr = (Listbox) row.getFellow("listAndOr" + row.getId());
        String andOr = listAndOr.getSelectedItem().getValue().toString();
        boolean and = true;
        if (rowIndex > 1) {
            and = !"OR".equals(andOr);
        }
        //  Op
        Listbox op = (Listbox) row.getFellow("listOperator" + row.getId());
        if (op == null)
            continue;
        String Operator = op.getSelectedItem().getValue().toString();
        //  Value   ******
        ListCell cellQueryFrom = (ListCell) row.getFellow("cellQueryFrom" + row.getId());
        Object value = cellQueryFrom.getAttribute("value");
        ListCell cellQueryTo = (ListCell) row.getFellow("cellQueryTo" + row.getId());
        Object value2 = cellQueryTo.getAttribute("value");
        if (value == null) {
            // Capture the case "is null" ?
            if (MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op) || MQuery.OPERATORS[MQuery.NOT_EQUAL_INDEX].equals(op)) {
                m_query.addRestriction(ColumnSQL, Operator, null, infoName, null, and, openBrackets);
            } else {
                continue;
            }
        } else {
            // Value has a value - check for range too.
            Object parsedValue = parseValue(field, value);
            if (parsedValue == null)
                continue;
            //TODO - verify compatibility with find.java
            if (field.isEncryptedColumn()) {
                value = SecureEngine.encrypt(value);
            }
            String infoDisplay = value.toString();
            if (field.isLookup())
                infoDisplay = field.getLookup().getDisplay(value);
            else if (field.getDisplayType() == DisplayType.YesNo)
                infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay);
            //  Value2  ******
            if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op.getSelectedItem().toValueNamePair())) {
                if (value2 == null)
                    continue;
                Object parsedValue2 = parseValue(field, value2);
                String infoDisplay_to = value2.toString();
                if (parsedValue2 == null)
                    continue;
                //encrypt the value if we are searching an encrypted column.
                if (field.isEncryptedColumn()) {
                    value2 = SecureEngine.encrypt(value2);
                }
                m_query.addRangeRestriction(ColumnSQL, parsedValue, parsedValue2, infoName, infoDisplay, infoDisplay_to, and, openBrackets);
            } else if (isProductCategoryField && MQuery.OPERATORS[MQuery.EQUAL_INDEX].equals(op)) {
                if (!(parsedValue instanceof Integer)) {
                    continue;
                }
                m_query.addRestriction(getSubCategoryWhereClause(((Integer) parsedValue).intValue()), and, openBrackets);
            } else
                m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay, and, openBrackets);
        }
        if (code.length() > 0)
            code.append(SEGMENT_SEPARATOR);
        code.append(ColumnName).append(FIELD_SEPARATOR).append(Operator).append(FIELD_SEPARATOR).append(value.toString()).append(FIELD_SEPARATOR).append(value2 != null ? value2.toString() : "").append(FIELD_SEPARATOR).append(andOr).append(FIELD_SEPARATOR).append(lBrackets != null ? lBrackets : "").append(FIELD_SEPARATOR).append(rBrackets != null ? rBrackets : "");
    }
    return code;
}
Also used : ListCell(org.adempiere.webui.component.ListCell) MQuery(org.compiere.model.MQuery) ListItem(org.adempiere.webui.component.ListItem) GridField(org.compiere.model.GridField) Listbox(org.adempiere.webui.component.Listbox)

Aggregations

MQuery (org.compiere.model.MQuery)109 PrintInfo (org.compiere.model.PrintInfo)19 GridField (org.compiere.model.GridField)15 MPrintFormat (org.compiere.print.MPrintFormat)14 ReportEngine (org.compiere.print.ReportEngine)12 Point (java.awt.Point)11 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)9 GridWindowVO (org.compiere.model.GridWindowVO)9 SQLException (java.sql.SQLException)8 GridTab (org.compiere.model.GridTab)8 GridWindow (org.compiere.model.GridWindow)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 AWindow (org.compiere.apps.AWindow)6 File (java.io.File)5 IOException (java.io.IOException)5 Language (org.compiere.util.Language)4 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MLookup (org.compiere.model.MLookup)3