private void btnAddUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddUserActionPerformed
        String userId,username,pass1="",pass2="",role;
        char[] pwd1,pwd2;
        userId=this.txtUserID.getText();
        username=this.txtUsername.getText();
        pwd1=this.txtPassword.getPassword();
        pwd2=this.txtRetypePassword.getPassword();
        role=((String)this.cmbRole.getSelectedItem()).toLowerCase();
        
        for(int i=0;i<pwd1.length;i++){
            pass1+=pwd1[i];
        }
        
        for(int i=0;i<pwd2.length;i++){
            pass2+=pwd2[i];
        }
        
        if(!(pass1.equals(pass2))){
            JOptionPane.showMessageDialog(null, "Password mismatch!", "Error", JOptionPane.ERROR_MESSAGE);
        }
        else{
            try{
                Statement st=con.createStatement();
                String query1="SELECT * FROM employee WHERE emp_id="+userId;
                String query2="SELECT * FROM users WHERE username='"+username+"'";
                String query3="SELECT * FROM users WHERE userid="+userId;
                String query4="SELECT * FROM manager WHERE emp_id="+userId;

                ResultSet rs1=st.executeQuery(query1);

                if(!(rs1.next())){
                    JOptionPane.showMessageDialog(null, "No employee exists with the employee id "+userId, "Registration Error", JOptionPane.ERROR_MESSAGE);
                }
                else{
                    ResultSet rs4=st.executeQuery(query4);
                    if(role.equalsIgnoreCase("manager") && !(rs4.next())){
                        JOptionPane.showMessageDialog(null, "Employee with id "+userId+" is not really a manager!", "Registration Error", JOptionPane.ERROR_MESSAGE);
                    }
                    else{
                        ResultSet rs2=st.executeQuery(query2);
                        if(rs2.next()){
                            JOptionPane.showMessageDialog(null, "Username cannot be used! Username already taken.", "Registration Error", JOptionPane.ERROR_MESSAGE);
                        }
                        else{
                            ResultSet rs3=st.executeQuery(query3);
                            if(rs3.next()){
                                JOptionPane.showMessageDialog(null, "Cannot create account! You already have an account.", "Registration Error", JOptionPane.ERROR_MESSAGE);
                            }
                            else{
                                query2="INSERT INTO users VALUES ('"+username+"','"+md5Crypt(pass1)+"','"+userId+"','"+role+"')";
                                st.executeUpdate(query2);
                                JOptionPane.showMessageDialog(null, "User added to "+role+"s!", "Successful", JOptionPane.INFORMATION_MESSAGE);
                            }

                        }
                    }

                }
            }
            catch(Exception ex){
                ex.printStackTrace();
            }
        }
        
        
    }//GEN-LAST:event_btnAddUserActionPerformed