Advertisement
Guest User

Untitled

a guest
Dec 27th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.18 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package controller;
  7.  
  8. import db.UzivatelSQL;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.sql.SQLException;
  12. import java.util.ResourceBundle;
  13. import javafx.event.ActionEvent;
  14. import javafx.fxml.FXML;
  15. import javafx.fxml.FXMLLoader;
  16. import javafx.fxml.Initializable;
  17. import javafx.scene.Node;
  18. import javafx.scene.Parent;
  19. import javafx.scene.Scene;
  20. import javafx.scene.control.Button;
  21. import javafx.scene.control.Label;
  22. import javafx.scene.control.TextField;
  23. import javafx.stage.Stage;
  24. import model.Uzivatel;
  25.  
  26. /**
  27.  *
  28.  * @author michal
  29.  */
  30. public class FXMLLoginController implements Initializable {
  31.  
  32.     @FXML
  33.     Label labelUsername;
  34.     Label labelPassword;
  35.     Label loginWindowName;
  36.  
  37.     @FXML
  38.     Button buttonLogin;
  39.  
  40.     @FXML
  41.     TextField textFieldUsername;
  42.     TextField textFieldPassword;
  43.  
  44.     @FXML
  45.     private void buttonLoginClick(ActionEvent event) throws SQLException {
  46.         String username = textFieldUsername.getText();
  47.         String password = textFieldPassword.getText();
  48.  
  49.         UzivatelSQL uzivatelSQL = new UzivatelSQL();
  50.         Uzivatel uzivatel = uzivatelSQL.overeniUzivatele(username, password);
  51.  
  52.         Parent root;
  53.         FXMLLoader fxmlLoader;
  54.  
  55.         try {
  56.  
  57.             if (uzivatel != null) {
  58.                 //pokud role = Admin
  59.                 if (uzivatel.getRoleId() == 1) {
  60.                     fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource("ui/FXMLAdminView.fxml"));
  61.                     root = fxmlLoader.load();
  62.                     //nacte okno s moznosti uprav
  63.                     FXMLAdminViewController controller = fxmlLoader.<FXMLAdminViewController>getController();
  64.                     //controller.setUzivatel(uzivatel);
  65.                     //controller.fillTable JAK DAL
  66.                 } else {
  67.                     //pokud role = User
  68.                     fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource("ui/FXMLUserView.fxml"));
  69.                     root = fxmlLoader.load();
  70.                     //nacte okno bez tlacitek pro upravy
  71.                     FXMLUserViewController controller = fxmlLoader.<FXMLUserViewController>getController();
  72.                     //controller.setUzivatel(uzivatel);
  73.                     //controller.afterInit(); CO JE TO
  74.                     //controller.fillTable JAK DAL
  75.                 }
  76.             } else {
  77.                 System.out.println("Spatne udaje");
  78.                 return;
  79.             }
  80.  
  81.             Stage stage = new Stage();
  82.             stage.setScene(new Scene(root, 450, 450));
  83.             stage.setMaximized(true);
  84.             stage.setTitle("Servisni katalog");
  85.             stage.show();
  86.  
  87.             //hide this current window (if this is whant you want
  88.             ((Node) (event.getSource())).getScene().getWindow().hide();
  89.  
  90.         } catch (IOException ex) {
  91.             System.out.println(ex);
  92.         }
  93.     }
  94.  
  95.     @Override
  96.     public void initialize(URL url, ResourceBundle rb) {
  97.         // TODO
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement