Compare commits
No commits in common. "cambios-definitivos" and "main" have entirely different histories.
cambios-de
...
main
AdminTicket
NetBeansProjects/ticketCine
.vscode
pom.xmlsrc/main/java/com/mycompany/ticketcine
Asiento.javaCompraBoletosApp.javaDatabaseConnection.javaMainApp.javaPelicula.javaSala.javaVentaBoleto.java
target/maven-status/maven-compiler-plugin/compile/default-compile
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"java.project.referencedLibraries": [
|
||||||
|
"lib/**/*.jar",
|
||||||
|
"c:\\Users\\Tron7\\Documents\\DesarrolloSoftware\\VentaBoletos\\AdminTicket\\MVC\\modelo\\mysql-connector-j-8.3.0.jar"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import modelo.Database;
|
||||||
|
import vista.VentaBoletosView;
|
||||||
|
import controlador.VentaBoletosController;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Database database = new Database();
|
||||||
|
VentaBoletosView vista = new VentaBoletosView();
|
||||||
|
VentaBoletosController controlador = new VentaBoletosController(vista, database);
|
||||||
|
|
||||||
|
vista.setVisible(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
package controlador;
|
||||||
|
|
||||||
|
import modelo.*;
|
||||||
|
import vista.VentaBoletosView;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VentaBoletosController {
|
||||||
|
private VentaBoletosView vista;
|
||||||
|
private Database database;
|
||||||
|
private List<JButton> botonesAsientos;
|
||||||
|
|
||||||
|
public VentaBoletosController(VentaBoletosView vista, Database database) {
|
||||||
|
this.vista = vista;
|
||||||
|
this.database = database;
|
||||||
|
this.botonesAsientos = new ArrayList<>();
|
||||||
|
|
||||||
|
cargarAsientos();
|
||||||
|
agregarListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarAsientos() {
|
||||||
|
try {
|
||||||
|
Connection conexion = database.getConexion();
|
||||||
|
Statement stmt = conexion.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM asientos");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
int numeroAsiento = rs.getInt("numero_asiento");
|
||||||
|
boolean disponible = rs.getBoolean("disponible");
|
||||||
|
|
||||||
|
JButton btnAsiento = new JButton(String.valueOf(numeroAsiento));
|
||||||
|
btnAsiento.setEnabled(disponible);
|
||||||
|
btnAsiento.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
venderAsiento(numeroAsiento);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
botonesAsientos.add(btnAsiento);
|
||||||
|
vista.agregarBotonAsiento(btnAsiento);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void venderAsiento(int numeroAsiento) {
|
||||||
|
try {
|
||||||
|
Connection conexion = database.getConexion();
|
||||||
|
PreparedStatement pstmt = conexion.prepareStatement("UPDATE asientos SET disponible = FALSE WHERE numero_asiento = ?");
|
||||||
|
pstmt.setInt(1, numeroAsiento);
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
|
||||||
|
pstmt = conexion.prepareStatement("INSERT INTO ventas (fecha_venta, numero_asiento, precio) VALUES (NOW(), ?, ?)");
|
||||||
|
pstmt.setInt(1, numeroAsiento);
|
||||||
|
pstmt.setDouble(2, 100.00); // Precio fijo por simplicidad
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
|
||||||
|
vista.mostrarMensaje("Boleto vendido: Asiento " + numeroAsiento);
|
||||||
|
actualizarBotones();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void actualizarBotones() {
|
||||||
|
for (JButton btn : botonesAsientos) {
|
||||||
|
btn.setEnabled(false);
|
||||||
|
}
|
||||||
|
vista.actualizarBotones();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generarReporte() {
|
||||||
|
try {
|
||||||
|
Connection conexion = database.getConexion();
|
||||||
|
Statement stmt = conexion.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM ventas");
|
||||||
|
|
||||||
|
StringBuilder reporte = new StringBuilder("Reporte de Ventas:\n");
|
||||||
|
while (rs.next()) {
|
||||||
|
reporte.append("Fecha: ").append(rs.getTimestamp("fecha_venta")).append(", ");
|
||||||
|
reporte.append("Asiento: ").append(rs.getInt("numero_asiento")).append(", ");
|
||||||
|
reporte.append("Precio: $").append(rs.getDouble("precio")).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
vista.mostrarMensaje(reporte.toString());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void agregarListeners() {
|
||||||
|
vista.getBtnGenerarReporte().addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
generarReporte();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package modelo;
|
||||||
|
|
||||||
|
public class Asiento {
|
||||||
|
private int id;
|
||||||
|
private int numeroAsiento;
|
||||||
|
private boolean disponible;
|
||||||
|
|
||||||
|
public Asiento(int id, int numeroAsiento, boolean disponible) {
|
||||||
|
this.id = id;
|
||||||
|
this.numeroAsiento = numeroAsiento;
|
||||||
|
this.disponible = disponible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumeroAsiento() {
|
||||||
|
return numeroAsiento;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisponible() {
|
||||||
|
return disponible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisponible(boolean disponible) {
|
||||||
|
this.disponible = disponible;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package modelo;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
private Connection conexion;
|
||||||
|
|
||||||
|
public Database() {
|
||||||
|
conectar();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void conectar() {
|
||||||
|
try {
|
||||||
|
conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/venta_boletos", "root", "4560");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConexion() {
|
||||||
|
return conexion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cerrarConexion() {
|
||||||
|
try {
|
||||||
|
if (conexion != null) {
|
||||||
|
conexion.close();
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package modelo;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class Venta {
|
||||||
|
private int id;
|
||||||
|
private Timestamp fechaVenta;
|
||||||
|
private int numeroAsiento;
|
||||||
|
private double precio;
|
||||||
|
|
||||||
|
public Venta(int id, Timestamp fechaVenta, int numeroAsiento, double precio) {
|
||||||
|
this.id = id;
|
||||||
|
this.fechaVenta = fechaVenta;
|
||||||
|
this.numeroAsiento = numeroAsiento;
|
||||||
|
this.precio = precio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getFechaVenta() {
|
||||||
|
return fechaVenta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumeroAsiento() {
|
||||||
|
return numeroAsiento;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPrecio() {
|
||||||
|
return precio;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,43 @@
|
||||||
|
package vista;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class VentaBoletosView extends JFrame {
|
||||||
|
private JPanel panelAsientos;
|
||||||
|
private JButton btnGenerarReporte;
|
||||||
|
|
||||||
|
public VentaBoletosView() {
|
||||||
|
super("Venta de Boletos");
|
||||||
|
setSize(600, 400);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
panelAsientos = new JPanel(new GridLayout(10, 10));
|
||||||
|
btnGenerarReporte = new JButton("Generar Reporte de Ventas");
|
||||||
|
|
||||||
|
add(panelAsientos, BorderLayout.CENTER);
|
||||||
|
add(btnGenerarReporte, BorderLayout.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel getPanelAsientos() {
|
||||||
|
return panelAsientos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JButton getBtnGenerarReporte() {
|
||||||
|
return btnGenerarReporte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void agregarBotonAsiento(JButton boton) {
|
||||||
|
panelAsientos.add(boton);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mostrarMensaje(String mensaje) {
|
||||||
|
JOptionPane.showMessageDialog(this, mensaje);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actualizarBotones() {
|
||||||
|
panelAsientos.revalidate();
|
||||||
|
panelAsientos.repaint();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE DATABASE venta_boletos;
|
||||||
|
|
||||||
|
USE venta_boletos;
|
||||||
|
|
||||||
|
CREATE TABLE asientos (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
numero_asiento INT NOT NULL,
|
||||||
|
disponible BOOLEAN NOT NULL DEFAULT TRUE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE ventas (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
fecha_venta DATETIME NOT NULL,
|
||||||
|
numero_asiento INT NOT NULL,
|
||||||
|
precio DECIMAL(10, 2) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO asientos (numero_asiento, disponible) VALUES
|
||||||
|
(101, true),
|
||||||
|
(102, false),
|
||||||
|
(103, true),
|
||||||
|
(104, true),
|
||||||
|
(105, false),
|
||||||
|
(106, true),
|
||||||
|
(107, true),
|
||||||
|
(108, false),
|
||||||
|
(109, true),
|
||||||
|
(110, true);
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<groupId>com.mycompany</groupId>
|
|
||||||
<artifactId>ticketCine</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.release>23</maven.compiler.release>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<!-- MySQL Connector -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>8.0.26</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>com.mycompany.ticketcine.MainApp</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
public class Asiento {
|
|
||||||
private int id;
|
|
||||||
private int idSala;
|
|
||||||
private int numeroAsiento;
|
|
||||||
private String estado;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
public Asiento(int id, int idSala, int numeroAsiento, String estado) {
|
|
||||||
this.id = id;
|
|
||||||
this.idSala = idSala;
|
|
||||||
this.numeroAsiento = numeroAsiento;
|
|
||||||
this.estado = estado;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdSala() {
|
|
||||||
return idSala;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdSala(int idSala) {
|
|
||||||
this.idSala = idSala;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumeroAsiento() {
|
|
||||||
return numeroAsiento;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumeroAsiento(int numeroAsiento) {
|
|
||||||
this.numeroAsiento = numeroAsiento;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEstado() {
|
|
||||||
return estado;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEstado(String estado) {
|
|
||||||
this.estado = estado;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,215 +0,0 @@
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
|
|
||||||
public class CompraBoletosApp {
|
|
||||||
private JFrame frame;
|
|
||||||
private JComboBox<String> peliculasComboBox;
|
|
||||||
private JComboBox<String> salasComboBox;
|
|
||||||
private JPanel asientosPanel;
|
|
||||||
private Map<Integer, JButton> asientosBotones;
|
|
||||||
|
|
||||||
public CompraBoletosApp() {
|
|
||||||
frame = new JFrame("Compra de Boletos");
|
|
||||||
frame.setSize(800, 600);
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JPanel topPanel = new JPanel();
|
|
||||||
peliculasComboBox = new JComboBox<>();
|
|
||||||
salasComboBox = new JComboBox<>();
|
|
||||||
topPanel.add(peliculasComboBox);
|
|
||||||
topPanel.add(salasComboBox);
|
|
||||||
frame.add(topPanel, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
asientosPanel = new JPanel(new GridLayout(5, 5, 5, 5));
|
|
||||||
frame.add(asientosPanel, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
JButton generarReporteButton = new JButton("Generar Reporte");
|
|
||||||
generarReporteButton.addActionListener(e -> generarReporteVentas());
|
|
||||||
JPanel bottomPanel = new JPanel();
|
|
||||||
bottomPanel.add(generarReporteButton);
|
|
||||||
frame.add(bottomPanel, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
cargarPeliculas();
|
|
||||||
cargarSalas();
|
|
||||||
|
|
||||||
salasComboBox.addActionListener(e -> cargarAsientos());
|
|
||||||
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cargarPeliculas() {
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
Statement statement = connection.createStatement();
|
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT nombre FROM peliculas");
|
|
||||||
while (resultSet.next()) {
|
|
||||||
peliculasComboBox.addItem(resultSet.getString("nombre"));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cargarSalas() {
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
Statement statement = connection.createStatement();
|
|
||||||
ResultSet resultSet = statement.executeQuery("SELECT nombre FROM salas");
|
|
||||||
while (resultSet.next()) {
|
|
||||||
salasComboBox.addItem(resultSet.getString("nombre"));
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cargarAsientos() {
|
|
||||||
asientosPanel.removeAll();
|
|
||||||
asientosBotones = new HashMap<>();
|
|
||||||
|
|
||||||
String peliculaSeleccionada = (String) peliculasComboBox.getSelectedItem();
|
|
||||||
String salaSeleccionada = (String) salasComboBox.getSelectedItem();
|
|
||||||
if (peliculaSeleccionada != null && salaSeleccionada != null) {
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
int idPelicula = obtenerIdPelicula(connection, peliculaSeleccionada);
|
|
||||||
int idSala = obtenerIdSala(connection, salaSeleccionada);
|
|
||||||
String query = "SELECT id_asiento, numero_asiento, estado FROM asientos WHERE id_sala = ?";
|
|
||||||
try (PreparedStatement statement = connection.prepareStatement(query)) {
|
|
||||||
statement.setInt(1, idSala);
|
|
||||||
try (ResultSet resultSet = statement.executeQuery()) {
|
|
||||||
while (resultSet.next()) {
|
|
||||||
int idAsiento = resultSet.getInt("id_asiento");
|
|
||||||
int numeroAsiento = resultSet.getInt("numero_asiento");
|
|
||||||
boolean disponible = "disponible".equals(resultSet.getString("estado"));
|
|
||||||
|
|
||||||
JButton asientoButton = new JButton(String.valueOf(numeroAsiento));
|
|
||||||
asientoButton.setEnabled(disponible);
|
|
||||||
asientoButton.addActionListener(e -> comprarBoleto(idAsiento, idPelicula, idSala, numeroAsiento));
|
|
||||||
|
|
||||||
asientosBotones.put(idAsiento, asientoButton);
|
|
||||||
asientosPanel.add(asientoButton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
JOptionPane.showMessageDialog(frame, "Error al cargar los asientos: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
asientosPanel.revalidate();
|
|
||||||
asientosPanel.repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void comprarBoleto(int idAsiento, int idPelicula, int idSala, int numeroAsiento) {
|
|
||||||
String peliculaSeleccionada = (String) peliculasComboBox.getSelectedItem();
|
|
||||||
String salaSeleccionada = (String) salasComboBox.getSelectedItem();
|
|
||||||
|
|
||||||
if (peliculaSeleccionada != null && salaSeleccionada != null) {
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
String query = "INSERT INTO ventas_boletos (id_asiento, id_pelicula) VALUES (?, ?)";
|
|
||||||
try (PreparedStatement statement = connection.prepareStatement(query)) {
|
|
||||||
statement.setInt(1, idAsiento);
|
|
||||||
statement.setInt(2, idPelicula);
|
|
||||||
statement.executeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
String updateQuery = "UPDATE asientos SET estado = 'vendido' WHERE id_asiento = ?";
|
|
||||||
try (PreparedStatement updateStatement = connection.prepareStatement(updateQuery)) {
|
|
||||||
updateStatement.setInt(1, idAsiento);
|
|
||||||
updateStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(frame, "Boleto comprado para " + peliculaSeleccionada +
|
|
||||||
" en " + salaSeleccionada + " (Asiento: " + numeroAsiento + ")");
|
|
||||||
|
|
||||||
JButton asientoButton = asientosBotones.get(idAsiento);
|
|
||||||
if (asientoButton != null) {
|
|
||||||
asientoButton.setEnabled(false);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
JOptionPane.showMessageDialog(frame, "Error al comprar el boleto: " + e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(frame, "Por favor, selecciona una película y sala.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generarReporteVentas() {
|
|
||||||
String[] columnNames = {"Película", "Sala", "Asiento", "Fecha de Venta"};
|
|
||||||
DefaultTableModel tableModel = new DefaultTableModel(columnNames, 0);
|
|
||||||
JTable table = new JTable(tableModel);
|
|
||||||
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
String query = "SELECT peliculas.nombre AS pelicula, salas.nombre AS sala, asientos.numero_asiento AS asiento, ventas_boletos.fecha_venta AS fecha " +
|
|
||||||
"FROM ventas_boletos " +
|
|
||||||
"JOIN asientos ON ventas_boletos.id_asiento = asientos.id_asiento " +
|
|
||||||
"JOIN peliculas ON ventas_boletos.id_pelicula = peliculas.id_pelicula " +
|
|
||||||
"JOIN salas ON asientos.id_sala = salas.id_sala";
|
|
||||||
try (Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery(query)) {
|
|
||||||
while (resultSet.next()) {
|
|
||||||
String pelicula = resultSet.getString("pelicula");
|
|
||||||
String sala = resultSet.getString("sala");
|
|
||||||
int asiento = resultSet.getInt("asiento");
|
|
||||||
Timestamp fechaVenta = resultSet.getTimestamp("fecha");
|
|
||||||
|
|
||||||
Object[] row = {pelicula, sala, asiento, fechaVenta};
|
|
||||||
tableModel.addRow(row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
JOptionPane.showMessageDialog(frame, "Error al generar el reporte: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(frame, new JScrollPane(table), "Reporte de Ventas de Boletos", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int obtenerIdPelicula(Connection connection, String nombrePelicula) throws SQLException {
|
|
||||||
String query = "SELECT id_pelicula FROM peliculas WHERE nombre = ?";
|
|
||||||
try (PreparedStatement statement = connection.prepareStatement(query)) {
|
|
||||||
statement.setString(1, nombrePelicula);
|
|
||||||
try (ResultSet resultSet = statement.executeQuery()) {
|
|
||||||
if (resultSet.next()) {
|
|
||||||
return resultSet.getInt("id_pelicula");
|
|
||||||
} else {
|
|
||||||
throw new SQLException("No se encontró la película: " + nombrePelicula);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int obtenerIdSala(Connection connection, String nombreSala) throws SQLException {
|
|
||||||
String query = "SELECT id_sala FROM salas WHERE nombre = ?";
|
|
||||||
try (PreparedStatement statement = connection.prepareStatement(query)) {
|
|
||||||
statement.setString(1, nombreSala);
|
|
||||||
try (ResultSet resultSet = statement.executeQuery()) {
|
|
||||||
if (resultSet.next()) {
|
|
||||||
return resultSet.getInt("id_sala");
|
|
||||||
} else {
|
|
||||||
throw new SQLException("No se encontró la sala: " + nombreSala);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DatabaseConnection {
|
|
||||||
private static final String URL = "jdbc:mysql://localhost:3306/cine";
|
|
||||||
private static final String USER = "root";
|
|
||||||
private static final String PASSWORD = "4560";
|
|
||||||
|
|
||||||
public static Connection getConnection() throws SQLException {
|
|
||||||
return DriverManager.getConnection(URL, USER, PASSWORD);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
public class MainApp {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// Inicializa la aplicación de compra de boletos
|
|
||||||
new CompraBoletosApp();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
public class Pelicula {
|
|
||||||
private int id;
|
|
||||||
private String nombre;
|
|
||||||
private int duracion;
|
|
||||||
private String genero;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
public Pelicula(int id, String nombre, int duracion, String genero) {
|
|
||||||
this.id = id;
|
|
||||||
this.nombre = nombre;
|
|
||||||
this.duracion = duracion;
|
|
||||||
this.genero = genero;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNombre() {
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNombre(String nombre) {
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDuracion() {
|
|
||||||
return duracion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDuracion(int duracion) {
|
|
||||||
this.duracion = duracion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGenero() {
|
|
||||||
return genero;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGenero(String genero) {
|
|
||||||
this.genero = genero;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
public class Sala {
|
|
||||||
private int id;
|
|
||||||
private String nombre;
|
|
||||||
private int capacidad;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
public Sala(int id, String nombre, int capacidad) {
|
|
||||||
this.id = id;
|
|
||||||
this.nombre = nombre;
|
|
||||||
this.capacidad = capacidad;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getNombre() {
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNombre(String nombre) {
|
|
||||||
this.nombre = nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCapacidad() {
|
|
||||||
return capacidad;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCapacidad(int capacidad) {
|
|
||||||
this.capacidad = capacidad;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
|
||||||
*/
|
|
||||||
package com.mycompany.ticketcine;
|
|
||||||
|
|
||||||
public class VentaBoleto {
|
|
||||||
private int id;
|
|
||||||
private int idAsiento;
|
|
||||||
private int idPelicula;
|
|
||||||
private String fechaVenta;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
public VentaBoleto(int id, int idAsiento, int idPelicula, String fechaVenta) {
|
|
||||||
this.id = id;
|
|
||||||
this.idAsiento = idAsiento;
|
|
||||||
this.idPelicula = idPelicula;
|
|
||||||
this.fechaVenta = fechaVenta;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdAsiento() {
|
|
||||||
return idAsiento;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdAsiento(int idAsiento) {
|
|
||||||
this.idAsiento = idAsiento;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIdPelicula() {
|
|
||||||
return idPelicula;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdPelicula(int idPelicula) {
|
|
||||||
this.idPelicula = idPelicula;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFechaVenta() {
|
|
||||||
return fechaVenta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFechaVenta(String fechaVenta) {
|
|
||||||
this.fechaVenta = fechaVenta;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\Asiento.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\CompraBoletosApp.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\DatabaseConnection.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\MainApp.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\Pelicula.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\Sala.java
|
|
||||||
C:\Users\Tron7\Documents\DesarrolloSoftware\v\VentaBoletos\NetBeansProjects\ticketCine\src\main\java\com\mycompany\ticketcine\VentaBoleto.java
|
|
Loading…
Reference in New Issue