Пример #1
0
  private void btnSaveActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnSaveActionPerformed
    // TODO add your handling code here:

    if (TxtUn.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(this, "UserName is required");
      TxtUn.grabFocus();

    } else if (new String(TxtPass.getPassword()).trim().equals("")) {
      JOptionPane.showMessageDialog(this, "Password is required");
      TxtPass.grabFocus();
    } else if (TxtName.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(this, "Name is required");
      TxtName.grabFocus();
    } else if (TxtNumber.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(this, "Contact is required");
      TxtNumber.grabFocus();
    } else if (TxtEmail.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(this, "Email is required");
      TxtEmail.grabFocus();
    } else {
      String result = "";
      Loginbean objBean = new Loginbean();
      objBean.setUserID(Integer.parseInt(TxtUserId.getText()));
      objBean.setUserName(TxtUn.getText());
      objBean.setPassword(new String(TxtPass.getPassword()));
      objBean.setName(TxtName.getText());
      objBean.setContact(TxtNumber.getText());
      objBean.setEmail(TxtEmail.getText());
      objBean.setUserType(ddlUserType.getSelectedItem().toString());
      objBean.setUserStatus(ddlUserStatus.getSelectedItem().toString());

      if (addUpdateFlag.equalsIgnoreCase("add")) {
        result = objDB.addUser(objBean);
      } else if (addUpdateFlag.equalsIgnoreCase("Update")) {
        result = objDB.updateUser(objBean);
      }
      if (result.equalsIgnoreCase("added")) {
        JOptionPane.showMessageDialog(this, "Record added successfuly");
        lst = objDB.getAllUsers();
        count = lst.size() - 1;
        showRecord(lst.get(count));
        disable(false);
        disableButton(true);

      } else if (result.equalsIgnoreCase("updated")) {
        JOptionPane.showMessageDialog(this, "Record updated successfuly");
        lst = objDB.getAllUsers();
        count = lst.size() - 1;
        showRecord(lst.get(count));
        disable(false);
        disableButton(true);
      } else if (result.equalsIgnoreCase("exists")) {
        JOptionPane.showMessageDialog(this, "Record already exists");

      } else {
        JOptionPane.showMessageDialog(this, "Operation failed");
      }
    }
  } // GEN-LAST:event_btnSaveActionPerformed
Пример #2
0
  private void btnAddActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnAddActionPerformed
    // TODO add your handling code here:

    Clear();
    addUpdateFlag = "add";
    disable(true);
    disableButton(false);
    int maxId = objDB.getMaxUserId();
    TxtUserId.setText(String.valueOf(maxId + 1));
  } // GEN-LAST:event_btnAddActionPerformed
Пример #3
0
 public UserDetail() {
   initComponents();
   objDB = new DBOperations();
   lst = objDB.getAllUsers();
   if (lst.size() > 0) {
     objBean = lst.get(0);
     showRecord(objBean);
   }
   disable(false);
   disableButton(true);
   TxtUserId.setEditable(false);
 }