mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
feat(examen 9-5-25): agregado segundo panel
This commit is contained in:
@@ -6,6 +6,8 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
|
||||
@@ -149,6 +151,41 @@ public class ControladorConcierto {
|
||||
return registroAfectados;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idSala
|
||||
* @return
|
||||
*/
|
||||
public static List<String> findConciertosPorSalaYNombreGrupo (
|
||||
int idSala, String nombreGrupo) {
|
||||
|
||||
List<String> lista = new ArrayList<String>();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
try {
|
||||
Connection conn = ConnectionManager.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement(
|
||||
"SELECT c.*, s.nombre as nombre_sala, g.nombre as nombre_grupo "
|
||||
+ "FROM concierto c "
|
||||
+ "inner join sala s on c.sala_id = s.id "
|
||||
+ "inner join grupo g on c.grupo_id = g.id "
|
||||
+ "where c.sala_id = ? "
|
||||
+ "and g.nombre like ?");
|
||||
ps.setInt(1, idSala);
|
||||
ps.setString(2, "%" + nombreGrupo + "%");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
String fecha = sdf.format(rs.getDate("fecha"));
|
||||
String s = fecha + " - "
|
||||
+ rs.getString("nombre_grupo") + " - "
|
||||
+ rs.getString("nombre_sala");
|
||||
lista.add(s);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return lista;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
package tutorialJava.examenes.examen20250509.vista;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.GridBagLayout;
|
||||
import javax.swing.JComboBox;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Insets;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorConcierto;
|
||||
import tutorialJava.examenes.examen20250509.controlador.ControladorSala;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Concierto;
|
||||
import tutorialJava.examenes.examen20250509.modelo.Sala;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JList;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class PanelFiltradoConciertos extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JTextField jtfNombreGrupo;
|
||||
private JTextField jtfAgregar;
|
||||
JComboBox<Sala> jcbSalas;
|
||||
DefaultListModel<String> dlmConciertos =
|
||||
new DefaultListModel<String>();
|
||||
|
||||
/**
|
||||
* Create the panel.
|
||||
*/
|
||||
public PanelFiltradoConciertos() {
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
gridBagLayout.columnWidths = new int[]{0, 0, 0, 0};
|
||||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
|
||||
gridBagLayout.columnWeights = new double[]{0.0, 1.0, 1.0, Double.MIN_VALUE};
|
||||
gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||
setLayout(gridBagLayout);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("Filtrado de conciertos");
|
||||
lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
|
||||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||||
gbc_lblNewLabel.gridwidth = 3;
|
||||
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel.gridx = 0;
|
||||
gbc_lblNewLabel.gridy = 0;
|
||||
add(lblNewLabel, gbc_lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Sala del concierto");
|
||||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_1.gridx = 0;
|
||||
gbc_lblNewLabel_1.gridy = 1;
|
||||
add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||
|
||||
jcbSalas = new JComboBox<Sala>();
|
||||
GridBagConstraints gbc_jcbSalas = new GridBagConstraints();
|
||||
gbc_jcbSalas.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jcbSalas.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jcbSalas.gridx = 1;
|
||||
gbc_jcbSalas.gridy = 1;
|
||||
add(jcbSalas, gbc_jcbSalas);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("Nombre del grupo:");
|
||||
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||
gbc_lblNewLabel_2.gridx = 0;
|
||||
gbc_lblNewLabel_2.gridy = 2;
|
||||
add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||
|
||||
jtfNombreGrupo = new JTextField();
|
||||
GridBagConstraints gbc_jtfNombreGrupo = new GridBagConstraints();
|
||||
gbc_jtfNombreGrupo.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_jtfNombreGrupo.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfNombreGrupo.gridx = 1;
|
||||
gbc_jtfNombreGrupo.gridy = 2;
|
||||
add(jtfNombreGrupo, gbc_jtfNombreGrupo);
|
||||
jtfNombreGrupo.setColumns(10);
|
||||
|
||||
JButton btnBuscar = new JButton("Buscar");
|
||||
btnBuscar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
filtrar();
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnBuscar = new GridBagConstraints();
|
||||
gbc_btnBuscar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnBuscar.gridx = 2;
|
||||
gbc_btnBuscar.gridy = 2;
|
||||
add(btnBuscar, gbc_btnBuscar);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridheight = 3;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 1;
|
||||
gbc_scrollPane.gridy = 3;
|
||||
add(scrollPane, gbc_scrollPane);
|
||||
|
||||
JList jlistConciertos = new JList(dlmConciertos);
|
||||
scrollPane.setViewportView(jlistConciertos);
|
||||
|
||||
JButton btnEliminar = new JButton("Eliminar");
|
||||
GridBagConstraints gbc_btnEliminar = new GridBagConstraints();
|
||||
gbc_btnEliminar.anchor = GridBagConstraints.SOUTH;
|
||||
gbc_btnEliminar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_btnEliminar.gridx = 2;
|
||||
gbc_btnEliminar.gridy = 3;
|
||||
add(btnEliminar, gbc_btnEliminar);
|
||||
|
||||
jtfAgregar = new JTextField();
|
||||
GridBagConstraints gbc_jtfAgregar = new GridBagConstraints();
|
||||
gbc_jtfAgregar.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_jtfAgregar.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbc_jtfAgregar.gridx = 2;
|
||||
gbc_jtfAgregar.gridy = 4;
|
||||
add(jtfAgregar, gbc_jtfAgregar);
|
||||
jtfAgregar.setColumns(10);
|
||||
|
||||
JButton btnAgregar = new JButton("Agregar");
|
||||
btnAgregar.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (jtfAgregar.getText().length() > 0) {
|
||||
dlmConciertos.addElement(jtfAgregar.getText());
|
||||
}
|
||||
}
|
||||
});
|
||||
GridBagConstraints gbc_btnAgregar = new GridBagConstraints();
|
||||
gbc_btnAgregar.gridx = 2;
|
||||
gbc_btnAgregar.gridy = 5;
|
||||
add(btnAgregar, gbc_btnAgregar);
|
||||
|
||||
|
||||
cargaTodasLasSalas();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void cargaTodasLasSalas() {
|
||||
List<Sala> salas = ControladorSala.findAll();
|
||||
for (Sala s : salas) {
|
||||
jcbSalas.addItem(s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void filtrar() {
|
||||
Sala salaSeleccionada = (Sala) jcbSalas.getSelectedItem();
|
||||
List<String> conciertosFiltrados =
|
||||
ControladorConcierto.findConciertosPorSalaYNombreGrupo(
|
||||
salaSeleccionada.getId(),
|
||||
jtfNombreGrupo.getText());
|
||||
dlmConciertos.removeAllElements();
|
||||
dlmConciertos.addAll(conciertosFiltrados);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -383,6 +383,23 @@ public class PanelGestionConciertos extends JPanel {
|
||||
}
|
||||
else if (registrosAfectados == 1) {
|
||||
JOptionPane.showMessageDialog(null, "Eliminado correctamente");
|
||||
|
||||
Concierto conciertoAnterior =
|
||||
ControladorConcierto.getAnterior(idConcierto);
|
||||
// Si elimino correctamente, intento mostrar el anterior
|
||||
if (conciertoAnterior != null) {
|
||||
mostrarConciertoEnPantalla(conciertoAnterior);
|
||||
}
|
||||
else { // No existe un anterior, intento mostrar el siguiente
|
||||
Concierto conciertoSiguiente =
|
||||
ControladorConcierto.getSiguiente(idConcierto);
|
||||
if (conciertoSiguiente != null) {
|
||||
mostrarConciertoEnPantalla(conciertoSiguiente);
|
||||
}
|
||||
else { // No tiene concierto anterior ni siguiente
|
||||
nuevo();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ public class VentanaPrincipal extends JFrame {
|
||||
contentPane.add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
PanelGestionConciertos panel1 = new PanelGestionConciertos();
|
||||
tabbedPane.addTab("New tab", null, panel1, null);
|
||||
tabbedPane.addTab("Gestión de conciertos", null, panel1, null);
|
||||
|
||||
JPanel panel2 = new JPanel();
|
||||
tabbedPane.addTab("New tab", null, panel2, null);
|
||||
PanelFiltradoConciertos panel2 = new PanelFiltradoConciertos();
|
||||
tabbedPane.addTab("Filtrado de conciertos", null, panel2, null);
|
||||
|
||||
JPanel panel3 = new JPanel();
|
||||
tabbedPane.addTab("New tab", null, panel3, null);
|
||||
|
||||
Reference in New Issue
Block a user