Vous êtes sur la page 1sur 2

package ProductInventorySystem;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.net.URL;
import java.util.ResourceBundle;

public class LoginController implements Initializable


{

@FXML
private TextField username;
//Retrieve text field values from defined FXML file
@FXML
private TextField password;
//Retrieve text field values from defined FXML file
@FXML
private ComboBox<AuthorizationLevel> comboBox;
//Retrieve combo box option values from defined FXML file
@FXML
private Button loginButton;
//Retrieve button values from defined FXML file
@FXML
private Label loginInformativeMessage;
//Retrieve text label values from defined FXML file

public void initialize(URL url, ResourceBundle rb)


{

this.comboBox.setItems(FXCollections.observableArrayList(AuthorizationLevel.values(
)));
//Initialize the SQL database for user authentication
}

LoginModel loginmodel = new LoginModel();


//Create constructor for unique login instance

@FXML
public void LoginAuthentication(ActionEvent event)
{
try
{
if(this.loginmodel.isLogin(this.username.getText(),
this.password.getText(),((AuthorizationLevel)this.comboBox.getValue()).toString()))
//Reference user entries in provided text fields with user login
information from the SQL database
{
//If entries are correct call the appropriate FXML file
Stage stage = (Stage)this.loginButton.getScene().getWindow();
stage.close();
switch (((AuthorizationLevel)this.comboBox.getValue()).toString())
//Call switch function to control which dashboard will be
given to the user, based on user level
{
case "Administrator":
try
{
FXMLLoader fxmlLoader = new
FXMLLoader(getClass().getResource("/ProductInventorySystem/administratorFXML.fxml")
);
Parent administratorRoot = (Parent) fxmlLoader.load();
Stage administratorStage = new Stage();
stage.setTitle("Administrator Dashboard");
stage.setScene(new Scene(administratorRoot));
stage.show();
//Load Administrator Dashboard
}
catch (Exception exception)
{
System.out.println("Can't load new window");
}
break;
case "Staff":
try
{
FXMLLoader fxmlLoader = new
FXMLLoader(getClass().getResource("/ProductInventorySystem/staffFXML.fxml"));
Parent staffRoot = (Parent) fxmlLoader.load();
Stage staffStage = new Stage();
stage.setTitle("Staff Dashboard");
stage.setScene(new Scene(staffRoot));
stage.show();
//Load Staff Dashboard
}
catch (Exception exception)
{
System.out.println("Can't load new window");
//Informative message to indicate that the system
was unable to load new window
}
break;
}
}
else
{
this.loginInformativeMessage.setText(("Incorrect Credentials"));
//Informative message to indicate that the entered credentials
were incorrect
}
}
catch (Exception exception)
{

}
}
}

Vous aimerez peut-être aussi