Arreglo de base de datos y modificaciones de interfaz

This commit is contained in:
Christopher Alessandro Rodriguez Salazar 2025-03-07 16:54:07 -06:00
parent e243d4d409
commit 71ec7620bc
5 changed files with 24 additions and 60 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

View File

@ -20,6 +20,11 @@
<artifactId>javafx-controls</artifactId> <artifactId>javafx-controls</artifactId>
<version>21</version> <version>21</version>
</dependency> </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<dependency> <dependency>
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId> <artifactId>javafx-fxml</artifactId>

View File

@ -4,9 +4,6 @@ import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; 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.GridPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -15,56 +12,24 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class VentaBoletos extends Application { public class VentaBoletos extends Application {
private static final String DB_URL = "jdbc:mysql://localhost:3306/bookticket"; private static final String DB_URL = "jdbc:mysql://159.54.135.17:3306/bookticket";
private static final String DB_USER = "root"; private static final String DB_USER = "edermaximus";
private static final String DB_PASSWORD = "smash1203bloons"; private static final String DB_PASSWORD = "1234";
private List<Integer> selectedSeats = new ArrayList<>(); private List<Integer> selectedSeats = new ArrayList<>();
@Override @Override
public void start(Stage primaryStage) { public void start(Stage mainStage) {
Label userLabel = new Label("Usuario:"); try{
TextField userField = new TextField(); Connection conexion = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
Label passLabel = new Label("Contraseña:"); System.out.println("Conexión realizada correctamente");
PasswordField passField = new PasswordField(); conexion.close();
Button loginButton = new Button("Iniciar Sesión");
Label messageLabel = new Label();
loginButton.setOnAction(e -> { } catch (SQLException e) {
String username = userField.getText(); System.out.println("Error en la conexión a la base de datos.");
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) {
e.printStackTrace(); e.printStackTrace();
return false;
} }
}
private void openMainWindow() {
Stage mainStage = new Stage();
mainStage.setTitle("Gestión de Boletos"); mainStage.setTitle("Gestión de Boletos");
Label welcomeLabel = new Label("Seleccione sus asientos"); Label welcomeLabel = new Label("Seleccione sus asientos");
GridPane seatGrid = new GridPane(); 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); Scene mainScene = new Scene(mainLayout, 400, 300);
mainStage.setScene(mainScene); mainStage.setScene(mainScene);
mainStage.show(); 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) { public static void main(String[] args) {
launch(args); launch(args);