Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package controller;
- import db.UzivatelSQL;
- import java.io.IOException;
- import java.net.URL;
- import java.sql.SQLException;
- import java.util.ResourceBundle;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.stage.Stage;
- import model.Uzivatel;
- /**
- *
- * @author michal
- */
- public class FXMLLoginController implements Initializable {
- @FXML
- Label labelUsername;
- Label labelPassword;
- Label loginWindowName;
- @FXML
- Button buttonLogin;
- @FXML
- TextField textFieldUsername;
- TextField textFieldPassword;
- @FXML
- private void buttonLoginClick(ActionEvent event) throws SQLException {
- String username = textFieldUsername.getText();
- String password = textFieldPassword.getText();
- UzivatelSQL uzivatelSQL = new UzivatelSQL();
- Uzivatel uzivatel = uzivatelSQL.overeniUzivatele(username, password);
- Parent root;
- FXMLLoader fxmlLoader;
- try {
- if (uzivatel != null) {
- //pokud role = Admin
- if (uzivatel.getRoleId() == 1) {
- fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource("ui/FXMLAdminView.fxml"));
- root = fxmlLoader.load();
- //nacte okno s moznosti uprav
- FXMLAdminViewController controller = fxmlLoader.<FXMLAdminViewController>getController();
- //controller.setUzivatel(uzivatel);
- //controller.fillTable JAK DAL
- } else {
- //pokud role = User
- fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource("ui/FXMLUserView.fxml"));
- root = fxmlLoader.load();
- //nacte okno bez tlacitek pro upravy
- FXMLUserViewController controller = fxmlLoader.<FXMLUserViewController>getController();
- //controller.setUzivatel(uzivatel);
- //controller.afterInit(); CO JE TO
- //controller.fillTable JAK DAL
- }
- } else {
- System.out.println("Spatne udaje");
- return;
- }
- Stage stage = new Stage();
- stage.setScene(new Scene(root, 450, 450));
- stage.setMaximized(true);
- stage.setTitle("Servisni katalog");
- stage.show();
- //hide this current window (if this is whant you want
- ((Node) (event.getSource())).getScene().getWindow().hide();
- } catch (IOException ex) {
- System.out.println(ex);
- }
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- // TODO
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement