Example usage for com.mongodb DBCollection update

List of usage examples for com.mongodb DBCollection update

Introduction

In this page you can find the example usage for com.mongodb DBCollection update.

Prototype

public WriteResult update(final DBObject query, final DBObject update) 

Source Link

Document

Modify an existing document.

Usage

From source file:org.restlet.example.ext.oauth.server.MongoAuthenticatedUser.java

License:LGPL

@Override
public void setPassword(char[] password) {
    DBCollection users = OAuth2Sample.getDefaultDB().getCollection("users");
    users.update(new BasicDBObject("_id", getId()),
            new BasicDBObject("$set", new BasicDBObject("password", new String(password))));
}

From source file:org.springframework.data.document.mongodb.MongoTemplate.java

License:Apache License

protected WriteResult doUpdate(final String collectionName, final Query query, final Update update,
        final Class<?> entityClass, final boolean upsert, final boolean multi) {

    return execute(collectionName, new CollectionCallback<WriteResult>() {
        public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException {
            DBObject queryObj = query.getQueryObject();
            DBObject updateObj = update.getUpdateObject();

            String idProperty = "id";
            if (null != entityClass) {
                idProperty = getPersistentEntity(entityClass).getIdProperty().getName();
            }/*from   ww  w.  j  a v a2 s .  c o  m*/
            for (String key : queryObj.keySet()) {
                if (idProperty.equals(key)) {
                    // This is an ID field
                    queryObj.put(ID, mongoConverter.maybeConvertObject(queryObj.get(key)));
                    queryObj.removeField(key);
                } else {
                    queryObj.put(key, mongoConverter.maybeConvertObject(queryObj.get(key)));
                }
            }

            for (String key : updateObj.keySet()) {
                updateObj.put(key, mongoConverter.maybeConvertObject(updateObj.get(key)));
            }

            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("calling update using query: " + queryObj + " and update: " + updateObj
                        + " in collection: " + collectionName);
            }

            WriteResult wr;
            if (writeConcern == null) {
                if (multi) {
                    wr = collection.updateMulti(queryObj, updateObj);
                } else {
                    wr = collection.update(queryObj, updateObj);
                }
            } else {
                wr = collection.update(queryObj, updateObj, upsert, multi, writeConcern);
            }
            handleAnyWriteResultErrors(wr, queryObj, "update with '" + updateObj + "'");
            return wr;
        }
    });

}

From source file:org.unitedid.shibboleth.attribute.resolver.provider.dataConnector.MongoDbDataConnector.java

License:Apache License

/**
 * Derived from shibboleth storedId, Copyright [2007] [University Corporation for Advanced Internet Development, Inc.].
 *
 * Gets the currently active identifier for a (principal, peer, local) tuple.
 *
 * @param resolutionContext current resolution context
 * @return persistent ID//from   w  w w  . j  a v a  2 s .c o m
 * @throws AttributeResolutionException if an error occurs when saving object to the database
 */
private String getPersistentId(ShibbolethResolutionContext resolutionContext)
        throws AttributeResolutionException {
    SAMLProfileRequestContext requestContext = resolutionContext.getAttributeRequestContext();
    ArrayList<PersistentIdEntry> entries = new ArrayList<PersistentIdEntry>();
    String localId = getLocalId(resolutionContext);

    try {
        DBCollection collection = db.getCollection(mongoCollection);
        BasicDBObject query = new BasicDBObject();
        query.put("localEntity", requestContext.getLocalEntityId());
        query.put("peerEntity", requestContext.getInboundMessageIssuer());
        query.put("localId", localId);
        query.put("deactivationTime", new BasicDBObject("$exists", false));

        log.debug("Data connector {} trying to fetch persistentId for principal: {}", getId(), localId);

        DBCursor result = collection.find(query);

        PersistentIdEntry entry;
        while (result.hasNext()) {
            DBObject r = result.next();
            entry = new PersistentIdEntry();
            entry.setLocalEntityId((String) r.get("localEntity"));
            entry.setPeerEntityId((String) r.get("peerEntity"));
            entry.setPrincipalName((String) r.get("principalName"));
            entry.setPersistentId((String) r.get("persistentId"));
            entry.setLocalId((String) r.get("localId"));
            entry.setCreationTime((Date) r.get("creationTime"));
            entry.setDeactivationTime((Date) r.get("deactivationTime"));
            entry.setLastVisitTime(new Date());

            // Update last visit time
            BasicDBObject updateQuery = new BasicDBObject("$set",
                    new BasicDBObject("lastVisitTime", entry.getLastVisitTime()));
            collection.update(r, updateQuery);

            entries.add(entry);
        }

        if (entries == null || entries.size() == 0) {
            log.debug("Data connector {} did not find a persistentId for principal: {}, generating a new one.",
                    getId(), localId);
            entry = createPersistentId(resolutionContext, localId);
            savePersistentId(entry);
            entries.add(entry);
        }
    } catch (MongoException e) {
        log.error("MongoDB query failed", e);
    }

    return entries.get(0).getPersistentId();
}

From source file:org.zeus.HealthEnhancements.ProviderInfo.java

public boolean UpdateProviderProfile() throws RuntimeException {
    HashMap<String, ProviderInfo> mpProviders = GetAllProviders();

    if (!mpProviders.containsKey(m_szUserName))
        throw new RuntimeException("{\"error\":\"Username does not exist in the system\"}");

    if (mpProviders.containsKey(m_szUserName)) {
        ProviderInfo provider = mpProviders.get(m_szUserName);

        if (!provider.m_szHashUserPassword.equals(m_szHashUserPassword))
            throw new RuntimeException("{\"error\":\"Invalid Password\"}");

        if (!provider.m_id.equals(m_id))
            throw new RuntimeException("{\"error\":\"Invalid identifier in field m_id\"}");
    }//from w w w .j a v  a  2 s  . c  o  m

    DBCollection collection = Bootstrap.getEHRdbHandle().getCollection("ProviderInfo");

    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szProviderType", m_szProviderType)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szFirstName", m_szFirstName)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szLastName", m_szLastName)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szMiddleName", m_szMiddleName)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szSocialSecurity", m_szSocialSecurity)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szLicenseNumber", m_szLicenseNumber)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szPersonnelType", m_szPersonnelType)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szSpecialization", m_szSpecialization)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szAffiliation", m_szAffiliation)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szAddress", m_szAddress)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szPhoneNumber", m_szPhoneNumber)));
    collection.update(new BasicDBObject("_id", new ObjectId(m_id)),
            new BasicDBObject("$set", new BasicDBObject("m_szEmail", m_szEmail)));

    return true;
}

From source file:payroll.FrmEdit.java

private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
    // TODO add your handling code here:
    int i = 0;//from   w ww  .j a v a2  s. c o m
    String nu = "";

    if (txtFname.getText().equals(nu)) {
        JOptionPane.showMessageDialog(null, "First name cannot remain empty", "FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (txtLname.getText().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Last name cannot remain empty", "FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (txtEmail.getText().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Email cannot remain empty", "FAILED", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (txtareaAddress.getText().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Address cannot remain empty", "FAILED", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (txtMobno.getText().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Mobile number cannot remain empty", "FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (txtMobno.getText().length() != 10) {
        JOptionPane.showMessageDialog(null, "Enter valid mobile number", "FAILED", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (cmbDesig.getSelectedItem().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Select a gender", "FAILED", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (cmbQual.getSelectedItem().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Select your qualification", "FAILED", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (dtDOB.getDate().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Date of birth cannot remain empty", "FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (dtDOJ.getDate().equals(nu)) {
        JOptionPane.showMessageDialog(null, "Date of joining cannot remain empty", "FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;
    }
    try {
        Connect1 k = new Connect1();
        DBCollection dbc2 = k.connect("Emp_Records");
        BasicDBObject bdb2 = new BasicDBObject();
        bdb2.put("ID", FrmAdmin.Id);
        DBCursor cur = dbc2.find(bdb2);
        DBObject obj1 = cur.next();

        java.util.Date d1 = dtDOB.getDate();
        java.util.Date d2 = dtDOJ.getDate();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date = sdf.format(dtDOB.getDate());
        String gender = null;
        ButtonGroup group = new ButtonGroup();

        if (rdbMale.isSelected()) {
            gender = rdbMale.getText();

        } else {
            gender = rdbFemale.getText();

        }
        final JPanel p2 = new JPanel();
        final JOptionPane jo = new JOptionPane();

        Connect1 j = new Connect1();
        DBCollection dbc = j.connect("Emp_Records");
        DBCursor cursor = dbc.find();
        while (cursor.hasNext() == true) {
            DBObject obj = cursor.next();
            i++;
        }

        String ID = FrmAdmin.Id;

        String emailID = txtEmail.getText();
        String emailRE = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";

        Boolean flag = emailID.matches(emailRE);
        BasicDBObject bdb = new BasicDBObject();
        bdb.put("ID", ID);

        bdb.put("First Name", txtFname.getText());
        bdb.put("Last Name", txtLname.getText());
        if (flag != null)
            bdb.put("Email", txtEmail.getText());
        else {
            JOptionPane.showMessageDialog(p2, "Invalid Email Id", "Enter a valid email address",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        bdb.put("Address", txtareaAddress.getText());
        bdb.put("Mobile Number", txtMobno.getText());
        bdb.put("Qualification", cmbQual.getSelectedItem());
        bdb.put("Designation", cmbDesig.getSelectedItem());
        Calendar c = new GregorianCalendar();
        int year = c.get(Calendar.YEAR);
        if (year - d1.getYear() > 60) {
            JOptionPane.showMessageDialog(p2, "Only employees between 21 to 60 years can work ", "failure",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        if (year - d1.getYear() < 20) {
            JOptionPane.showMessageDialog(p2, "Only employees between 21 to 60 years can work ", "failure",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        bdb.put("DOB", d1);
        bdb.put("Gender", gender);
        bdb.put("DOJ", d2);
        dbc.update(obj1, bdb);

        JOptionPane.showMessageDialog(p2, "Successfully Updated", "Success", JOptionPane.INFORMATION_MESSAGE);
        clear();
        this.setVisible(false);

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "ONE OR MORE FIELDS ARE EMPTY", "FAILURE",
                JOptionPane.ERROR_MESSAGE);
    }

}

From source file:payroll.FrmLeave.java

private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed
    // TODO add your handling code here:
    Connect1 j = new Connect1();
    DBCollection dbc = j.connect("leave");
    BasicDBObject bdb = new BasicDBObject();
    Date d1 = dtFrom.getDate();/*from ww w.  j  av a  2  s.co m*/
    Date d2 = dtTo.getDate();
    Calendar calendar = new GregorianCalendar();
    if ((d1.getDate() > d2.getDate()) && (d1.getMonth()) == d2.getMonth()) {
        JOptionPane.showMessageDialog(null, "Invalid order of dates", "FAILURE", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (d1.getDate() < calendar.get(Calendar.DATE) && d1.getMonth() == calendar.get(Calendar.DATE)) {
        JOptionPane.showMessageDialog(null, "Only future leaves can be taken", "FAILURE",
                JOptionPane.ERROR_MESSAGE);
        System.out.println("1");
        return;

    }
    if (d1.getMonth() > d2.getMonth()) {
        JOptionPane.showMessageDialog(null, "Invalid order of dates", "FAILURE", JOptionPane.ERROR_MESSAGE);
        System.out.println("2");
        return;

    }
    int end = 0;

    int from = d1.getDate();
    int to = d2.getDate();
    int from_month = d1.getMonth();
    int to_month = d2.getMonth();
    if (from_month != to_month) {
        switch (from_month) {
        case 0:
            end = 31;
            break;
        case 1:
            end = 28;
            break;
        case 2:
            end = 31;
            break;
        case 3:
            end = 30;
            break;
        case 4:
            end = 31;
            break;
        case 5:
            end = 30;
            break;
        case 6:
            end = 31;
            break;
        case 7:
            end = 31;
            break;
        case 8:
            end = 30;
            break;
        case 9:
            end = 31;
            break;
        case 10:
            end = 30;
            break;
        case 11:
            end = 31;
            break;

        }
        String type = "";
        if (rdbCleave.isSelected()) {
            type = "Casual Leave";

        } else {
            type = "Sick Leave";

        }
        bdb.put("ID", lblEmpid.getText());
        bdb.put("From", d1.getDate());
        bdb.put("To", end);
        bdb.put("Month", d1.getMonth());
        bdb.put("Type", type);

        BasicDBObject bdb3 = new BasicDBObject();
        bdb3.put("ID", lblEmpid.getText());
        bdb3.put("From", 1);
        bdb3.put("To", d2.getDate());
        bdb3.put("Month", d2.getMonth());
        bdb3.put("Type", type);

        DBCollection dbc1 = j.connect("remaining_leaves");
        BasicDBObject bdb1 = new BasicDBObject();
        bdb1.put("ID", lblEmpid.getText());
        DBCursor cur = dbc1.find(bdb1);
        DBObject obj = cur.next();
        int rcleaves = (Integer) obj.get("Casual_leaves");
        int rsleaves = (Integer) obj.get("Sick_leaves");

        if (type.equals("Casual Leave")) {
            if (rcleaves >= end - d1.getDate()) {
                bdb.put("Paid_Casual", end - d1.getDate() + 1);
                bdb.put("Paid_Sick", 0);
                rcleaves -= end - d1.getDate();
            } else {
                bdb.put("Paid_Casual", rcleaves + 1);
                bdb.put("Paid_Sick", 0);
                rcleaves = 0;
            }

        } else {
            if (rsleaves >= end - d1.getDate()) {
                bdb.put("Paid_Sick", end - d1.getDate() + 1);
                bdb.put("Paid_Casual", 0);
                rsleaves -= end - d1.getDate();
            } else {
                bdb.put("Paid_Sick", rsleaves + 1);
                bdb.put("Paid_Casual", 0);
                rsleaves = 0;
            }

        }
        if (type.equals("Casual Leave")) {
            if (rcleaves >= d2.getDate() - 1) {
                bdb3.put("Paid_Casual", d2.getDate() - 1 + 1);
                bdb3.put("Paid_Sick", 0);
                rcleaves -= d2.getDate() - 1;
            } else {
                bdb3.put("Paid_Casual", rcleaves + 1);
                bdb3.put("Paid_Sick", 0);
                rcleaves = 0;
            }

        } else {
            if (rsleaves >= d2.getDate() - 1) {
                bdb3.put("Paid_Sick", d2.getDate() - 1 + 1);
                bdb3.put("Paid_Casual", 0);
                rsleaves -= d2.getDate() - 1;
            } else {
                bdb3.put("Paid_Sick", rsleaves + 1);
                bdb3.put("Paid_Casual", 0);
                rsleaves = 0;
            }

        }
        dbc.insert(bdb);
        dbc.insert(bdb3);
        bdb1.put("Casual_leaves", rcleaves);
        bdb1.put("Sick_leaves", rsleaves);
        dbc1.update(obj, bdb1);

        final JPanel p2 = new JPanel();
        final JOptionPane jo = new JOptionPane();
        JOptionPane.showMessageDialog(p2, "Leave Taken", "Success", JOptionPane.INFORMATION_MESSAGE);
        this.setVisible(false);

    }
    BasicDBObject bdb2 = new BasicDBObject();
    bdb2.put("Month", from_month);
    bdb2.put("ID", lblEmpid.getText());
    DBCursor cur1 = dbc.find(bdb2);
    while (cur1.hasNext()) {
        DBObject obj = cur1.next();
        int from1 = (Integer) obj.get("From");
        int to1 = (Integer) obj.get("To");
        if (from >= from1 && from <= to1) {
            JOptionPane.showMessageDialog(null, "You have already taken leave in this period", "Failure",
                    JOptionPane.ERROR_MESSAGE);
            return;
        } else if (to >= from1 && to <= to1) {
            JOptionPane.showMessageDialog(null, "You have already taken leave in this period", "Failure",
                    JOptionPane.ERROR_MESSAGE);
            return;
        } else if (from <= from1 && to >= to1) {
            JOptionPane.showMessageDialog(null, "You have already taken leave in this period", "Failure",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    String type = "";
    if (rdbCleave.isSelected()) {
        type = "Casual Leave";

    } else {
        type = "Sick Leave";

    }
    bdb.put("ID", lblEmpid.getText());
    bdb.put("From", d1.getDate());
    bdb.put("To", d2.getDate());
    bdb.put("Month", d1.getMonth());

    bdb.put("Type", type);

    DBCollection dbc1 = j.connect("remaining_leaves");
    BasicDBObject bdb1 = new BasicDBObject();
    bdb1.put("ID", lblEmpid.getText());
    DBCursor cur = dbc1.find(bdb1);
    DBObject obj = cur.next();
    int rcleaves = (Integer) obj.get("Casual_leaves");
    int rsleaves = (Integer) obj.get("Sick_leaves");

    if (type.equals("Casual Leave")) {
        if (rcleaves >= d2.getDate() - d1.getDate()) {
            bdb.put("Paid_Casual", d2.getDate() - d1.getDate());
            bdb.put("Paid_Sick", 0);
            rcleaves -= d2.getDate() - d1.getDate();
        } else {
            bdb.put("Paid_Casual", rcleaves);
            bdb.put("Paid_Sick", 0);
            rcleaves = 0;
        }

    } else {
        if (rsleaves >= d2.getDate() - d1.getDate()) {
            bdb.put("Paid_Sick", d2.getDate() - d1.getDate());
            bdb.put("Paid_Casual", 0);
            rsleaves -= d2.getDate() - d1.getDate();
        } else {
            bdb.put("Paid_Sick", rsleaves);
            bdb.put("Paid_Casual", 0);
            rsleaves = 0;
        }

    }
    dbc.insert(bdb);
    bdb1.put("Casual_leaves", rcleaves);
    bdb1.put("Sick_leaves", rsleaves);
    dbc1.update(obj, bdb1);

    final JPanel p2 = new JPanel();
    final JOptionPane jo = new JOptionPane();
    JOptionPane.showMessageDialog(p2, "Leave Taken", "Success", JOptionPane.INFORMATION_MESSAGE);
    this.setVisible(false);
}

From source file:payroll.FrmLogin.java

private void btnTimeoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTimeoutActionPerformed
    // TODO add your handling code here:
    String username = "";
    String password = "";

    Connect1 j = new Connect1();
    DBCollection dbc = j.connect("Passwords");

    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("Employee Id", txtUname.getText());

    DBCursor cursor = dbc.find(searchQuery);
    if (cursor.hasNext() == false) {
        JOptionPane.showMessageDialog(null, "Employee id not found", "TIME OUT FAILED",
                JOptionPane.ERROR_MESSAGE);
        return;// w ww  . j a va2s.  c om
    }
    DBObject obj = cursor.next();

    password = (String) obj.get("Password");
    username = (String) obj.get("Employee Id");

    if (password.equals(txtPwd.getText()) && username.equals(txtUname.getText())) {

        Connect1 k = new Connect1();

        DBCollection dbc1 = k.connect("Attendance");

        Calendar cal = new GregorianCalendar();
        int date = cal.get(Calendar.DATE);

        int month = cal.get(Calendar.MONTH);
        int year = cal.get(Calendar.YEAR);
        BasicDBObject bdb3 = new BasicDBObject();
        bdb3.put("Employee ID", txtUname.getText());
        bdb3.put("Date", date);
        bdb3.put("Month", month);
        DBCursor cur2 = dbc1.find(bdb3);
        if (cur2.hasNext()) {
            DBObject obj3 = cur2.next();
            if ((Integer) obj3.get("Logout Hour") != -1) {
                JOptionPane.showMessageDialog(null, "You have already timed out today", "TIME OUT FAILED",
                        JOptionPane.ERROR_MESSAGE);

                txtPwd.setText("");
                txtUname.setText("");
                return;
            }
        } else {
            JOptionPane.showMessageDialog(null, "YOU HAVE NOT TIMED IN YET", "LOGOUT FAILED",
                    JOptionPane.ERROR_MESSAGE);
            txtUname.setText("");
            txtPwd.setText("");
            return;
        }

        String dat = date + ":" + month + ":" + year;

        BasicDBObject search1 = new BasicDBObject();
        search1.put("Date", date);
        search1.put("Month", month);
        search1.put("Employee ID", txtUname.getText());
        DBCursor cur = dbc1.find(search1);

        DBObject bdb2 = cur.next();

        System.out.println(bdb2);

        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int mins = cal.get(Calendar.MINUTE);

        BasicDBObject bdb1 = new BasicDBObject();

        //   System.out.println(bdb2);
        bdb1.put("Date", date);
        bdb1.put("Month", month);

        int login_hour = (int) bdb2.get("Login Hour");

        int login_mins = (int) bdb2.get("Login Minute");

        bdb1.put("Employee ID", txtUname.getText());
        bdb1.put("Login Hour", login_hour);
        bdb1.put("Login Minute", login_mins);
        bdb1.put("Logout Hour", hour);
        bdb1.put("Logout Minute", mins);
        int workhours = 0;
        int workmins = 0;
        System.out.println(mins - login_mins);
        if (mins - login_mins >= 0) {
            workhours = hour - login_hour;
            workmins = mins - login_mins;
        } else {
            workhours = hour - login_hour - 1;
            workmins = mins - login_mins + 60;
        }
        if (workmins > 45)
            workhours++;
        if (workhours < 8)
            bdb1.put("Normal time", workhours);
        else
            bdb1.put("Normal time", 8);
        if (workhours - 8 > 0)
            bdb1.put("Overtime time", 8 - workhours);
        else
            bdb1.put("Overtime time", 0);

        dbc1.update(bdb2, bdb1);
        JOptionPane.showMessageDialog(null, "THANK YOU", "TIMEOUT SUCCESSFUL", JOptionPane.INFORMATION_MESSAGE);
        txtUname.setText("");
        txtPwd.setText("");
    }

    else {
        JOptionPane.showMessageDialog(null, "WRONG USERNAME OR PASSWORD", "LOGOUT FAILED",
                JOptionPane.ERROR_MESSAGE);
        txtUname.setText("");
        txtPwd.setText("");

    }

}

From source file:payroll.FrmRate.java

private void btnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUpdateActionPerformed
    // TODO add your handling code here:
    Connect1 j = new Connect1();
    DBCollection dbc = j.connect("Rates");
    BasicDBObject search = new BasicDBObject();
    search.put("Designation", txtDesig.getText());
    DefaultTableModel model = (DefaultTableModel) tblRates.getModel();
    DBCursor cursor = dbc.find(search);/* w ww .  ja  va 2  s. c o  m*/
    DBObject obj = cursor.next();
    final JPanel p2 = new JPanel();
    final JOptionPane jo = new JOptionPane();

    if (cursor.hasNext()) {
        BasicDBObject bdb = new BasicDBObject();
        bdb.put("Designation", txtDesig.getText());
        int nrate = Integer.parseInt(txtNrate.getText());
        bdb.put("Normal Rate", nrate);
        int orate = Integer.parseInt(txtOrate.getText());
        bdb.put("Overtime Rate", orate);
        dbc.update(obj, bdb);

        JOptionPane.showMessageDialog(p2, "Designation details updated Successfully", "Success",
                JOptionPane.INFORMATION_MESSAGE);

    } else {
        JOptionPane.showMessageDialog(p2, "Designation not found", "Failed", JOptionPane.INFORMATION_MESSAGE);

    }
}

From source file:Pennyworth.Frame2.java

private void btnPayNowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPayNowActionPerformed

    try {//from  w  ww  . j  ava  2 s  .  c o m

        new ProgressBarDelay("Transaction Completed");

        MongoClient mongoClient = new MongoClient("localhost", 27017); // CREATING THE MONGO CLIENT OBJECT
        DB db = mongoClient.getDB("PENNYWORTH"); // Object to access the database

        DBCollection coll_bank = db.getCollection("PENNYWORTH_BANKS");
        DBCollection coll = db.getCollection("PENNYWORTH_USERS");

        System.out.println("Avilable balance is ---->" + pay_electricity.AvailableBalance);

        System.out.println("Consumer No is ---->" + pay_electricity.ConsumerNo);

        // UPDATING THE AVAILABLE BALANCE AMOUNTT             

        BasicDBObject newDocument = new BasicDBObject();
        newDocument.append("$set",
                new BasicDBObject().append("AvailableBalance", pay_electricity.AvailableBalance));
        BasicDBObject searchQuery = new BasicDBObject().append("AccountNo", OPERATIONS.Acc);
        coll_bank.update(searchQuery, newDocument);

        // UPDATING THE AMOUNT OF THE BILL AMOUNT TO 0

        BasicDBObject newDocument_ElectricityBill = new BasicDBObject();
        newDocument.append("$set", new BasicDBObject().append("TotalCharges", 0));
        BasicDBObject searchQuery_Consumer = new BasicDBObject().append("ConsumerNo",
                pay_electricity.ConsumerNo);
        coll_bank.update(searchQuery_Consumer, newDocument_ElectricityBill);

        // ADDING TRANSACTION DETAILS TO THE BACKEND

        DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
        Date dateobj = new Date();

        DBObject curUser = new BasicDBObject("UserName", Mint_login.login_username);

        DBObject listItem = new BasicDBObject("Transactions",
                new BasicDBObject("TransactionNo", pay_electricity.TransactionNo)
                        .append("DateofTransaction", dateobj)
                        .append("TransactionDescription", "Paid for Electricity Bill Month : October")
                        .append("TransactionCategory", "Electricity Bill")
                        .append("TransactionAmount", pay_electricity.BillAmount));
        DBObject updateQuery = new BasicDBObject("$push", listItem);
        coll.update(curUser, updateQuery);

        OPERATIONS.reterive();
        OPERATIONS.reterivalTransaction();

        // ADDING TRANSACTION DETAILS 

        this.dispose();

    }

    catch (UnknownHostException ex) {
        Logger.getLogger(Mint_login.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:Pennyworth.propertydetails.java

private void btnAddPropertyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPropertyActionPerformed

    ConfirmVal = -1;//from  w  w w  . j a v  a2 s  .  c o  m

    try {
        MongoClient mongoClient = new MongoClient("localhost", 27017); // CREATING THE MONGO CLIENT OBJECT
        DB db = mongoClient.getDB("PENNYWORTH"); // Object to access the database

        // CHOOSING THE COLLECTION

        DBCollection coll_bank = db.getCollection("PENNYWORTH_BANKS");
        DBCollection coll = db.getCollection("PENNYWORTH_USERS");

        PropertyType = (String) ComboPropertyType.getSelectedItem();

        PropertyDesc = txtProppertyDesc.getText();
        PropertyName = txtPropertyName.getText();
        OriginalPropertyValue = Integer.parseInt(txtOriginalPrice.getText());

        txtCurrentValue.setEditable(false);
        PropertyArea = Integer.parseInt(txtPropertyArea.getText());
        PropertyLocation = (String) ComboPropertyLocation.getSelectedItem();

        DBObject curUser = new BasicDBObject("UserName", Mint_login.login_username);

        // ADDING CONTENT TO A PARTICULAR FIELD 

        DBObject listItem = new BasicDBObject("PropertyDetails",
                new BasicDBObject("PropertyType", PropertyType).append("PropertyName", PropertyName)
                        .append("PropertyDescription", PropertyDesc)
                        .append("PropertyOriginalValue", OriginalPropertyValue)
                        .append("PropertyCurrentValue", CurrentPropertyValue)
                        .append("PropertyArea", PropertyArea).append("PropertyLocation", PropertyLocation));
        DBObject updateQuery = new BasicDBObject("$push", listItem);
        coll.update(curUser, updateQuery);

        //          JOptionPane.showMessageDialog(DateCombo,"Your Property Details Are Added to Your Pennyworth Account");             

        OPERATIONS.reterive();
        this.dispose();

    }

    catch (UnknownHostException ex) {
        Logger.getLogger(Mint_login.class.getName()).log(Level.SEVERE, null, ex);
    }

}