示例#1
0
 // Get username
 public String getUsername(int userId) {
   logManager.logInfo("Entering 'getUsername(int userId)' method");
   String username = "";
   try {
     sqlString = queryBuilder.sqlSelectUsername(userId);
     resultset = executeQuery.executeSelect(sqlString);
     if (resultset.next()) {
       username = resultset.getString("usr");
     }
   } catch (Exception exception) {
     logManager.logError("Exception was thrown and caught in 'getUsername(int userId)' method");
   }
   logManager.logInfo("Exiting 'getUsername(int userId)' method");
   return username;
 }
示例#2
0
 // Get userid
 public int getUserId(String username) {
   logManager.logInfo("Entering 'getUserId(String username)' method");
   int userId = 0;
   try {
     sqlString = queryBuilder.sqlSelectUserId(username);
     resultset = executeQuery.executeSelect(sqlString);
     if (resultset.next()) {
       userId = resultset.getInt("user_id");
     }
   } catch (Exception exception) {
     logManager.logError("Exception was thrown and caught in 'getUserId(String username)' method");
   }
   logManager.logInfo("Exiting 'getUserId(String username)' method");
   return userId;
 }
示例#3
0
 // Save new user
 private int insertNewUser(
     String firstName,
     String lastName,
     String middleName,
     String userName,
     String password,
     String gender,
     String email,
     int organisationId,
     int roleId,
     int jobFunctionId,
     int languageId) {
   logManager.logInfo(
       "Entering 'insertNewUser(String firstName, String lastName, String middleName, String userName, String password, String gender,"
           + " String email, int organisationId, int roleId, int jobFunctionId, int languageId)' method");
   int result = 0;
   try {
     sqlString =
         queryBuilder.sqlInsertNewUser(
             firstName,
             lastName,
             middleName,
             userName,
             password,
             gender,
             email,
             organisationId,
             roleId,
             jobFunctionId,
             languageId);
     result = executeQuery.executeInsert(sqlString);
     if (result > 0) {
       // Comit
       executeQuery.commit();
     } else {
       // Roll back
       executeQuery.rollBack();
     }
   } catch (Exception exception) {
     logManager.logError(
         "Exception was thrown and caught in 'insertNewUser(String firstName, String lastName, String middleName, String userName, String password, String gender,"
             + " String email, int organisationId, int roleId, int jobFunctionId, int languageId)' method");
   }
   logManager.logInfo(
       "Exiting 'insertNewUser(String firstName, String lastName, String middleName, String userName, String password, String gender,"
           + " String email, int organisationId, int roleId, int jobFunctionId, int languageId)' method");
   return result;
 }
示例#4
0
 // Delete user
 public int deleteUser(int userId) {
   logManager.logInfo("Entering 'deleteUser(int userId)' method");
   int result = 0;
   try {
     sqlString = queryBuilder.sqlUpdateUserSetInactive(userId);
     result = executeQuery.executeInsert(sqlString);
     if (result > 0) {
       executeQuery.commit();
     } else {
       executeQuery.rollBack();
     }
   } catch (Exception exception) {
     logManager.logError("Exception was thrown and caught in 'deleteUser(int userId)' method");
   }
   logManager.logInfo("Exiting 'deleteUser(int userId)' method");
   return result;
 }
示例#5
0
 // Reset password
 public int resetPassword(int userId, String newPassword) {
   logManager.logInfo("Entering 'resetPassword(int userId, String newPassword)' method");
   int result = 0;
   try {
     sqlString = queryBuilder.sqlUpdatePassword(newPassword, userId);
     result = executeQuery.executeInsert(sqlString);
     if (result > 0) {
       executeQuery.commit();
     } else {
       executeQuery.rollBack();
     }
   } catch (Exception exception) {
     logManager.logError(
         "Exception was thrown and caught in 'resetPassword(int userId, String newPassword)' method");
   }
   logManager.logInfo("Exiting 'resetPassword(int userId, String newPassword)' method");
   return result;
 }
示例#6
0
 // Load languages
 public void loadLanguages(javax.swing.JComboBox... cboLanguages) {
   logManager.logInfo("Entering 'loadUserRoles(javax.swing.JComboBox... cboUserRoles)' method");
   String language = "";
   try {
     sqlString = queryBuilder.sqlSelectLanguages();
     resultset = executeQuery.executeSelect(sqlString);
     if (resultset.next()) {
       while (!resultset.isAfterLast()) {
         language = resultset.getString("lang");
         // Insert language into combo box
         for (JComboBox cboLanguage : cboLanguages) {
           cboLanguage.addItem(language);
         }
         resultset.next();
       }
     }
   } catch (Exception exception) {
     logManager.logError(
         "Exception was thrown and caught in 'loadUserRoles(javax.swing.JComboBox... cboUserRoles)' method");
   }
   logManager.logInfo("Exiting 'loadUserRoles(javax.swing.JComboBox... cboUserRoles)' method");
 }
示例#7
0
 // Save new organisation in the database
 public int saveNewJobFunction(String jobFunction, String description) {
   logManager.logInfo(
       "Entering 'saveNewJobFunction(String jobFunction, String description)' method");
   int result = 0;
   try {
     sqlString = queryBuilder.sqlInsertJobFunction(jobFunction, description);
     result = executeQuery.executeInsert(sqlString);
     if (result > 0) {
       // Comit
       executeQuery.commit();
     } else {
       // Roll back
       executeQuery.rollBack();
     }
   } catch (Exception exception) {
     logManager.logError(
         "Exception was thrown and caught in 'saveNewJobFunction(String jobFunction, String description)' method");
   }
   logManager.logInfo(
       "Exiting 'saveNewJobFunction(String jobFunction, String description)' method");
   return result;
 }
示例#8
0
 // Load languages
 public void loadOrganisations(javax.swing.JComboBox... cboOrganisations) {
   logManager.logInfo(
       "Entering 'loadOrganisations(javax.swing.JComboBox... cboOrganisations)' method");
   String organisation = "";
   try {
     sqlString = queryBuilder.sqlSelectOrganisations();
     resultset = executeQuery.executeSelect(sqlString);
     if (resultset.next()) {
       while (!resultset.isAfterLast()) {
         organisation = resultset.getString("org");
         // Insert organisations into combo box
         for (JComboBox cboOrganisation : cboOrganisations) {
           cboOrganisation.addItem(organisation);
         }
         resultset.next();
       }
     }
   } catch (Exception exception) {
     logManager.logError(
         "Exception was thrown and caught in 'loadOrganisations(javax.swing.JComboBox... cboOrganisations)' method");
   }
   logManager.logInfo(
       "Exiting 'loadOrganisations(javax.swing.JComboBox... cboOrganisations)' method");
 }
示例#9
0
  // Load all users
  public void loadUsers(
      int userId,
      JTextField txtFirstname,
      JTextField txtLastname,
      JTextField txtMiddlename,
      JTextField txtEmail,
      JRadioButton rbtFemale,
      JRadioButton rbtMale,
      JRadioButton rbtActive,
      JRadioButton rbtInactive,
      JComboBox cboUserRole,
      JComboBox cboLanguage,
      JComboBox cboJobFunction,
      JComboBox cboOrganisation) {
    logManager.logInfo(
        "Entering 'loadUsers(int userId, JTextField txtFirstname, JTextField txtLastname, JTextField txtMiddlename, JTextField txtEmail,"
            + "  JRadioButton rbtFemale, JRadioButton rbtMale, JRadioButton rbtActive, JRadioButton rbtInactive,"
            + "  JComboBox cboUserRole, JComboBox cboLanguage, JComboBox cboJobFunction, JComboBox cboOrganisation)' method");

    String firstName = "";
    String lastName = "";
    String middleName = "";
    String gender = "";
    String email = "";
    String userRole = "";
    String organisation = "";
    String language = "";
    String jobFunction = "";
    // int userId = 0;
    boolean isActive = false;

    try {
      sqlString = queryBuilder.sqlSelectUsers(userId);
      resultset = executeQuery.executeSelect(sqlString);

      if (resultset.next()) {
        firstName = resultset.getString("fname");
        lastName = resultset.getString("lname");
        middleName = resultset.getString("mname");
        email = resultset.getString("email");
        gender = resultset.getString("gender");
        userRole = resultset.getString("rname");
        organisation = resultset.getString("org");
        language = resultset.getString("langname");
        isActive = resultset.getInt("active") != 0 ? true : false;
        jobFunction = resultset.getString("job_func");

        // Load user details
        txtFirstname.setText(firstName);
        txtLastname.setText(lastName);
        txtMiddlename.setText(middleName);
        txtEmail.setText(email);
        cboLanguage.setSelectedItem(language);
        cboOrganisation.setSelectedItem(organisation);
        cboJobFunction.setSelectedItem(jobFunction);
        cboUserRole.setSelectedItem(userRole);
        if (gender.equalsIgnoreCase("Female")) {
          rbtFemale.setSelected(true);
        } else if (gender.equalsIgnoreCase("Male")) {
          rbtMale.setSelected(true);
        }
        if (isActive) {
          rbtActive.setSelected(true);
        } else {
          rbtInactive.setSelected(false);
        }
      }
    } catch (Exception exception) {
      logManager.logError(
          "Exception was thrown and caught in 'loadUsers(int userId, JTextField txtFirstname, JTextField txtLastname, JTextField txtMiddlename, JTextField txtEmail,"
              + "  JRadioButton rbtFemale, JRadioButton rbtMale, JRadioButton rbtActive, JRadioButton rbtInactive,"
              + "  JComboBox cboUserRole, JComboBox cboLanguage, JComboBox cboJobFunction, JComboBox cboOrganisation)' method");
    }
    logManager.logInfo(
        "Exiting 'loadUsers(int userId, JTextField txtFirstname, JTextField txtLastname, JTextField txtMiddlename, JTextField txtEmail,"
            + "  JRadioButton rbtFemale, JRadioButton rbtMale, JRadioButton rbtActive, JRadioButton rbtInactive,"
            + "  JComboBox cboUserRole, JComboBox cboLanguage, JComboBox cboJobFunction, JComboBox cboOrganisation)' method");
  }
示例#10
0
  // Load all users
  public void loadUsers(javax.swing.JTable tblUsers, javax.swing.table.DefaultTableModel tbmUsers) {
    logManager.logInfo(
        "Entering 'loadUsers(javax.swing.JTable tblUsers, javax.swing.table.DefaultTableModel tbmUsers)' method");
    String firstName = "";
    String lastName = "";
    String middleName = "";
    String userRole = "";
    String organisation = "";
    String language = "";
    int userNumber = 0;
    int userIndex = 0;
    int userId = 0;
    boolean isActive = false;

    try {
      sqlString = queryBuilder.sqlSelectUsers();
      resultset = executeQuery.executeSelect(sqlString);
      // Add columns to model
      insertColumnsToModel(
          tblUsers,
          tbmUsers,
          "Number",
          "First Name",
          "Last Name",
          "Middle Name",
          "User Role",
          "Organisation",
          "Language",
          "Active");
      // Set row count to 0
      tbmUsers.setRowCount(0);

      if (resultset.next()) {
        while (!resultset.isAfterLast()) {
          firstName = resultset.getString("fname"); // index 1
          lastName = resultset.getString("lname"); // index 2
          middleName = resultset.getString("mname"); // index 3
          userRole = resultset.getString("rname"); // index 4
          organisation = resultset.getString("org"); // index 5
          language = resultset.getString("langname"); // index 6
          isActive = resultset.getInt("active") != 0 ? true : false; // index 7
          userId = resultset.getInt("user_id"); // index 0
          // Insert row
          tbmUsers.insertRow(userIndex, new Object[] {null});
          // Populate rows
          tblUsers.setValueAt(userId, userIndex, 0);
          tblUsers.setValueAt(firstName, userIndex, 1);
          tblUsers.setValueAt(lastName, userIndex, 2);
          tblUsers.setValueAt(middleName, userIndex, 3);
          tblUsers.setValueAt(userRole, userIndex, 4);
          tblUsers.setValueAt(organisation, userIndex, 5);
          tblUsers.setValueAt(language, userIndex, 6);
          tblUsers.setValueAt(new JCheckBox("", isActive), userIndex, 7);
          resultset.next();
        }
      }
    } catch (Exception exception) {
      logManager.logError(
          "Exception was thrown and caught in 'loadUsers(javax.swing.JTable tblUsers, javax.swing.table.DefaultTableModel tbmUsers)' method");
    }
    logManager.logInfo(
        "Exiting 'loadUsers(javax.swing.JTable tblUsers, javax.swing.table.DefaultTableModel tbmUsers)' method");
  }