use of org.compiere.model.MQuery in project adempiere by adempiere.
the class ZoomMenuAction method zoom.
private void zoom() {
String tablename = tableName;
int tableid = tableID;
MQuery query = new MQuery();
query.setTableName(tablename);
AWindow window = new AWindow();
if (window.initWindow(tableid, query)) {
AEnv.showCenterScreen(window);
}
window = null;
}
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, WebSessionCtx wsc, WWindowStatus ws) {
// Get Parameter: Command and Tab changes
String p_tab = WebUtil.getParameter(request, P_Tab);
// MR Row Command
String p_row = WebUtil.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 /**
* Position Commands
*/
if (p_cmd.equals("First")) {
ws.curTab.navigate(0);
} else if (p_cmd.equals("Next")) {
// multi row is positioned at last displayed row
ws.curTab.navigateRelative(+1);
} else if (p_cmd.equals("Previous")) {
int rows = ws.curTab.isSingleRow() ? -1 : -2 * MAX_LINES;
ws.curTab.navigateRelative(rows);
} else if (p_cmd.equals("Last")) {
ws.curTab.navigateRelative(LAST_LINE);
} else /**
* Find
*/
if (p_cmd.equals("Test")) {
/** @todo Chat */
} else /**
* Refresh
*/
if (p_cmd.equals("Refresh")) {
ws.curTab.dataRefreshAll();
} else /**
* Attachment
*/
if (p_cmd.equals("Attachment")) {
/** @todo Attachment */
} else /**
* Favorite
*/
if (p_cmd.equals("Favorite")) {
int AD_Window_ID = ws.curTab.getAD_Window_ID();
String sqlNode = "SELECT AD_Menu_ID FROM AD_Menu WHERE" + " AD_Window_ID = " + AD_Window_ID;
int Node_ID = DB.getSQLValue(null, sqlNode);
int AD_User_ID = Env.getAD_User_ID(wsc.ctx);
int AD_Role_ID = Env.getAD_Role_ID(wsc.ctx);
int AD_Org_ID = Env.getAD_Org_ID(wsc.ctx);
int AD_Client_ID = Env.getAD_Client_ID(wsc.ctx);
int AD_Tree_ID = DB.getSQLValue(null, "SELECT COALESCE(r.AD_Tree_Menu_ID, ci.AD_Tree_Menu_ID)" + "FROM AD_ClientInfo ci" + " INNER JOIN AD_Role r ON (ci.AD_Client_ID=r.AD_Client_ID) " + "WHERE AD_Role_ID=?", AD_Role_ID);
if (AD_Tree_ID <= 0)
// Menu
AD_Tree_ID = 10;
String sql = "SELECT count(*) FROM AD_TreeBar WHERE" + " Node_ID = " + Node_ID + " AND CreatedBy = " + AD_User_ID + " AND AD_Tree_ID = " + AD_Tree_ID;
int Favorite = DB.getSQLValue(null, sql);
if (Favorite > 0) {
sql = "DELETE FROM AD_TreeBar WHERE" + " Node_ID = " + Node_ID + " AND CreatedBy = " + AD_User_ID + " AND AD_Tree_ID = " + AD_Tree_ID;
DB.executeUpdate(sql, null);
} else {
sql = "INSERT INTO AD_TreeBar " + "( Node_ID, AD_User_ID, AD_Client_ID, AD_Org_ID," + " IsActive, CreatedBy, AD_Tree_ID, UpdatedBy)" + "VALUES ( " + Node_ID + ", " + AD_User_ID + ", " + AD_Client_ID + ", " + AD_Org_ID + ", 'Y', " + AD_User_ID + ", " + AD_Tree_ID + ", " + AD_User_ID + ")";
DB.executeUpdate(sql, null);
}
} else /**
* History
*/
if (p_cmd.equals("History")) {
//Modified by Rob Klein 4/29/07
//if (ws.mWindow.isTransaction() && ws.curTab.getWindowNo() == 0)
//{
ws.mWindow.initTab(ws.curTab.getTabNo());
ws.curTab.query(!ws.curTab.isOnlyCurrentRows());
ws.curTab.navigate(0);
//}
} else /**
* Report
*/
if (p_cmd.equals("Report")) {
/** @todo Report */
} else /**
* Print
*/
if (p_cmd.equals("Print")) {
/** @todo Print */
} 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 = WebUtil.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")) {
String strSQL = WebUtil.getParameter(request, "txtSQL");
if (strSQL != null) {
MQuery query = new MQuery();
if (strSQL.equals("FIND")) {
String value = WebUtil.getParameter(request, "txtValue");
String docno = WebUtil.getParameter(request, "txtDocumentNo");
String name = WebUtil.getParameter(request, "txtName");
String desc = WebUtil.getParameter(request, "txtDescription");
if (value != null && value.length() != 0)
query.addRestriction("Value", MQuery.LIKE, value);
if (docno != null && docno.length() != 0)
query.addRestriction("DocumentNo", MQuery.LIKE, docno);
if (name != null && name.length() != 0)
query.addRestriction("Name", MQuery.LIKE, name);
if (desc != null && desc.length() != 0)
query.addRestriction("Description", MQuery.LIKE, desc);
} else {
query.addRestriction(strSQL);
}
ws.curTab.setQuery(query);
ws.curTab.query(false);
ws.curTab.navigate(0);
}
}
}
use of org.compiere.model.MQuery in project adempiere by adempiere.
the class DynamicDashBoard method onEvent.
public void onEvent(Event event) throws Exception {
Component comp = event.getTarget();
Row row = (Row) comp;
int recordId = new Integer(row.getId());
MQuery query = new MQuery();
query.setZoomValue(recordId);
query.setZoomTableName(zoomTableName);
query.setZoomColumnName(zoomTableColumnName);
query.setRecordCount(1);
query.addRestriction(zoomTableColumnName, MQuery.EQUAL, new Integer(recordId));
AEnv.zoom(zoomWindowId, query);
}
use of org.compiere.model.MQuery in project adempiere by adempiere.
the class ZoomCommand method service.
public boolean service(AuRequest request, boolean everError) {
if (!ZoomEvent.EVENT_NAME.equals(request.getCommand()))
return false;
Map<?, ?> map = request.getData();
JSONArray data = (JSONArray) map.get("data");
final Component comp = request.getComponent();
if (comp == null)
throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
if (data == null || data.size() < 2)
throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] { Objects.toString(data), this });
String columnName = (String) data.get(0);
String tableName = MQuery.getZoomTableName(columnName);
Object code = null;
if (columnName.endsWith("_ID")) {
try {
code = Integer.parseInt((String) data.get(1));
} catch (Exception e) {
code = data.get(1);
}
} else {
code = data.get(1);
}
//
MQuery query = new MQuery(tableName);
query.addRestriction(columnName, MQuery.EQUAL, code);
query.setRecordCount(1);
Events.postEvent(new ZoomEvent(comp, query));
return true;
}
use of org.compiere.model.MQuery in project adempiere by adempiere.
the class GenericZoomProvider method evaluateQuery.
private static MQuery evaluateQuery(String targetTableName, int AD_Tab_ID, String Name, final PO po) {
MTab tab = new MTab(Env.getCtx(), AD_Tab_ID, null);
final MQuery query = new MQuery();
query.addRestriction(po.get_TableName() + "_ID=" + po.get_ID());
if (tab.getWhereClause() != null && tab.getWhereClause().length() > 0)
query.addRestriction("(" + tab.getWhereClause() + ")");
query.setZoomTableName(targetTableName);
query.setZoomColumnName(po.get_KeyColumns()[0]);
query.setZoomValue(po.get_ID());
String sql = "SELECT COUNT(*) FROM " + targetTableName + " WHERE " + Env.parseVariable(query.getWhereClause(false), po, null, false);
int count = DB.getSQLValue(null, sql);
query.setRecordCount(count);
return query;
}
Aggregations