Search in sources :

Example 66 with KeyNamePair

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

the class LoginDynUpdate method doPost.

//  doPost
/**
	 *  Process the HTTP Post request
	 *  @param request
	 *  @param response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //  Get Session Info
    MobileSessionCtx wsc = MobileSessionCtx.get(request);
    WWindowStatus ws = WWindowStatus.get(request);
    if (//  ws can be null for Login
    wsc == null || ws == null)
        ;
    String role = request.getParameter("AD_Role_ID");
    int roleId;
    try {
        roleId = Integer.parseInt(role);
    } catch (Exception e) {
        roleId = -1;
    }
    String client = request.getParameter("AD_Client_ID");
    int clientId;
    try {
        clientId = Integer.parseInt(client);
    } catch (Exception e) {
        clientId = -1;
    }
    Login login = new Login(wsc.ctx);
    StringBuffer script = new StringBuffer("{");
    boolean hasClients = false;
    if (roleId >= 0) {
        //  Get Data
        KeyNamePair[] clients = login.getClients(new KeyNamePair(roleId, role));
        //  Set Client ----
        script.append("\"clients\":[");
        for (int i = 0; i < clients.length; i++) {
            if (i > 0)
                script.append(",");
            KeyNamePair p = clients[i];
            script.append("{\"text\":\"");
            //  text
            script.append(p.getName());
            script.append("\",\"value\":\"");
            //  value
            script.append(p.getKey());
            script.append("\"}");
        }
        script.append("]");
        if (clientId < 0 && clients.length > 0) {
            clientId = clients[0].getKey();
        }
    }
    if (clientId >= 0) {
        script.append(",\"orgs\":[");
        KeyNamePair[] orgs = login.getOrgs(new KeyNamePair(clientId, client));
        for (int i = 0; i < orgs.length; i++) {
            if (i > 0)
                script.append(",");
            KeyNamePair p = orgs[i];
            script.append("{\"text\":\"");
            //  text
            script.append(p.getName());
            script.append("\",\"value\":\"");
            //  value
            script.append(p.getKey());
            script.append("\"}");
        }
        script.append("]");
    }
    script.append("}");
    //  print document
    //  with character encoding support
    PrintWriter out = response.getWriter();
    out.print(script);
    out.flush();
    if (out.checkError())
        log.log(Level.SEVERE, "error writing");
    //  binary output (is faster but does not do character set conversion)
    //	OutputStream out = response.getOutputStream();
    //	byte[] data = doc.toString().getBytes();
    //	response.setContentLength(data.length);
    //	out.write(doc.toString().getBytes());
    //
    out.close();
}
Also used : Login(org.compiere.util.Login) KeyNamePair(org.compiere.util.KeyNamePair) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 67 with KeyNamePair

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

the class InfoSchedule method displayCalendar.

//	fillResource
/**
	 * 	Display Calendar for selected Resource, Time(day/week/month) and Date
	 */
private void displayCalendar() {
    //	Get Values
    ListItem listItem = fieldResource.getSelectedItem();
    if (listItem == null)
        return;
    KeyNamePair pp = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
    int S_Resource_ID = pp.getKey();
    m_mAssignment.setS_Resource_ID(S_Resource_ID);
    // Elaine 2008/12/12
    Date date = fieldDate.getValue();
    if (date == null)
        date = new Timestamp(System.currentTimeMillis());
    //		Date date = m_dateFrom;
    //
    //	Set Info
    m_loading = true;
    schedulePane.recreate(S_Resource_ID, date);
    m_loading = false;
    invalidate();
}
Also used : ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 68 with KeyNamePair

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

the class InfoSchedule method fillResourceType.

//	dynInit
/**
	 * 	Fill Resource Type (one time)
	 */
private void fillResourceType() {
    //	Get ResourceType of selected Resource
    int S_ResourceType_ID = 0;
    if (m_mAssignment.getS_Resource_ID() != 0) {
        String sql = "SELECT S_ResourceType_ID FROM S_Resource WHERE S_Resource_ID=?";
        try {
            PreparedStatement pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, m_mAssignment.getS_Resource_ID());
            ResultSet rs = pstmt.executeQuery();
            if (rs.next())
                S_ResourceType_ID = rs.getInt(1);
            rs.close();
            pstmt.close();
        } catch (SQLException e) {
            log.log(Level.SEVERE, sql, e);
        }
    }
    //	Get Resource Types
    String sql = MRole.getDefault().addAccessSQL("SELECT S_ResourceType_ID, Name FROM S_ResourceType WHERE IsActive='Y' ORDER BY 2", "S_ResourceType", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
    KeyNamePair defaultValue = null;
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
            if (S_ResourceType_ID == pp.getKey())
                defaultValue = pp;
            fieldResourceType.appendItem(pp.getName(), pp.getKey());
        }
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    if (defaultValue != null) {
        int cnt = fieldResourceType.getItemCount();
        for (int i = 0; i < cnt; i++) {
            ListItem li = fieldResourceType.getItemAtIndex(i);
            Integer key = (Integer) li.getValue();
            if (key.intValue() == defaultValue.getKey()) {
                fieldResourceType.setSelectedItem(li);
                break;
            }
        }
    } else if (fieldResourceType.getItemCount() > 0) {
        fieldResourceType.setSelectedIndex(0);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) KeyNamePair(org.compiere.util.KeyNamePair) ListItem(org.adempiere.webui.component.ListItem)

Example 69 with KeyNamePair

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

the class InfoSchedule method doAdd.

//	adjustDate
//
private void doAdd() {
    ListItem listItem = fieldResource.getSelectedItem();
    if (listItem == null)
        return;
    //	Get Resource Type
    KeyNamePair pp = new KeyNamePair((Integer) listItem.getValue(), listItem.getLabel());
    int S_Resource_ID = pp.getKey();
    ScheduleUtil schedule = new ScheduleUtil(Env.getCtx());
    Timestamp start = m_dateFrom;
    java.sql.Date startDate = new java.sql.Date(start.getTime());
    Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(startDate.getTime());
    start = new Timestamp(startDate.getTime());
    start = new Timestamp(cal.getTimeInMillis());
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    start = new Timestamp(cal.getTimeInMillis());
    cal.add(Calendar.DAY_OF_MONTH, 1);
    Timestamp end = new Timestamp(cal.getTimeInMillis());
    MAssignmentSlot[] mas = schedule.getAssignmentSlots(S_Resource_ID, start, end, null, true, null);
    MAssignmentSlot[] mts = schedule.getDayTimeSlots();
    MAssignmentSlot slot = null;
    for (int i = 0; i < mts.length; i++) {
        slot = mts[i];
        for (int j = 0; j < mas.length; j++) {
            if (mts[i].getStartTime().getTime() == mas[j].getStartTime().getTime()) {
                slot = null;
                break;
            }
            if (mas[j].getEndTime() != null) {
                if (mts[i].getStartTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getStartTime().getTime() < mas[j].getEndTime().getTime()) {
                    slot = null;
                    break;
                } else if (mts[i].getEndTime().getTime() > mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() < mas[j].getEndTime().getTime()) {
                    slot = null;
                    break;
                } else if (mts[i].getStartTime().getTime() < mas[j].getStartTime().getTime() && mts[i].getEndTime().getTime() >= mas[j].getEndTime().getTime()) {
                    slot = null;
                    break;
                }
            }
        }
        if (slot != null)
            break;
    }
    if (slot != null) {
        MResourceAssignment ma;
        if (m_mAssignment == null)
            ma = new MResourceAssignment(Env.getCtx(), 0, null);
        else
            ma = m_mAssignment;
        ma.setS_Resource_ID(S_Resource_ID);
        ma.setAssignDateFrom(TimeUtil.getDayTime(start, slot.getStartTime()));
        ma.setQty(new BigDecimal(1));
        WAssignmentDialog vad = new WAssignmentDialog(ma, false, m_createNew);
        mAssignmentCallback(vad.getMResourceAssignment());
    } else {
        FDialog.error(0, this, "No available time slot for the selected day.");
    }
}
Also used : MResourceAssignment(org.compiere.model.MResourceAssignment) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ScheduleUtil(org.compiere.model.ScheduleUtil) GregorianCalendar(java.util.GregorianCalendar) Timestamp(java.sql.Timestamp) Date(java.util.Date) BigDecimal(java.math.BigDecimal) MAssignmentSlot(org.compiere.model.MAssignmentSlot) ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair)

Example 70 with KeyNamePair

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

the class AcctViewer method actionQuery.

//	sortAddItem
/**
	 *  Query
	 */
private void actionQuery() {
    //  Parameter Info
    StringBuffer para = new StringBuffer();
    //  Reset Selection Data
    m_data.C_AcctSchema_ID = 0;
    m_data.AD_Org_ID = 0;
    //  Save Selection Choices
    KeyNamePair kp = (KeyNamePair) selAcctSchema.getSelectedItem();
    if (kp != null)
        m_data.C_AcctSchema_ID = kp.getKey();
    para.append("C_AcctSchema_ID=").append(m_data.C_AcctSchema_ID);
    //
    ValueNamePair vp = (ValueNamePair) selPostingType.getSelectedItem();
    m_data.PostingType = vp.getValue();
    para.append(", PostingType=").append(m_data.PostingType);
    //  Document
    m_data.documentQuery = selDocument.isSelected();
    para.append(", DocumentQuery=").append(m_data.documentQuery);
    if (selDocument.isSelected()) {
        if (m_data.AD_Table_ID == 0 || m_data.Record_ID == 0)
            return;
        para.append(", AD_Table_ID=").append(m_data.AD_Table_ID).append(", Record_ID=").append(m_data.Record_ID);
    } else {
        m_data.DateFrom = (Timestamp) selDateFrom.getValue();
        para.append(", DateFrom=").append(m_data.DateFrom);
        m_data.DateTo = (Timestamp) selDateTo.getValue();
        para.append(", DateTo=").append(m_data.DateTo);
        kp = (KeyNamePair) selOrg.getSelectedItem();
        if (kp != null)
            m_data.AD_Org_ID = kp.getKey();
        para.append(", AD_Org_ID=").append(m_data.AD_Org_ID);
        //
        Iterator it = m_data.whereInfo.values().iterator();
        while (it.hasNext()) para.append(", ").append(it.next());
    }
    //  Save Display Choices
    m_data.displayQty = displayQty.isSelected();
    para.append(" - Display Qty=").append(m_data.displayQty);
    m_data.displaySourceAmt = displaySourceAmt.isSelected();
    para.append(", Source=").append(m_data.displaySourceAmt);
    m_data.displayDocumentInfo = displayDocumentInfo.isSelected();
    para.append(", Doc=").append(m_data.displayDocumentInfo);
    //
    m_data.sortBy1 = ((ValueNamePair) sortBy1.getSelectedItem()).getValue();
    m_data.group1 = group1.isSelected();
    para.append(" - Sorting: ").append(m_data.sortBy1).append("/").append(m_data.group1);
    m_data.sortBy2 = ((ValueNamePair) sortBy2.getSelectedItem()).getValue();
    m_data.group2 = group2.isSelected();
    para.append(", ").append(m_data.sortBy2).append("/").append(m_data.group2);
    m_data.sortBy3 = ((ValueNamePair) sortBy3.getSelectedItem()).getValue();
    m_data.group3 = group3.isSelected();
    para.append(", ").append(m_data.sortBy3).append("/").append(m_data.group3);
    m_data.sortBy4 = ((ValueNamePair) sortBy4.getSelectedItem()).getValue();
    m_data.group4 = group4.isSelected();
    para.append(", ").append(m_data.sortBy4).append("/").append(m_data.group4);
    bQuery.setEnabled(false);
    statusLine.setText(" " + Msg.getMsg(Env.getCtx(), "Processing"));
    log.config(para.toString());
    Thread.yield();
    //  Switch to Result pane
    tabbedPane.setSelectedIndex(1);
    //  Set TableModel with Query
    table.setModel(m_data.query());
    bQuery.setEnabled(true);
    statusLine.setText(" " + Msg.getMsg(Env.getCtx(), "ViewerOptions"));
}
Also used : Iterator(java.util.Iterator) KeyNamePair(org.compiere.util.KeyNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

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