Beispiel #1
0
 public String GetAccountName(int id) {
   for (Account a : accounts) {
     if (a.getAccountID() == id) {
       return a.getAccountName();
     }
   }
   return null;
 }
Beispiel #2
0
 public int GetAccoutID(String user) {
   for (Account a : accounts) {
     if (a.getAccountName().equals(user)) {
       return a.getAccountID();
     }
   }
   return 0;
 }
Beispiel #3
0
  public String deleteUser() {
    if (selectedUser != null) {
      if (!"admin".equals(selectedUser.getLoginName())) {
        List<Account> accountList = accountService.getAllByUser(selectedUser);
        for (Account account : accountList) {
          account.setDestroy(true);
          account.setUser(null);
          accountService.updateAccount(account);
        }
        List<Topic> topicList = messageService.findByUser(selectedUser);
        for (Topic topic : topicList) {
          List<Message> messageList = messageService.findByTopic(topic);
          topic.setLastMessage(null);
          messageService.editTopic(topic);
          for (Message message : messageList) {
            message.setSender(null);
            message.setTopic(null);
            messageService.removeMessage(message);
          }
          messageList.clear();
          messageService.removeTopic(topic);
        }

        topicList.clear();

        userService.removeUser(selectedUser);
        selectedUser = new User();
        return "listUser?faces-redirect=true";
      } else {
        FacesContext.getCurrentInstance()
            .addMessage(
                null,
                new FacesMessage(
                    FacesMessage.SEVERITY_INFO,
                    "Deleting error",
                    "This user has leaded projects or you tried to delete admin! >> nice try! "));
        return "listUser?faces-redirect=false";
      }
    } else {
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_INFO,
                  "User has not selected",
                  "You did not select any user!"));
      return "listUser?faces-redirect=false";
    }
  }
Beispiel #4
0
 public void deleteAccountEmp(Account acc) {
   boolean del = accountFacade.deleteAccountEmp(acc);
   if (del) {
     FacesMessage message =
         new FacesMessage(
             FacesMessage.SEVERITY_INFO,
             "SUCCESSFULL",
             "Delete Account Of EmpID " + acc.getUserName().getEmployeeID() + " Successful !!!");
     FacesContext.getCurrentInstance().addMessage(null, message);
   } else {
     FacesMessage message =
         new FacesMessage(
             FacesMessage.SEVERITY_ERROR,
             "ERROR",
             "Delete Account Of EmpID " + acc.getUserName().getEmployeeID() + " UnSuccessful !!!");
     FacesContext.getCurrentInstance().addMessage(null, message);
   }
 }
Beispiel #5
0
  // create account (account name, account password, account email)
  public boolean CreateAccount(Account a) throws NoSuchAlgorithmException {
    String name = a.getAccountName();

    if (!CheckUserExist(name)) {
      String pass = new MD5().createMD5(a.getAccountPassword());
      String email = a.getAccountMail();
      int type = 2;
      String cmd2 =
          "insert into Account values('" + name + "','" + pass + "','" + email + "'," + type + ")";
      boolean result = new SQLUtil().execute(cmd2);
      if (result) {
        JOptionPane.showMessageDialog(Accounts, "Register Successfully");
        return true;
      } else {
        JOptionPane.showMessageDialog(Accounts, "Create Account faild");
        return false;
      }

    } else {
      JOptionPane.showMessageDialog(Accounts, "Username already exist");
      return false;
    }
  }