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>
<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>

View File

@ -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);