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.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import edu.spbstu.hoteldb.Main;
import edu.spbstu.hoteldb.admin.handler.CountryStatEventHandler;
import edu.spbstu.hoteldb.admin.handler.LanguageStatEventHandler;
import edu.spbstu.hoteldb.admin.handler.LoadReportEventHandler;
import edu.spbstu.hoteldb.interfaces.Panel;
import edu.spbstu.hoteldb.panels.PanelType;
public class StatisticsPanel extends VBox implements Panel {
private Connection connect;
private final Main main;
public StatisticsPanel(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);
}
});
this.getChildren().addAll(btnback, createStatPanel());
}
@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();
}
private VBox createStatPanel() {
VBox box = new VBox();
box.setSpacing(10);
Label lbusy = new Label("Hotel load report");
Button btngenerate = new Button("Generate report");
btngenerate.setOnAction(new LoadReportEventHandler(connect));
Label llang = new Label("Language statistics");
Label lfrom = new Label("From");
DatePicker dpfrom = new DatePicker();
Label lto = new Label("To");
DatePicker dpto = new DatePicker();
GridPane gp = new GridPane();
gp.setVgap(10);
gp.setHgap(10);
gp.add(lfrom, 0, 0);
gp.add(dpfrom, 1, 0);
gp.add(lto, 0, 1);
gp.add(dpto, 1, 1);
Button btngenerate1 = new Button("Generate report");
btngenerate1.setOnAction(new LanguageStatEventHandler(connect));
Label lcountry = new Label("Country statistics");
Label lfrom1 = new Label("From");
DatePicker dpfrom1 = new DatePicker();
Label lto1 = new Label("To");
DatePicker dpto1 = new DatePicker();
GridPane gp1 = new GridPane();
gp1.setVgap(10);
gp1.setHgap(10);
gp1.add(lfrom1, 0, 0);
gp1.add(dpfrom1, 1, 0);
gp1.add(lto1, 0, 1);
gp1.add(dpto1, 1, 1);
Button btngenerate2 = new Button("Generate report");
btngenerate2.setOnAction(new CountryStatEventHandler(connect));
box.getChildren().addAll(lbusy, btngenerate, llang, gp, btngenerate1,
lcountry, gp1, btngenerate2);
return box;
}
}