diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/lib/mysql-connector-j-8.0.33.jar b/lib/mysql-connector-j-8.0.33.jar new file mode 100644 index 0000000..3f741f5 Binary files /dev/null and b/lib/mysql-connector-j-8.0.33.jar differ diff --git a/lib/protobuf-java-3.21.9.jar b/lib/protobuf-java-3.21.9.jar new file mode 100644 index 0000000..c4fd860 Binary files /dev/null and b/lib/protobuf-java-3.21.9.jar differ diff --git a/pom.xml b/pom.xml index 1d6bfa5..e1312ee 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,11 @@ <artifactId>javafx-controls</artifactId> <version>21</version> </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>8.0.33</version> + </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> diff --git a/src/main/java/org/example/saladeconciertos/VentaBoletos.java b/src/main/java/org/example/saladeconciertos/VentaBoletos.java index 76f18d6..6e61b1a 100644 --- a/src/main/java/org/example/saladeconciertos/VentaBoletos.java +++ b/src/main/java/org/example/saladeconciertos/VentaBoletos.java @@ -4,9 +4,6 @@ import javafx.application.Application; 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.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; @@ -15,56 +12,24 @@ import java.util.ArrayList; import java.util.List; public class VentaBoletos extends Application { - private static final String DB_URL = "jdbc:mysql://localhost:3306/bookticket"; - private static final String DB_USER = "root"; - private static final String DB_PASSWORD = "smash1203bloons"; + private static final String DB_URL = "jdbc:mysql://159.54.135.17:3306/bookticket"; + private static final String DB_USER = "edermaximus"; + private static final String DB_PASSWORD = "1234"; private List<Integer> selectedSeats = new ArrayList<>(); @Override - public void start(Stage primaryStage) { + public void start(Stage mainStage) { - Label userLabel = new Label("Usuario:"); - TextField userField = new TextField(); - Label passLabel = new Label("Contraseña:"); - PasswordField passField = new PasswordField(); - Button loginButton = new Button("Iniciar Sesión"); - Label messageLabel = new Label(); + try{ + Connection conexion = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); + System.out.println("Conexión realizada correctamente"); + conexion.close(); - loginButton.setOnAction(e -> { - String username = userField.getText(); - String password = passField.getText(); - if (authenticate(username, password)) { - messageLabel.setText("Acceso concedido"); - openMainWindow(); - primaryStage.close(); - } else { - messageLabel.setText("Credenciales incorrectas"); - } - }); - - VBox loginLayout = new VBox(10, userLabel, userField, passLabel, passField, loginButton, messageLabel); - Scene loginScene = new Scene(loginLayout, 300, 200); - primaryStage.setScene(loginScene); - primaryStage.setTitle("Sistema de Venta de Boletos"); - primaryStage.show(); - } - - private boolean authenticate(String username, String password) { - try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) { - String sql = "SELECT * FROM users WHERE username = ? AND password = ?"; - PreparedStatement stmt = conn.prepareStatement(sql); - stmt.setString(1, username); - stmt.setString(2, password); - ResultSet rs = stmt.executeQuery(); - return rs.next(); - } catch (Exception e) { + } catch (SQLException e) { + System.out.println("Error en la conexión a la base de datos."); e.printStackTrace(); - return false; } - } - private void openMainWindow() { - Stage mainStage = new Stage(); mainStage.setTitle("Gestión de Boletos"); Label welcomeLabel = new Label("Seleccione sus asientos"); GridPane seatGrid = new GridPane(); @@ -84,27 +49,15 @@ public class VentaBoletos extends Application { } } - confirmButton.setOnAction(e -> confirmPurchase()); - VBox mainLayout = new VBox(10, welcomeLabel, seatGrid, confirmButton); + VBox mainLayout = new VBox(10, welcomeLabel, seatGrid, confirmButton); Scene mainScene = new Scene(mainLayout, 400, 300); mainStage.setScene(mainScene); mainStage.show(); } - private void confirmPurchase() { - try (Connection conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD)) { - String sql = "INSERT INTO sales (seat_number) VALUES (?)"; - PreparedStatement stmt = conn.prepareStatement(sql); - for (int seat : selectedSeats) { - stmt.setInt(1, seat); - stmt.executeUpdate(); - } - selectedSeats.clear(); - } catch (Exception e) { - e.printStackTrace(); - } - } + + public static void main(String[] args) { launch(args);