package edu.spbstu.hoteldb.admin.handler;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.LinkedList;
import java.util.List;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import edu.spbstu.hoteldb.interfaces.SQLQuery;
import edu.spbstu.hoteldb.sql.IncomeCalcQuery;
public class IncomeCalcEventHandler implements EventHandler<ActionEvent> {
private final Connection connect;
private final TextArea results;
private List<Object> args;
public IncomeCalcEventHandler(TextArea results, Connection connect,
List<Object> args) {
this.connect = connect;
this.results = results;
this.args = args;
}
@Override
public void handle(ActionEvent arg0) {
List<Object> arg = new LinkedList<Object>();
LocalDate from = ((DatePicker) args.get(0)).getValue();
LocalDate to = ((DatePicker) args.get(1)).getValue();
if (from == null || to == null) {
results.appendText("undefined from date or to date\n");
return;
}
if (from.compareTo(to) >= 0) {
results.appendText("from date >= to date\n");
return;
}
arg.add(from.toString()); arg.add(to.toString());
try {
SQLQuery query = new IncomeCalcQuery(connect, results);
query.prepareQuery(arg);
query.doQuery();
query.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}