So the problem right now is that I have issue with prompting towards the right stage for each type of users, I have a method which checks their username and return their type of role and after that it will prompt it to their respective stage after verifying their user and pass.
I have tried to do some debug and it seems that the method getUserRole has something wrong with it, since I can't get into the method for it in the login controller.
**Login Controller*
@FXML
public void Login(ActionEvent event) {
try {
if (this.loginModel.isLogin(this.username.getText(), this.password.getText())) {
Stage stage = (Stage) this.login.getScene().getWindow();
stage.close();
if (this.loginModel.getUserRole(this.username.getText()) == 5) {
adminLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 4) {
technicianLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
custServiceLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
financeLogin();
} else if (this.loginModel.getUserRole(this.username.getText()) == 3) {
managementLogin();
} else {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
} catch (Exception localException) {
this.loginStatus.setText("The username or password entered is incorrect. Please check and try again.");
}
}
Get UserRole Method
public int getUserRole(String user) throws Exception
{
PreparedStatement pr = null;
ResultSet rs = null;
String sql = "SELECT * FROM Login WHERE username = ? AND role = ?";
try
{
pr = this.connection.prepareStatement(sql);
pr.setString(1, user);
if(rs.next())//cant initialized this if statement
{
int role = rs.getInt("role");
return role;
}
else{
return 0;
}
}
catch(SQLException ex)
{
return 0;
}
finally
{
pr.close();
rs.close();
}
}