Package edu.spbstu.hoteldb.handlers

Source Code of edu.spbstu.hoteldb.handlers.RegisterQueryEventHandler

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.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import edu.spbstu.hoteldb.Main;
import edu.spbstu.hoteldb.interfaces.SQLQuery;
import edu.spbstu.hoteldb.panels.PanelType;
import edu.spbstu.hoteldb.sql.NewUserUpdate;

public class RegisterQueryEventHandler implements EventHandler<ActionEvent> {
  private final TextArea textArea;
  private final Main main;
  private final List<Node> args;
  private final Connection connect;

  public RegisterQueryEventHandler(Connection connection, TextArea ta, Main m, List<Node> l) {
    textArea = ta;
    main = m;
    args = l;
    connect = connection;
  }

  @SuppressWarnings("unchecked")
  @Override
  public void handle(ActionEvent event) {
    String login = ((TextField) args.get(0)).getText();
    String email = ((TextField) args.get(1)).getText();
    String pass = ((TextField) args.get(2)).getText();
    String name = ((TextField) args.get(3)).getText();
    String country = ((ChoiceBox<String>) args.get(4)).getValue();
    String lang = ((ChoiceBox<String>) args.get(5)).getValue();
    if ((email.compareTo("") == 0) || (pass.compareTo("") == 0)
        || (name.compareTo("") == 0)) {
      textArea.appendText("Login, password and name are required to complete registration.");
    } else {
      SQLQuery nuu = new NewUserUpdate(connect, textArea);
      List<Object> args = new LinkedList<Object>();
      args.add(login); args.add(email); args.add(pass); args.add(name); args.add(country); args.add(lang);
      try {
        nuu.prepareQuery(args);
        nuu.doQuery();
        main.setPanel(PanelType.LoginPanel, null);       
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
}
TOP

Related Classes of edu.spbstu.hoteldb.handlers.RegisterQueryEventHandler

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.