// Path: src/data/updating/LoggedUser.java
// public class LoggedUser {
// 
//   private static StringProperty loggedUser = new SimpleStringProperty("");
// 
//   public static StringProperty loggedUserProperty() {
//     return loggedUser;
//   }
// 
//   public static String getLoggedUser() {
//     return loggedUser.get();
//   }
// 
// 
//   public static void setLoggedUser(String currentLoggedUser) {
//     loggedUser.set(currentLoggedUser);
//   }
// 
// }
// 
// Path: src/database/Database.java
// public class Database {
// 
//   private static final String DBURL = "jdbc:h2:~/test";
//   private static final String DBUSER = "Kaloyan_Bogoslovov";
//   private static final String DBPASS = "qwerty";
//   private static Connection connection;
// 
//   public static void connectingToDB() throws ClassNotFoundException, SQLException {
//     Class.forName("org.h2.Driver");
//     connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
//   }
// 
//   public static void createDB() throws ClassNotFoundException, SQLException {
//     Class.forName("org.h2.Driver");
//     Connection con = DriverManager.getConnection("jdbc:h2:~/test", "Kaloyan_Bogoslovov", "qwerty");
//     Statement st = con.createStatement();
//     String createUsersTable =
//         "CREATE TABLE IF NOT EXISTS USERS(USERNAME VARCHAR2(20) primary key,FIRSTNAME VARCHAR2,lastname varchar2,password varchar2 ,balance number,leverage integer,margin NUMBER,totalprofit NUMBER,equity NUMBER,freemargin number,ordernumber integer,stockexchange varchar2);";
//     String createTradesTable =
//         "CREATE TABLE IF NOT EXISTS TRADES(USERNAME VARCHAR2(20) references users(username),SYMBOL VARCHAR2(8),ORDERNUMBER INTEGER,TRADETIME DATETIME ,TRADETYPE VARCHAR2(8),VOLUME NUMBER,PURCHASEPRICE NUMBER,CURRENTPRICE NUMBER,PROFIT NUMBER,TRADESTATE VARCHAR2,LASTPRICE NUMBER,COMPANY varchar2,Closetime datetime);";
//     st.executeUpdate(createUsersTable);
//     st.executeUpdate(createTradesTable);
//     con.close();
//   }
// 
//   public static ResultSet SelectDB(String data) throws SQLException {
//     Statement st = connection.createStatement();
//     ResultSet rs = st.executeQuery(data);
//     return rs;
//   }
// 
//   public static void insertDB(String data) throws SQLException {
//     Statement st = connection.createStatement();
//     st.executeUpdate(data);
//   }
// 
//   public static void closeConnectionToDB() throws SQLException {
//     connection.close();
//   }
// 
// }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import data.updating.LoggedUser;
import database.Database;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
    signButton.setOnAction(e -> {
      new CreateAccount();
    });
    signButton.setPrefWidth(110);
    HBox hbox = new HBox(10);
    hbox.getChildren().addAll(signButton, loginButton);
    GridPane.setConstraints(hbox, 1, 2);

    error = new Label();
    GridPane.setConstraints(error, 1, 3);

    grid.getChildren().addAll(nameLabel, nameTF, passLabel, passTF, hbox, error);

    Scene scene = new Scene(grid, 330, 160);
    window.setScene(scene);
    window.setResizable(false);
    window.setOnCloseRequest(e -> {
      System.exit(0);
    });
    window.getIcons().add(new Image("blue.png"));
    window.show();

  }

  private void logging() throws ClassNotFoundException, SQLException {
    Database.connectingToDB();
    String input = nameTF.getText() + " " + passTF.getText();
    ResultSet result = Database.SelectDB("Select username,password,stockexchange from USERS");
    while (result.next()) {
      if (input.equals(result.getString(1) + " " + result.getString(2))) {
// Path: src/data/updating/LoggedUser.java
// public class LoggedUser {
// 
//   private static StringProperty loggedUser = new SimpleStringProperty("");
// 
//   public static StringProperty loggedUserProperty() {
//     return loggedUser;
//   }
// 
//   public static String getLoggedUser() {
//     return loggedUser.get();
//   }
// 
// 
//   public static void setLoggedUser(String currentLoggedUser) {
//     loggedUser.set(currentLoggedUser);
//   }
// 
// }
// 
// Path: src/database/Database.java
// public class Database {
// 
//   private static final String DBURL = "jdbc:h2:~/test";
//   private static final String DBUSER = "Kaloyan_Bogoslovov";
//   private static final String DBPASS = "qwerty";
//   private static Connection connection;
// 
//   public static void connectingToDB() throws ClassNotFoundException, SQLException {
//     Class.forName("org.h2.Driver");
//     connection = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
//   }
// 
//   public static void createDB() throws ClassNotFoundException, SQLException {
//     Class.forName("org.h2.Driver");
//     Connection con = DriverManager.getConnection("jdbc:h2:~/test", "Kaloyan_Bogoslovov", "qwerty");
//     Statement st = con.createStatement();
//     String createUsersTable =
//         "CREATE TABLE IF NOT EXISTS USERS(USERNAME VARCHAR2(20) primary key,FIRSTNAME VARCHAR2,lastname varchar2,password varchar2 ,balance number,leverage integer,margin NUMBER,totalprofit NUMBER,equity NUMBER,freemargin number,ordernumber integer,stockexchange varchar2);";
//     String createTradesTable =
//         "CREATE TABLE IF NOT EXISTS TRADES(USERNAME VARCHAR2(20) references users(username),SYMBOL VARCHAR2(8),ORDERNUMBER INTEGER,TRADETIME DATETIME ,TRADETYPE VARCHAR2(8),VOLUME NUMBER,PURCHASEPRICE NUMBER,CURRENTPRICE NUMBER,PROFIT NUMBER,TRADESTATE VARCHAR2,LASTPRICE NUMBER,COMPANY varchar2,Closetime datetime);";
//     st.executeUpdate(createUsersTable);
//     st.executeUpdate(createTradesTable);
//     con.close();
//   }
// 
//   public static ResultSet SelectDB(String data) throws SQLException {
//     Statement st = connection.createStatement();
//     ResultSet rs = st.executeQuery(data);
//     return rs;
//   }
// 
//   public static void insertDB(String data) throws SQLException {
//     Statement st = connection.createStatement();
//     st.executeUpdate(data);
//   }
// 
//   public static void closeConnectionToDB() throws SQLException {
//     connection.close();
//   }
// 
// }


// Path: src/accounts/LogIn.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import data.updating.LoggedUser;
import database.Database;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;

    signButton.setOnAction(e -> {
      new CreateAccount();
    });
    signButton.setPrefWidth(110);
    HBox hbox = new HBox(10);
    hbox.getChildren().addAll(signButton, loginButton);
    GridPane.setConstraints(hbox, 1, 2);

    error = new Label();
    GridPane.setConstraints(error, 1, 3);

    grid.getChildren().addAll(nameLabel, nameTF, passLabel, passTF, hbox, error);

    Scene scene = new Scene(grid, 330, 160);
    window.setScene(scene);
    window.setResizable(false);
    window.setOnCloseRequest(e -> {
      System.exit(0);
    });
    window.getIcons().add(new Image("blue.png"));
    window.show();

  }

  private void logging() throws ClassNotFoundException, SQLException {
    Database.connectingToDB();
    String input = nameTF.getText() + " " + passTF.getText();
    ResultSet result = Database.SelectDB("Select username,password,stockexchange from USERS");
    while (result.next()) {
      if (input.equals(result.getString(1) + " " + result.getString(2))) {
        LoggedUser.setLoggedUser(nameTF.getText());