diff --git a/NetBeansProjects/ticketCine/.vscode/settings.json b/NetBeansProjects/ticketCine/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/NetBeansProjects/ticketCine/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/CompraBoletosApp.java b/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/CompraBoletosApp.java index 390c84c..928d586 100644 --- a/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/CompraBoletosApp.java +++ b/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/CompraBoletosApp.java @@ -1,13 +1,25 @@ package com.mycompany.ticketcine; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.sql.*; +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; @@ -17,7 +29,7 @@ public class CompraBoletosApp { public CompraBoletosApp() { frame = new JFrame("Compra de Boletos"); - frame.setSize(500, 500); + frame.setSize(800, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); @@ -31,6 +43,12 @@ public class CompraBoletosApp { 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(); @@ -67,9 +85,11 @@ public class CompraBoletosApp { asientosPanel.removeAll(); asientosBotones = new HashMap<>(); + String peliculaSeleccionada = (String) peliculasComboBox.getSelectedItem(); String salaSeleccionada = (String) salasComboBox.getSelectedItem(); - if (salaSeleccionada != null) { + 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)) { @@ -82,7 +102,7 @@ public class CompraBoletosApp { JButton asientoButton = new JButton(String.valueOf(numeroAsiento)); asientoButton.setEnabled(disponible); - asientoButton.addActionListener(e -> comprarBoleto(idAsiento, numeroAsiento)); + asientoButton.addActionListener(e -> comprarBoleto(idAsiento, idPelicula, idSala, numeroAsiento)); asientosBotones.put(idAsiento, asientoButton); asientosPanel.add(asientoButton); @@ -98,14 +118,12 @@ public class CompraBoletosApp { asientosPanel.repaint(); } - private void comprarBoleto(int idAsiento, int numeroAsiento) { + 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()) { - int idPelicula = obtenerIdPelicula(connection, peliculaSeleccionada); - String query = "INSERT INTO ventas_boletos (id_asiento, id_pelicula) VALUES (?, ?)"; try (PreparedStatement statement = connection.prepareStatement(query)) { statement.setInt(1, idAsiento); @@ -135,6 +153,36 @@ public class CompraBoletosApp { } } + 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)) { @@ -162,4 +210,6 @@ public class CompraBoletosApp { } } } -} + + +} \ No newline at end of file diff --git a/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/DatabaseConnection.java b/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/DatabaseConnection.java index d7dbf69..2d8a322 100644 --- a/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/DatabaseConnection.java +++ b/NetBeansProjects/ticketCine/src/main/java/com/mycompany/ticketcine/DatabaseConnection.java @@ -7,7 +7,7 @@ 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 = "qwerty"; + private static final String PASSWORD = "4560"; public static Connection getConnection() throws SQLException { return DriverManager.getConnection(URL, USER, PASSWORD); diff --git a/NetBeansProjects/ticketCine/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/NetBeansProjects/ticketCine/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..04cdbb7 --- /dev/null +++ b/NetBeansProjects/ticketCine/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,7 @@ +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 diff --git a/docker-hub.md b/docker-hub.md deleted file mode 100644 index 13e0246..0000000 --- a/docker-hub.md +++ /dev/null @@ -1 +0,0 @@ -aldovh22