From df0e51e30190e5562624a51a144a516a9c397aa3 Mon Sep 17 00:00:00 2001 From: nicomencia Date: Mon, 30 Nov 2020 00:35:21 +0100 Subject: [PATCH] Visualizar tabla registro finalizado --- .../medicocita/FindAllMedicoCita.java | 1 - .../business/registro/FindAllRegistros.java | 48 +++++++ .../pgh/business/registro/ListaRegistros.java | 41 ++++++ .../src/pgh/business/registro/Registro.java | 32 +++++ .../pgh/business/registro/RegistroDTO.java | 10 ++ .../src/pgh/ui/VentanaPrincipal.java | 24 +++- .../src/pgh/ui/paneles/PanelAuditor.java | 126 ++++++++++++++++++ 7 files changed, 279 insertions(+), 3 deletions(-) create mode 100644 IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java create mode 100644 IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java create mode 100644 IPS_l33_Sprint1/src/pgh/business/registro/Registro.java create mode 100644 IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java create mode 100644 IPS_l33_Sprint1/src/pgh/ui/paneles/PanelAuditor.java diff --git a/IPS_l33_Sprint1/src/pgh/business/medicocita/FindAllMedicoCita.java b/IPS_l33_Sprint1/src/pgh/business/medicocita/FindAllMedicoCita.java index da6e4ba..c5fc947 100644 --- a/IPS_l33_Sprint1/src/pgh/business/medicocita/FindAllMedicoCita.java +++ b/IPS_l33_Sprint1/src/pgh/business/medicocita/FindAllMedicoCita.java @@ -7,7 +7,6 @@ import java.util.ArrayList; import java.util.List; -import pgh.business.cita.CitaDTO; import pgh.jdbc.Database; public class FindAllMedicoCita { diff --git a/IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java b/IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java new file mode 100644 index 0000000..86b36f4 --- /dev/null +++ b/IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java @@ -0,0 +1,48 @@ +package pgh.business.registro; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import pgh.jdbc.Database; + +public class FindAllRegistros { + + private static String SQL = "SELECT idregistro, fecha, descripcion FROM registro"; + + Database db = new Database(); + + public List execute() { + List registros = new ArrayList(); + + Connection c = null; + PreparedStatement pst = null; + ResultSet rs = null; + + try { + c = db.getConnection(); + + pst = c.prepareStatement(SQL); + + rs = pst.executeQuery(); + registros = new ArrayList<>(); + while(rs.next()) { + RegistroDTO registro = new RegistroDTO(); + registro.idRegistro=rs.getInt("idregistro"); + registro.fecha=rs.getDate("fecha"); + registro.descripcion=rs.getString("descripcion"); + registros.add(registro); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + finally { + db.close(rs, pst, c); + } + + return registros; + } +} diff --git a/IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java b/IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java new file mode 100644 index 0000000..a88908f --- /dev/null +++ b/IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java @@ -0,0 +1,41 @@ +package pgh.business.registro; + +import java.util.ArrayList; +import java.util.List; + +public class ListaRegistros { + + List registros = new ArrayList(); + List result ; + + public ListaRegistros() { + + result = new FindAllRegistros().execute(); + + } + + public List getRegistros(){ + return registros; + } + + + public void creaListaRegistros() { + + for(RegistroDTO r : result) { + Registro registro = new Registro(r); + registros.add(registro); + } + } + + + public void listarRegistros() { + + for(RegistroDTO r : result) { + System.out.println(r.idRegistro); + System.out.println(r.fecha); + System.out.println(r.descripcion); + } + + } + +} diff --git a/IPS_l33_Sprint1/src/pgh/business/registro/Registro.java b/IPS_l33_Sprint1/src/pgh/business/registro/Registro.java new file mode 100644 index 0000000..8be84e9 --- /dev/null +++ b/IPS_l33_Sprint1/src/pgh/business/registro/Registro.java @@ -0,0 +1,32 @@ +package pgh.business.registro; + +import java.sql.Date; + +public class Registro { + +private RegistroDTO reg; + + public Registro(RegistroDTO registro) { + + this.reg = registro; + + } + + public int getIdRegistro() { + + return reg.idRegistro; + + } + + public Date getFecha() { + + return reg.fecha; + + } + + public String getDescripcion() { + + return reg.descripcion; + } + +} diff --git a/IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java b/IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java new file mode 100644 index 0000000..c0a027b --- /dev/null +++ b/IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java @@ -0,0 +1,10 @@ +package pgh.business.registro; + +import java.sql.Date; + +public class RegistroDTO { + + public int idRegistro; + public Date fecha; + public String descripcion; +} diff --git a/IPS_l33_Sprint1/src/pgh/ui/VentanaPrincipal.java b/IPS_l33_Sprint1/src/pgh/ui/VentanaPrincipal.java index 148b2ba..24c20f7 100644 --- a/IPS_l33_Sprint1/src/pgh/ui/VentanaPrincipal.java +++ b/IPS_l33_Sprint1/src/pgh/ui/VentanaPrincipal.java @@ -32,6 +32,7 @@ import pgh.business.prescripcion.ListaPrescripciones; import pgh.business.prescripcion.Prescripcion; import pgh.ui.paneles.PanelAdministrativo; +import pgh.ui.paneles.PanelAuditor; import pgh.ui.paneles.PanelLoginEnfermero; import pgh.ui.paneles.PanelMedico; import pgh.ui.paneles.filtros.JListFiltroLoginMedico; @@ -91,6 +92,7 @@ public class VentanaPrincipal extends JFrame { private DefaultListModel modeloListaMedicosLogueados; private JButton btnNewButton; private JButton btnComprobarVacacionesSolicitadas; + private JButton btnAuditor; @@ -151,6 +153,7 @@ private JPanel getPanelPrincipal() { panelPrincipal.add(getBtnAdministrativo()); panelPrincipal.add(getBtnEntrarComoMdico()); panelPrincipal.add(getBtnAdministrativo_1_1()); + panelPrincipal.add(getBtnAuditor()); } return panelPrincipal; } @@ -488,6 +491,23 @@ public void actionPerformed(ActionEvent e) { } return btnSalirPanelMedico; } - - + private JButton getBtnAuditor() { + if (btnAuditor == null) { + btnAuditor = new JButton("Entrar como auditor"); + btnAuditor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + PanelAuditor panel = new PanelAuditor(panelPrincipal,panelContenido); + panelContenido.add(panel); + panelPrincipal.setVisible(false); + panel.setVisible(true); + } + }); + btnAuditor.setForeground(Color.WHITE); + btnAuditor.setFont(new Font("Tahoma", Font.PLAIN, 20)); + btnAuditor.setFocusable(false); + btnAuditor.setBackground(Color.RED); + btnAuditor.setBounds(362, 459, 286, 52); + } + return btnAuditor; + } } diff --git a/IPS_l33_Sprint1/src/pgh/ui/paneles/PanelAuditor.java b/IPS_l33_Sprint1/src/pgh/ui/paneles/PanelAuditor.java new file mode 100644 index 0000000..f2def8a --- /dev/null +++ b/IPS_l33_Sprint1/src/pgh/ui/paneles/PanelAuditor.java @@ -0,0 +1,126 @@ +package pgh.ui.paneles; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JLabel; +import javax.swing.JTable; +import javax.swing.border.BevelBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.table.DefaultTableModel; + +import pgh.business.registro.ListaRegistros; +import pgh.business.registro.Registro; +import javax.swing.JScrollPane; + +public class PanelAuditor extends JPanel { + + private JPanel panelAnterior; + private JPanel panelContenido; + private JPanel panelAuditor; + private JButton btnSalir; + private JLabel lblRegistro; + private JTable tableRegistro; + + + public PanelAuditor (JPanel panelAnterior, JPanel panelContenido) { + + this.panelAnterior = panelAnterior; + this.panelContenido = panelContenido; + panelAuditor = this; + getPanelAuditor(); + + } + + private JPanel getPanelAuditor() { + + this.setBackground(Color.WHITE); + this.setLayout(null); + this.add(getBtnSalir()); + add(getLblRegistro()); + add(getScrollPane()); + + return panelAuditor; + } + + private JButton getBtnSalir() { + if (btnSalir == null) { + btnSalir = new JButton("Salir"); + btnSalir.setFocusable(false); + btnSalir.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + closePanel(); + } + }); + btnSalir.setBounds(1008, 580, 115, 38); + } + return btnSalir; + } + + protected void closePanel() { + this.setVisible(false); + this.panelAnterior.setVisible(true); + } + private JLabel getLblRegistro() { + if (lblRegistro == null) { + lblRegistro = new JLabel("Registro"); + lblRegistro.setFont(new Font("Sitka Small", Font.PLAIN, 35)); + lblRegistro.setBounds(496, -4, 163, 68); + } + return lblRegistro; + } + + DefaultTableModel modelo = new DefaultTableModel() { + private static final long serialVersionUID = 1L; + }; + private JScrollPane scrollPane; + + private JTable getTableRegistro() { + if (tableRegistro == null) { + tableRegistro = new JTable(); + tableRegistro.setModel(modelo); + + modelo.addColumn("ID"); + modelo.addColumn("FECHA"); + modelo.addColumn("DESCRIPCION"); + + tableRegistro.getColumnModel().getColumn(0).setPreferredWidth(55); + tableRegistro.getColumnModel().getColumn(1).setPreferredWidth(100); + tableRegistro.getColumnModel().getColumn(2).setPreferredWidth(1000); + tableRegistro.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); + + cargarDatosTabla(); + } + return tableRegistro; + } + + private void cargarDatosTabla() { + + ListaRegistros lr = new ListaRegistros(); + lr.creaListaRegistros(); + + for(Registro r : lr.getRegistros()) { + Object[] registro = new Object[3]; + registro[0] = r.getIdRegistro(); + registro[1] = r.getFecha(); + registro[2] = r.getDescripcion(); + + modelo.addRow(registro); + } + + } + + private JScrollPane getScrollPane() { + if (scrollPane == null) { + scrollPane = new JScrollPane(); + scrollPane.setBackground(Color.WHITE); + scrollPane.setBounds(10, 75, 1155, 480); + scrollPane.setViewportView(getTableRegistro()); + } + return scrollPane; + } +}