package edu.spbstu.hoteldb.admin.panel;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.List;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import edu.spbstu.hoteldb.Main;
import edu.spbstu.hoteldb.interfaces.Panel;
import edu.spbstu.hoteldb.panels.ClientSearchPanel;
import edu.spbstu.hoteldb.panels.PanelType;
import edu.spbstu.hoteldb.panels.PersonnelSearchPanel;
import edu.spbstu.hoteldb.panels.RoomSearchPanel;
public class RootSearchPanel extends VBox implements Panel {
private Connection connect;
private RoomSearchPanel rsp;
private ClientSearchPanel csp;
private PersonnelSearchPanel psp;
private final Main main;
public RootSearchPanel(Main main) {
this.main = main;
}
@Override
public void create(List<Object> args) {
this.setSpacing(30);
this.setPadding(new Insets(10, 10, 10, 10));
Button btnback = new Button("Back");
btnback.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
main.setPanel(PanelType.RootPanel, null);
}
});
rsp = new RoomSearchPanel();
csp = new ClientSearchPanel();
psp = new PersonnelSearchPanel();
args.add(connect);
try {
rsp.connect();
} catch (ClassNotFoundException | SQLException e) {
//ignore
e.printStackTrace();
}
rsp.create(args);
csp.create(args);
psp.create(args);
this.getChildren().addAll(btnback, rsp, csp, psp);
}
@Override
public void connect() throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager
.getConnection("jdbc:mysql://localhost/hotel_db?"
+ "user=hoteldb_admin&password=qwerty");
}
@Override
public void close() throws SQLException {
connect.close();
}
}