Package edu.spbstu.hoteldb.admin.panel

Source Code of edu.spbstu.hoteldb.admin.panel.FinancePanel

package edu.spbstu.hoteldb.admin.panel;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.LinkedList;
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.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import edu.spbstu.hoteldb.Main;
import edu.spbstu.hoteldb.admin.handler.IncomeCalcEventHandler;
import edu.spbstu.hoteldb.handlers.HistorySearchEventHandler;
import edu.spbstu.hoteldb.interfaces.Panel;
import edu.spbstu.hoteldb.panels.PanelType;

public class FinancePanel extends VBox implements Panel {
  private final Main main;
  private TextArea results;
  private Connection connect;
 
  public FinancePanel(Main main, List<Object> args) {
    this.main = main;
  }
 
  @Override
  public void create(List<Object> args) {
    this.setSpacing(30);
    this.setPadding(new Insets(10, 10, 10, 10));
   
    results = (TextArea) args.get(0);
   
    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, createHistorySearchPanel(), createIncomeOutcomePanel());
  }
 
  @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 GridPane createHistorySearchPanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
   
    Label lhistory = new Label("History");
    Label lfrom = new Label("From");
    DatePicker dpFrom = new DatePicker();
    Label lto = new Label("To");
    DatePicker dpTo = new DatePicker();
    Button btnsearch = new Button("Search");
    List<Object> args = new LinkedList<Object>();
    args.add(dpFrom); args.add(dpTo);
    btnsearch.setOnAction(new HistorySearchEventHandler(results, connect, args));
   
    gp.add(lhistory, 0, 0);
    gp.add(lfrom, 0, 1);
    gp.add(dpFrom, 1, 1);
    gp.add(lto, 0, 2);
    gp.add(dpTo, 1, 2);
    gp.add(btnsearch, 0, 3);
   
    return gp;
  }
 
  private GridPane createIncomeOutcomePanel() {
    GridPane gp = new GridPane();
    gp.setHgap(10);
    gp.setVgap(10);
    Label lincome = new Label("Income/Outcome");
    Label lFrom = new Label("From");
    DatePicker dpFrom = new DatePicker();
   
    Label lTo = new Label("To");
    DatePicker dpTo = new DatePicker();
    List<Object> args = new LinkedList<Object>();
    args.add(dpFrom); args.add(dpTo);
   
    Button btnCalc = new Button("Calculate");
    btnCalc.setOnAction(new IncomeCalcEventHandler(results, connect, args));
   
    gp.add(lincome, 0, 0);
    gp.add(lFrom, 0, 1);
    gp.add(dpFrom, 1, 1);
    gp.add(lTo, 0, 2);
    gp.add(dpTo, 1, 2);
    gp.add(btnCalc, 0, 3);
    return gp;
  }
}
TOP

Related Classes of edu.spbstu.hoteldb.admin.panel.FinancePanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.