package edu.spbstu.hoteldb.handlers;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import edu.spbstu.hoteldb.interfaces.SQLQuery;
import edu.spbstu.hoteldb.sql.ClientSearchQuery;
public class ClientSearchEventHandler implements EventHandler<ActionEvent>{
private final Connection connect;
private final TextArea results;
private List<Node> args;
public ClientSearchEventHandler(TextArea ta, Connection c, List<Node> arg) {
results = ta;
connect = c;
args = arg;
}
@Override
public void handle(ActionEvent arg0) {
SQLQuery query = new ClientSearchQuery(results, connect);
try {
List<Object> arg = new LinkedList<Object>();
arg.add(((TextField) args.get(0)).getText());
arg.add(((TextField) args.get(1)).getText());
query.prepareQuery(arg);
query.doQuery();
query.close();
} catch (SQLException e) {
results.appendText("invalid query\n");
e.printStackTrace();
}
}
}