-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from nicomencia/VerRegistro
Visualizar tabla registro finalizado
- Loading branch information
Showing
7 changed files
with
279 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
IPS_l33_Sprint1/src/pgh/business/registro/FindAllRegistros.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
41
IPS_l33_Sprint1/src/pgh/business/registro/ListaRegistros.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
IPS_l33_Sprint1/src/pgh/business/registro/RegistroDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |