Cambio de base de datos
This commit is contained in:
parent
71ec7620bc
commit
4e3bfd6e1c
|
@ -1,6 +1,3 @@
|
||||||
CREATE DATABASE bookticket;
|
|
||||||
USE bookticket;
|
|
||||||
|
|
||||||
CREATE TABLE conciertos (
|
CREATE TABLE conciertos (
|
||||||
id INT auto_increment primary key,
|
id INT auto_increment primary key,
|
||||||
nombre varchar(50) not null,
|
nombre varchar(50) not null,
|
||||||
|
|
|
@ -9,22 +9,37 @@ import javafx.scene.layout.VBox;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class VentaBoletos extends Application {
|
public class VentaBoletos extends Application {
|
||||||
private static final String DB_URL = "jdbc:mysql://159.54.135.17:3306/bookticket";
|
private static final String DB_URL = "jdbc:mysql://sql10.freesqldatabase.com:3306/sql10766655";
|
||||||
private static final String DB_USER = "edermaximus";
|
private static final String DB_USER = "sql10766655";
|
||||||
private static final String DB_PASSWORD = "1234";
|
private static final String DB_PASSWORD = "7BZbRjEkXZ";
|
||||||
private List<Integer> selectedSeats = new ArrayList<>();
|
private List<Integer> selectedSeats = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage mainStage) {
|
public void start(Stage mainStage) {
|
||||||
|
int totalSeats = 0;
|
||||||
|
Map<Integer, String> seatStatus = new HashMap<>();
|
||||||
|
|
||||||
try{
|
try {
|
||||||
Connection conexion = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
|
Connection conexion = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
|
||||||
System.out.println("Conexión realizada correctamente");
|
System.out.println("Conexión realizada correctamente");
|
||||||
conexion.close();
|
|
||||||
|
|
||||||
|
String query = "SELECT id_asiento, status FROM boleto WHERE idevento = 1"; // Cambia el idevento según corresponda
|
||||||
|
Statement statement = conexion.createStatement();
|
||||||
|
ResultSet resultSet = statement.executeQuery(query);
|
||||||
|
|
||||||
|
while (resultSet.next()) {
|
||||||
|
int seatId = resultSet.getInt("id_asiento");
|
||||||
|
String status = resultSet.getString("status");
|
||||||
|
seatStatus.put(seatId, status);
|
||||||
|
totalSeats++;
|
||||||
|
}
|
||||||
|
|
||||||
|
conexion.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("Error en la conexión a la base de datos.");
|
System.out.println("Error en la conexión a la base de datos.");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -35,31 +50,39 @@ public class VentaBoletos extends Application {
|
||||||
GridPane seatGrid = new GridPane();
|
GridPane seatGrid = new GridPane();
|
||||||
Button confirmButton = new Button("Confirmar Compra");
|
Button confirmButton = new Button("Confirmar Compra");
|
||||||
|
|
||||||
for (int row = 0; row < 5; row++) {
|
int cols = 5;
|
||||||
for (int col = 0; col < 5; col++) {
|
int rows = (int) Math.ceil((double) totalSeats / cols);
|
||||||
int seatNumber = row * 5 + col + 1;
|
|
||||||
Button seatButton = new Button("Asiento " + seatNumber);
|
for (int seatNumber = 1; seatNumber <= totalSeats; seatNumber++) {
|
||||||
|
int row = (seatNumber - 1) / cols;
|
||||||
|
int col = (seatNumber - 1) % cols;
|
||||||
|
Button seatButton = new Button("Asiento " + seatNumber);
|
||||||
|
int finalSeatNumber = seatNumber;
|
||||||
|
|
||||||
|
if ("vendido".equals(seatStatus.getOrDefault(finalSeatNumber, "disponible"))) {
|
||||||
|
seatButton.setStyle("-fx-background-color: red");
|
||||||
|
seatButton.setDisable(true);
|
||||||
|
} else {
|
||||||
seatButton.setOnAction(e -> {
|
seatButton.setOnAction(e -> {
|
||||||
if (!selectedSeats.contains(seatNumber)) {
|
if (!selectedSeats.contains(finalSeatNumber)) {
|
||||||
selectedSeats.add(seatNumber);
|
selectedSeats.add(finalSeatNumber);
|
||||||
seatButton.setStyle("-fx-background-color: red");
|
seatButton.setStyle("-fx-background-color: green");
|
||||||
|
} else {
|
||||||
|
selectedSeats.remove(Integer.valueOf(finalSeatNumber));
|
||||||
|
seatButton.setStyle("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
seatGrid.add(seatButton, col, row);
|
|
||||||
}
|
}
|
||||||
|
seatGrid.add(seatButton, col, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue