document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //LoginScreenController.java
  2.  
  3. package hotelmanagementsystem;
  4.  
  5. import com.jfoenix.controls.JFXButton;
  6. import com.jfoenix.controls.JFXDialog;
  7. import com.jfoenix.controls.JFXDialogLayout;
  8. import com.jfoenix.controls.JFXTextField;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.sql.Connection;
  12. import java.sql.PreparedStatement;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.sql.Statement;
  16. import java.util.ResourceBundle;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import javafx.event.ActionEvent;
  20. import javafx.event.EventHandler;
  21. import javafx.fxml.FXML;
  22. import javafx.fxml.FXMLLoader;
  23. import javafx.fxml.Initializable;
  24. import javafx.geometry.Pos;
  25. import javafx.scene.Parent;
  26. import javafx.scene.Scene;
  27. import javafx.scene.image.Image;
  28. import javafx.scene.image.ImageView;
  29. import javafx.scene.input.MouseEvent;
  30. import javafx.scene.layout.StackPane;
  31. import javafx.scene.text.Text;
  32. import javafx.stage.Stage;
  33. import javafx.stage.StageStyle;
  34. import javafx.util.Duration;
  35. import org.controlsfx.control.Notifications;
  36.  
  37. /**
  38.  * FXML Controller class
  39.  *
  40.  * @author medam
  41.  */
  42. public class LoginScreenController implements Initializable {
  43.  
  44.     @FXML
  45.     private JFXTextField username;
  46.     @FXML
  47.     private JFXTextField password;
  48.     @FXML
  49.     private StackPane stackepane;
  50.  
  51.     /**
  52.      * Initializes the controller class.
  53.      */
  54.     @Override
  55.     public void initialize(URL url, ResourceBundle rb) {
  56.         // TODO
  57.     }
  58.    
  59. @FXML
  60.     private void loginButton(MouseEvent event) {
  61.         //video : 19-5
  62.         if(username.getText().toString().equals("")){
  63.        
  64.             Image image = new Image("/img/delete.png");
  65.             Notifications notification = Notifications.create()
  66.                     .title("Error")
  67.                     .text("Username is empty")
  68.                     .hideAfter(Duration.seconds(3))
  69.                     .position(Pos.BOTTOM_LEFT)
  70.                     .graphic(new ImageView(image));
  71.             notification.darkStyle();
  72.             notification.show();
  73.         }else if(password.getText().toString().equals("")){
  74.        
  75.             Image image = new Image("/img/delete.png");
  76.             Notifications notification = Notifications.create()
  77.                     .title("Error")
  78.                     .text("Password is empty")
  79.                     .hideAfter(Duration.seconds(3))
  80.                     .position(Pos.BOTTOM_LEFT)
  81.                     .graphic(new ImageView(image));
  82.             notification.darkStyle();
  83.             notification.show();
  84.            
  85.         }else {
  86.        
  87.            
  88.                     boolean isExist=false;
  89.         String userPass="";
  90.         String userType="";
  91.        
  92.         String sql="select * from users where username=\'" +username.getText().toString().trim()+ "\' ";
  93.         //Connection con = DataBase.getInstance().getConnection();
  94.         Connection connection = DBConnection.getConnection();
  95.         try {
  96.             PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql);
  97.             ResultSet rs = ps.executeQuery();
  98.            
  99.             while(rs.next()){
  100.                 isExist=true;
  101.                 userPass=rs.getString(3);
  102.                 userType=rs.getString(8);
  103.                
  104.             }
  105.                
  106.             if(isExist){
  107.                 if(password.getText().toString().trim().equals(userPass)){
  108.                     if(userType.equals("admin")){
  109.                         //if user admin → admin Screen
  110.                         Stage adminScreen = new Stage();
  111.                         Parent root=null;
  112.                        
  113.                         try {
  114.                             root= FXMLLoader.load(getClass().getResource("AdminScreen.fxml"));
  115.                                    
  116.                          } catch (IOException ex) { Logger.getLogger(LoginScreenController.class.getName()).log(Level.SEVERE, null, ex);}
  117.                        
  118.                         Stage current = (Stage) username.getScene().getWindow();
  119.                         Scene scene = new Scene(root,1366,730);
  120.                         adminScreen.setScene(scene);
  121.                         adminScreen.initStyle(StageStyle.TRANSPARENT);
  122.                        
  123.                         current.hide();
  124.                         adminScreen.show();
  125.                        
  126.                    
  127.                     }else {     //if user normal → HomeScreen
  128.                    
  129.                        
  130.                         Stage homeScreen = new Stage();
  131.                         Parent root=null;
  132.                         try {
  133.                             root= FXMLLoader.load(getClass().getResource("HomeScreen.fxml"));
  134.                          } catch (IOException ex) { Logger.getLogger(LoginScreenController.class.getName()).log(Level.SEVERE, null, ex);}
  135.                        
  136.                         Stage current = (Stage) username.getScene().getWindow();
  137.                         Scene scene = new Scene(root,1366,730);
  138.                         homeScreen.setScene(scene);
  139.                         homeScreen.initStyle(StageStyle.TRANSPARENT);
  140.                         current.hide();
  141.                         homeScreen.show();
  142.                        
  143.                        
  144.                     }
  145.                 }
  146.             }else {
  147.                         Image image = new Image("/img/delete.png");
  148.             Notifications notification = Notifications.create()
  149.                     .title("Error")
  150.                     .text("Check Your username and password again !!!")
  151.                     .hideAfter(Duration.seconds(3))
  152.                     .position(Pos.BOTTOM_LEFT)
  153.                     .graphic(new ImageView(image));
  154.             notification.darkStyle();
  155.             notification.show();
  156.            
  157.             }
  158.            
  159.         } catch (SQLException ex) {
  160.             Logger.getLogger(LoginScreenController.class.getName()).log(Level.SEVERE, null, ex);
  161.         }
  162.         }
  163.      }
  164.  
  165.     @FXML
  166.     private void cancelButton(MouseEvent event) {
  167.         //vid 20 : 20-6  Enhance Login Screen Design
  168.            
  169.         JFXDialogLayout dialogLayout = new JFXDialogLayout();
  170.         dialogLayout.setHeading(new Text("Close"));
  171.         dialogLayout.setBody(new Text("Do you want to exit !"));
  172.         JFXButton ok = new JFXButton("ok");
  173.         JFXButton Cancel = new JFXButton("cancel");
  174.        
  175.         JFXDialog dialog = new JFXDialog(stackepane,dialogLayout,JFXDialog.DialogTransition.CENTER);
  176.         ok.setOnAction(new EventHandler<ActionEvent>() {
  177.             @Override
  178.             public void handle(ActionEvent event) {
  179.              
  180.             System.exit(0);
  181.             }
  182.         });
  183.        
  184.        
  185.         Cancel.setOnAction(new EventHandler<ActionEvent>(){
  186.            @Override
  187.             public void handle(ActionEvent event) {
  188.              
  189.             dialog.close();
  190.             }
  191.         });
  192.        
  193.         dialogLayout.setActions(ok,Cancel);
  194.         dialog.show();
  195.        
  196.     }
  197. }
');