Skip to content

Commit

Permalink
Merge pull request #36 from nicomencia/VerRegistro
Browse files Browse the repository at this point in the history
Visualizar tabla registro finalizado
  • Loading branch information
nicomencia authored Nov 29, 2020
2 parents 0438a34 + a625b10 commit d3ca439
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.ArrayList;
import java.util.List;

import pgh.business.cita.CitaDTO;
import pgh.jdbc.Database;

public class FindAllMedicoCita {
Expand Down
48 changes: 48 additions & 0 deletions IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java
Original file line number Diff line number Diff line change
@@ -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<RegistroDTO> execute() {
List<RegistroDTO> registros = new ArrayList<RegistroDTO>();

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;
}
}
41 changes: 41 additions & 0 deletions IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package pgh.business.registro;

import java.util.ArrayList;
import java.util.List;

public class ListaRegistros {

List<Registro> registros = new ArrayList<Registro>();
List<RegistroDTO> result ;

public ListaRegistros() {

result = new FindAllRegistros().execute();

}

public List<Registro> 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);
}

}

}
32 changes: 32 additions & 0 deletions IPS_l33_Sprint1/src/pgh/business/registro/Registro.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
10 changes: 10 additions & 0 deletions IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pgh.business.registro;

import java.sql.Date;

public class RegistroDTO {

public int idRegistro;
public Date fecha;
public String descripcion;
}
24 changes: 22 additions & 2 deletions IPS_l33_Sprint1/src/pgh/ui/VentanaPrincipal.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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;
Expand Down Expand Up @@ -95,6 +96,7 @@ public class VentanaPrincipal extends JFrame {
private DefaultListModel<Medico> modeloListaMedicosLogueados;
private JButton btnNewButton;
private JButton btnComprobarVacacionesSolicitadas;
private JButton btnAuditor;
private List<NodoMayor> nodos;
private NodoMayor raiz;

Expand Down Expand Up @@ -159,6 +161,7 @@ private JPanel getPanelPrincipal() {
panelPrincipal.add(getBtnAdministrativo());
panelPrincipal.add(getBtnEntrarComoMdico());
panelPrincipal.add(getBtnAdministrativo_1_1());
panelPrincipal.add(getBtnAuditor());
}
return panelPrincipal;
}
Expand Down Expand Up @@ -496,6 +499,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;
}
}
126 changes: 126 additions & 0 deletions IPS_l33_Sprint1/src/pgh/ui/paneles/PanelAuditor.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit d3ca439

Please sign in to comment.