Plaza de Estacionamiento
El programa gestiona una plaza de estacionamiento, registrando los autos que estan estacionados y posteriormente guardando los datos es un archivo historial para llevar un registro de la actividad.
Tanto al ingresar como al salir un coche del estacionamiento se impreme un ticket con los datos de la ubicacion del vehiculo. Si se trata del ticket de salida se muestra el importe pagado.
Cabe destacar que los datos de la hora de ingreso como la de salida se guardan en la base de datos como un double (que se obtiene del metodo getTime() de la clase java.util.Date) para luego ser recuperado desde el programa y asi calcular el tiempo que estuvo estacionado el coche.
El tipo de auto puede ser 'G' grande, 'P' pequeño o 'M' mediano.
Para el proyecto use una base de datos con tres tablas: cocheras, historico y tarifas, que se muestran abajo respectivemente
El siguiente .rar tiene el .jar ejecutable y el script para generar la base de datos.
Para ejecutar: en consola escribir java -jar plazadeestacionamiento.jar
https://drive.google.com/file/d/0B0sBXdZ8aJgdb1d2MGpkM1h5dk0/edit?usp=sharing
Tanto al ingresar como al salir un coche del estacionamiento se impreme un ticket con los datos de la ubicacion del vehiculo. Si se trata del ticket de salida se muestra el importe pagado.
Cabe destacar que los datos de la hora de ingreso como la de salida se guardan en la base de datos como un double (que se obtiene del metodo getTime() de la clase java.util.Date) para luego ser recuperado desde el programa y asi calcular el tiempo que estuvo estacionado el coche.
El tipo de auto puede ser 'G' grande, 'P' pequeño o 'M' mediano.
Para el proyecto use una base de datos con tres tablas: cocheras, historico y tarifas, que se muestran abajo respectivemente
HistoricoBean.java
package com.dansan.bean;
/**
*
* @author dansan
*/
public class HistoricoBean {
private String patente;
private double hora_ocupacion;
private char tipo_auto;
private int piso;
private double hora_salida;
private double importe;
/**
* @return the patente
*/
public String getPatente() {
return patente;
}
/**
* @param patente the patente to set
*/
public void setPatente(String patente) {
this.patente = patente;
}
/**
* @return the hora_ocupacion
*/
public double getHora_ocupacion() {
return hora_ocupacion;
}
/**
* @param hora_ocupacion the hora_ocupacion to set
*/
public void setHora_ocupacion(double hora_ocupacion) {
this.hora_ocupacion = hora_ocupacion;
}
/**
* @return the tipo_auto
*/
public char getTipo_auto() {
return tipo_auto;
}
/**
* @param tipo_auto the tipo_auto to set
*/
public void setTipo_auto(char tipo_auto) {
this.tipo_auto = tipo_auto;
}
/**
* @return the piso
*/
public int getPiso() {
return piso;
}
/**
* @param piso the piso to set
*/
public void setPiso(int piso) {
this.piso = piso;
}
/**
* @return the hora_salida
*/
public double getHora_salida() {
return hora_salida;
}
/**
* @param hora_salida the hora_salida to set
*/
public void setHora_salida(double hora_salida) {
this.hora_salida = hora_salida;
}
/**
* @return the importe
*/
public double getImporte() {
return importe;
}
/**
* @param importe the importe to set
*/
public void setImporte(double importe) {
this.importe = importe;
}
}
BDManagement.java
package com.dansan.database;
import com.dansan.bean.HistoricoBean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author dansan
*/
public class BDManagement {
private String username = "root";
private String password = "riverplate";
private String db = "jdbc:mysql://localhost:3306/plaza_estacionamiento";
private String driver = "com.mysql.jdbc.Driver";
private Connection conexion;
private Statement st;
// Se crea la conexion a la base plaza_estacionamiento
public BDManagement() {
try {
Class.forName(driver);
conexion = DriverManager.getConnection(db, username, password);
st = conexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* Metodos de la tabla tarifa
*/
public double obtenerTarifa(char c) {
double tarifa = 0;
String pedido = "select * from tarifas where tipo_auto='" + c + "'";
try {
ResultSet rs = st.executeQuery(pedido);
if (rs.next()) {
tarifa = (double) rs.getObject("tarifa");
}
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return tarifa;
}
public ResultSet listarTarifas() {
ResultSet rs = null;
String pedido = "select * from tarifas";
try {
rs = st.executeQuery(pedido);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
/**
* Metodos de la tabla cochera
*/
public ResultSet listarCocheras() {
ResultSet rs = null;
String pedido = "select * from cocheras";
try {
rs = st.executeQuery(pedido);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
public int numCochesEnCocheras(int piso) {
int total = 0;
ResultSet rs=null;
String pedido = "select count(*) as total from cocheras where piso="+piso;
try {
rs = st.executeQuery(pedido);
while(rs.next()){
total = rs.getInt("total");
}
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return total;
}
public HistoricoBean obtenerCoche(String patente) {
HistoricoBean bean = new HistoricoBean();
try {
String query = "select * from cocheras where patente='" + patente + "'";
ResultSet rs = st.executeQuery(query);
if (rs.next()) {
bean.setPatente(rs.getString("patente"));
bean.setHora_ocupacion(rs.getDouble("hora_ocupacion"));
String cad = (String) rs.getObject("tipo_auto");
char c = cad.charAt(0);
bean.setTipo_auto(c);
bean.setPiso(rs.getInt("piso"));
}
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return bean;
}
public ArrayList obtenerCoche(int piso) {
ArrayList beanes = new ArrayList();
try {
String query = "select * from cocheras where piso=" + piso;
ResultSet rs = st.executeQuery(query);
rs.beforeFirst();
while (rs.next()) {
HistoricoBean bean = new HistoricoBean();
bean.setPatente(rs.getString("patente"));
bean.setHora_ocupacion(rs.getDouble("hora_ocupacion"));
String cad = (String) rs.getObject("tipo_auto");
char c = cad.charAt(0);
bean.setTipo_auto(c);
bean.setPiso(rs.getInt("piso"));
beanes.add(bean);
}
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return beanes;
}
public void agregarCocheras(String patente, int piso, char tipo) {
Date date = new Date();
double fecha = date.getTime();
String query = "insert into cocheras (patente,hora_ocupacion,tipo_auto,piso) ";
query += "values('" + patente + "','" + fecha + "','" + tipo + "','" + piso + "')";
try {
st.executeUpdate(query);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void borrarCocheras(String patente) {
String query = "delete from cocheras where patente = '" + patente + "'";
try {
st.executeUpdate(query);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Metodos de la tabla historico
*/
public ResultSet listarHistorico() {
ResultSet rs = null;
String query = "select * from historico";
try {
rs = st.executeQuery(query);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
return rs;
}
public void grabarHistorico(String patente, double hora_ocupacion, char tipo, int piso, double importe) {
Date date = new Date();
double fecha = date.getTime();
String query = "";
query += "insert into historico (patente,hora_ocupacion,tipo_auto,piso,hora_salida,importe) ";
query += "values('" + patente + "','" + hora_ocupacion + "','" + tipo + "','" + piso + "','" + fecha + "','" + importe + "')";
try {
st.executeUpdate(query);
} catch (SQLException ex) {
Logger.getLogger(BDManagement.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
FechaHora.java
package com.dansan.fechahora;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author dansan
*/
public class FechaHora {
private Date date;
private String fecha_hora;
public FechaHora(Date date) {
this.date = date;
}
public String obtenerFechaHora() {
fecha_hora = "";
String formato = "dd";
SimpleDateFormat dateFormat3 = new SimpleDateFormat(formato);
fecha_hora += Integer.parseInt(dateFormat3.format(date));
fecha_hora += "/";
formato = "MM";
SimpleDateFormat dateFormat2 = new SimpleDateFormat(formato);
fecha_hora += Integer.parseInt(dateFormat2.format(date));;
fecha_hora += "/";
formato = "yyyy";
SimpleDateFormat dateFormat = new SimpleDateFormat(formato);
fecha_hora += Integer.parseInt(dateFormat.format(date));
fecha_hora += " ";
if (date.getHours() < 0) {
fecha_hora += "0";
}
fecha_hora += date.getHours();
fecha_hora += ":";
if (date.getMinutes() < 0) {
fecha_hora += "0";
}
fecha_hora += date.getMinutes();
fecha_hora += ":";
if (date.getSeconds() < 0) {
fecha_hora += "0";
}
fecha_hora += date.getSeconds();
return fecha_hora;
}
}
VentanaPrincipal.java
package com.dansan.frontend;
/**
*
* @author dansan
*/
public class VentanaPrincipal extends javax.swing.JFrame {
public VentanaPrincipal() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
btnEntrada = new javax.swing.JButton();
btnSalida = new javax.swing.JButton();
btnInformes = new javax.swing.JButton();
btnBuscar = new javax.swing.JButton();
labelGestion = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnEntrada.setText("Nueva Entrada");
btnEntrada.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEntradaActionPerformed(evt);
}
});
btnSalida.setText("Salida");
btnSalida.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalidaActionPerformed(evt);
}
});
btnInformes.setText("Informes");
btnInformes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnInformesActionPerformed(evt);
}
});
btnBuscar.setText("Buscar");
btnBuscar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBuscarActionPerformed(evt);
}
});
labelGestion.setText("Gestion de autos estacionados");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelGestion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(btnInformes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnEntrada, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnSalida, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(labelGestion)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnSalida, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnEntrada, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnInformes, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}
private void btnEntradaActionPerformed(java.awt.event.ActionEvent evt) {
VentanaEntrada ventanaEntrada = new VentanaEntrada(this, true);
}
private void btnSalidaActionPerformed(java.awt.event.ActionEvent evt) {
VentanaSalida ventanaSalida = new VentanaSalida(this, true);
}
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {
VentanaBuscar ventanaBuscar = new VentanaBuscar(this, true);
}
private void btnInformesActionPerformed(java.awt.event.ActionEvent evt) {
VentanaInformes ventanaInformes = new VentanaInformes(this, true);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VentanaPrincipal().setVisible(true);
}
});
}
private javax.swing.JButton btnBuscar;
private javax.swing.JButton btnEntrada;
private javax.swing.JButton btnInformes;
private javax.swing.JButton btnSalida;
private javax.swing.JLabel labelGestion;
}
VentanaEntrada.java
package com.dansan.frontend;
import com.dansan.bean.HistoricoBean;
import com.dansan.database.BDManagement;
import com.dansan.fechahora.FechaHora;
import com.dansan.ticket.TicketEntrada;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author dansan
*/
public class VentanaEntrada extends javax.swing.JDialog {
private BDManagement bdm = new BDManagement();
private static final int maxCochesEnCocherasPorPiso = 20;
private static final int maxPiso = 18;
public VentanaEntrada(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setVisible(true);
}
VentanaEntrada() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@SuppressWarnings("unchecked")
private void initComponents() {
labelPatente = new javax.swing.JLabel();
labelPiso = new javax.swing.JLabel();
labelTipo = new javax.swing.JLabel();
campoPatente = new javax.swing.JFormattedTextField();
campoPiso = new javax.swing.JFormattedTextField();
campoTipo = new javax.swing.JFormattedTextField();
labelIndPiso = new javax.swing.JLabel();
labelIndTipo = new javax.swing.JLabel();
btnAceptar = new javax.swing.JButton();
btnCancelar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setModal(true);
labelPatente.setText("Patente");
labelPiso.setText("Piso");
labelTipo.setText("Tipo de Auto");
try {
campoPatente.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("UUU###")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
try {
campoPiso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
try {
campoTipo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("U")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
labelIndPiso.setText("Del 01 al 18");
labelIndTipo.setText("P, M, G");
btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});
btnCancelar.setText("Cancelar");
btnCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(labelPatente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(labelPiso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(labelTipo, javax.swing.GroupLayout.DEFAULT_SIZE, 71, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(campoPatente, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(campoTipo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
.addComponent(campoPiso, javax.swing.GroupLayout.Alignment.LEADING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(labelIndPiso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(labelIndTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))))
.addGroup(layout.createSequentialGroup()
.addGap(51, 51, 51)
.addComponent(btnAceptar)
.addGap(18, 18, 18)
.addComponent(btnCancelar)))
.addContainerGap(38, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPatente)
.addComponent(campoPatente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(campoPiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelIndPiso))
.addComponent(labelPiso))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(campoTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(labelIndTipo))
.addComponent(labelTipo))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAceptar)
.addComponent(btnCancelar))
.addContainerGap(29, Short.MAX_VALUE))
);
pack();
}
private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {
String patente = campoPatente.getText();
int piso = 1;
if (!campoPiso.getText().equals(" ")) {
piso = Integer.parseInt(campoPiso.getText());
}
char tipo = campoTipo.getText().charAt(0);
tipo = Character.toUpperCase(tipo);
HistoricoBean bean = bdm.obtenerCoche(patente);
boolean patenteExistente = bean.getPatente() == patente;
boolean longitudPatente = patente.length() == 6;
boolean tipoCocheValido = tipo == 'G' || tipo == 'M' || tipo == 'P';
if (bdm.numCochesEnCocheras(piso) < maxCochesEnCocherasPorPiso && piso <= maxPiso && !patenteExistente && tipoCocheValido && longitudPatente) { //Solo se permiten 20 autos por piso
bdm.agregarCocheras(patente, piso, tipo);
Date date = new Date();
FechaHora fechahora = new FechaHora(date);
String hora = fechahora.obtenerFechaHora();
imprimirTicket(hora, piso, tipo, patente);
JOptionPane.showMessageDialog(new JFrame(), "Operacion Satisfactoria", "", JOptionPane.INFORMATION_MESSAGE);
this.dispose();
} else {
JOptionPane.showMessageDialog(new JFrame(), "Piso Ocupado o Error de Piso Inexistente o Error en los Datos Introducidos", "", JOptionPane.INFORMATION_MESSAGE);
}
}
private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
public void imprimirTicket(String hora, int piso, char tipo, String patente) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new TicketEntrada(hora, piso, tipo, patente));
PageFormat pageFormat = new PageFormat();
pageFormat = job.pageDialog(pageFormat);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException ex) {
Logger.getLogger(VentanaEntrada.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnCancelar;
private javax.swing.JFormattedTextField campoPatente;
private javax.swing.JFormattedTextField campoPiso;
private javax.swing.JFormattedTextField campoTipo;
private javax.swing.JLabel labelIndPiso;
private javax.swing.JLabel labelIndTipo;
private javax.swing.JLabel labelPatente;
private javax.swing.JLabel labelPiso;
private javax.swing.JLabel labelTipo;
}
VentanaSalida.java
package com.dansan.frontend;
import com.dansan.bean.HistoricoBean;
import com.dansan.database.BDManagement;
import com.dansan.fechahora.FechaHora;
import com.dansan.ticket.TicketSalida;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author dansan
*/
public class VentanaSalida extends javax.swing.JDialog {
BDManagement bdm = new BDManagement();
public VentanaSalida(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setVisible(true);
}
@SuppressWarnings("unchecked")
private void initComponents() {
labelPatente = new javax.swing.JLabel();
campoPatente = new javax.swing.JFormattedTextField();
btnAceptar = new javax.swing.JButton();
btnCancelar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
labelPatente.setText("Patente");
try {
campoPatente.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("UUU###")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});
btnCancelar.setText("Cancelar");
btnCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(labelPatente, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(campoPatente, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(119, 119, 119)
.addComponent(btnAceptar)
.addGap(18, 18, 18)
.addComponent(btnCancelar)))
.addContainerGap(37, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPatente, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(campoPatente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAceptar)
.addComponent(btnCancelar))
.addContainerGap(31, Short.MAX_VALUE))
);
pack();
}
private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {
//Compruebo si es una patente valida
String patente = campoPatente.getText();
if (patente.length() == 6) {
//Obtengo bean
HistoricoBean bean = bdm.obtenerCoche(patente);
//Seteo las fechas del ticket
Date date = new Date();
FechaHora fechahora = new FechaHora(date);
String hora = fechahora.obtenerFechaHora();
Date dateEntrada = new Date((long) bean.getHora_ocupacion());
FechaHora fechaEntrada = new FechaHora(dateEntrada);
String horaEntrada = fechaEntrada.obtenerFechaHora();
//Obtango importe ,graba en historico y borro registro de cocheras
double tarifa = bdm.obtenerTarifa(bean.getTipo_auto());
double importe = calcularImporte(tarifa, dateEntrada.getTime(), date.getTime());
bdm.grabarHistorico(patente, bean.getHora_ocupacion(), bean.getTipo_auto(), bean.getPiso(), importe);
bdm.borrarCocheras(patente);
//imprimo ticket
imprimirTicket(horaEntrada, bean.getPiso(), bean.getTipo_auto(), patente, hora, importe);
JOptionPane.showMessageDialog(new JFrame(), "Operacion Satisfactoria", "", JOptionPane.INFORMATION_MESSAGE);
this.dispose();
}
}
private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void imprimirTicket(String hora, int piso, char tipo, String patente, String hora_salida, double importe) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new TicketSalida(hora, piso, tipo, patente, hora_salida, importe));
PageFormat pageFormat = new PageFormat();
pageFormat = job.pageDialog(pageFormat);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException ex) {
Logger.getLogger(VentanaEntrada.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private double calcularImporte(double tarifa, long entrada, long salida) {
double tiempo = salida - entrada;
double segundos = tiempo / 1000;
double minutos = segundos / 60;
double horas = minutos / 60;
if (horas < 1) {
horas = 1; // aunque sea se cobra una hora que es el minimo
}
double importe = tarifa * horas;
return importe;
}
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnCancelar;
private javax.swing.JFormattedTextField campoPatente;
private javax.swing.JLabel labelPatente;
}
VentanaBuscar.java
package com.dansan.frontend;
import com.dansan.bean.HistoricoBean;
import com.dansan.database.BDManagement;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.table.DefaultTableModel;
/**
*
* @author dansan
*/
public class VentanaBuscar extends javax.swing.JDialog {
BDManagement bdm = new BDManagement();
public VentanaBuscar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setVisible(true);
}
@SuppressWarnings("unchecked")
private void initComponents() {
labelPatente = new javax.swing.JLabel();
labelPiso = new javax.swing.JLabel();
campoPatente = new javax.swing.JFormattedTextField();
campoPiso = new javax.swing.JFormattedTextField();
btnBuscarPatente = new javax.swing.JButton();
btnBuscarPiso = new javax.swing.JButton();
scrollTabla = new javax.swing.JScrollPane();
tablaCoches = new javax.swing.JTable();
btnCerrar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
labelPatente.setText("Patente");
labelPiso.setText("Piso");
try {
campoPatente.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("UUU###")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
try {
campoPiso.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##")));
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
btnBuscarPatente.setText("Buscar");
btnBuscarPatente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBuscarPatenteActionPerformed(evt);
}
});
btnBuscarPiso.setText("Buscar");
btnBuscarPiso.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBuscarPisoActionPerformed(evt);
}
});
tablaCoches.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null}
},
new String[]{
"Patente", "Piso", "Hora de Ingreso", "Tipo de Auto"
}
) {
Class[] types = new Class[]{
java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
});
scrollTabla.setViewportView(tablaCoches);
btnCerrar.setText("Cerrar");
btnCerrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCerrarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 732, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(labelPatente, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
.addComponent(labelPiso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(campoPatente)
.addComponent(campoPiso, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnBuscarPatente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnBuscarPiso, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(77, 77, 77))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPatente)
.addComponent(campoPatente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBuscarPatente))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelPiso)
.addComponent(campoPiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnBuscarPiso))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(scrollTabla, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
.addComponent(btnCerrar))
);
pack();
}
private void btnBuscarPatenteActionPerformed(java.awt.event.ActionEvent evt) {
if (campoPatente.getText().trim().length()==6) {
HistoricoBean bean = bdm.obtenerCoche(campoPatente.getText());
Double d2 = bean.getHora_ocupacion();
Date dateEntrada = new Date(d2.longValue());
DefaultTableModel tm33 = (DefaultTableModel) tablaCoches.getModel();
tm33.setRowCount(0);
if (bean.getPiso()>0) {
Object rowData[] = {bean.getPatente(), bean.getPiso(), dateEntrada.toString(), bean.getTipo_auto()};
tm33.addRow(rowData);
}
}
}
private void btnBuscarPisoActionPerformed(java.awt.event.ActionEvent evt) {
if (!campoPiso.getText().equals(" ")) {
int piso = Integer.parseInt(campoPiso.getText());
ArrayList beanes = bdm.obtenerCoche(piso);
if (beanes.size() > 0) {
DefaultTableModel tm33 = (DefaultTableModel) tablaCoches.getModel();
tm33.setRowCount(0);
for (int i = 0; i < beanes.size(); i++) {
HistoricoBean bean = beanes.get(i);
Double d2 = bean.getHora_ocupacion();
Date dateEntrada = new Date(d2.longValue());
Object rowData[] = {bean.getPatente(), bean.getPiso(), dateEntrada.toString(), bean.getTipo_auto()};
tm33.addRow(rowData);
}
}
}
}
private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private javax.swing.JButton btnBuscarPatente;
private javax.swing.JButton btnBuscarPiso;
private javax.swing.JButton btnCerrar;
private javax.swing.JFormattedTextField campoPatente;
private javax.swing.JFormattedTextField campoPiso;
private javax.swing.JLabel labelPatente;
private javax.swing.JLabel labelPiso;
private javax.swing.JScrollPane scrollTabla;
private javax.swing.JTable tablaCoches;
}
VentanaInformes.java
package com.dansan.frontend;
import com.dansan.database.BDManagement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
/**
*
* @author dansan
*/
public class VentanaInformes extends javax.swing.JDialog {
BDManagement bdm = new BDManagement();
public VentanaInformes(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
cargarTablas();
this.setVisible(true);
}
@SuppressWarnings("unchecked")
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
scrollPaneTabla = new javax.swing.JScrollPane();
tablaHistorial = new javax.swing.JTable();
jPanel2 = new javax.swing.JPanel();
scrollPaneCocheras = new javax.swing.JScrollPane();
tablaCocheras = new javax.swing.JTable();
jPanel3 = new javax.swing.JPanel();
scrollPaneTarifas = new javax.swing.JScrollPane();
tablaTarifas = new javax.swing.JTable();
btnCerrar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
tablaHistorial.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null},
{null, null, null, null, null, null}
},
new String[]{
"patente", "tipo de auto", "piso", "hora_entrada", "hora de salida", "importe"
}
) {
Class[] types = new Class[]{
java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class
};
boolean[] canEdit = new boolean[]{
false, false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
tablaHistorial.setToolTipText("");
scrollPaneTabla.setViewportView(tablaHistorial);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneTabla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Historial", jPanel1);
tablaCocheras.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String[]{
"patente", "tipo de auto", "piso", "hora de entrada"
}
) {
Class[] types = new Class[]{
java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class
};
boolean[] canEdit = new boolean[]{
false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
scrollPaneCocheras.setViewportView(tablaCocheras);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneCocheras, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneCocheras, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Cocheras", jPanel2);
tablaTarifas.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null},
{null, null},
{null, null},
{null, null}
},
new String[]{
"Tipo de auto", "Tarifa"
}
) {
Class[] types = new Class[]{
java.lang.String.class, java.lang.Double.class
};
boolean[] canEdit = new boolean[]{
false, false
};
public Class getColumnClass(int columnIndex) {
return types[columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit[columnIndex];
}
});
scrollPaneTarifas.setViewportView(tablaTarifas);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneTarifas, javax.swing.GroupLayout.DEFAULT_SIZE, 735, Short.MAX_VALUE)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scrollPaneTarifas, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
);
jTabbedPane1.addTab("Tarifas", jPanel3);
btnCerrar.setText("Cerrar");
btnCerrar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCerrarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(41, 41, 41))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCerrar)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
private void btnCerrarActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void cargarTablas() {
//carga historial
ResultSet rs = bdm.listarHistorico();
DefaultTableModel tm33 = (DefaultTableModel) tablaHistorial.getModel();
tm33.setRowCount(0);
try {
while (rs.next()) {
Double dOcup = (Double) rs.getObject("hora_ocupacion");
Double dSal = (Double) rs.getObject("hora_ocupacion");
Date dateEntrada = new Date(dOcup.longValue());
Date dateSalida = new Date(dSal.longValue());
Object rowData[] = {rs.getObject("patente"), rs.getObject("tipo_auto"), rs.getObject("piso"), dateEntrada.toString(), dateSalida.toString(), rs.getObject("importe")};
tm33.addRow(rowData);
}
} catch (SQLException ex) {
Logger.getLogger(VentanaInformes.class.getName()).log(Level.SEVERE, null, ex);
}
//carga cocheras
ResultSet rs2 = bdm.listarCocheras();
DefaultTableModel tm2 = (DefaultTableModel) tablaCocheras.getModel();
tm2.setRowCount(0);
try {
while (rs2.next()) {
Double d2 = (Double) rs2.getObject("hora_ocupacion");
Date dateEntrada = new Date(d2.longValue());
Object rowData2[] = {rs2.getObject("patente"), rs2.getObject("tipo_auto"), rs2.getObject("piso"), dateEntrada.toString()};
tm2.addRow(rowData2);
}
} catch (SQLException ex) {
Logger.getLogger(VentanaInformes.class.getName()).log(Level.SEVERE, null, ex);
}
//carga tarifas
ResultSet rs3 = bdm.listarTarifas();
DefaultTableModel tm3 = (DefaultTableModel) tablaTarifas.getModel();
tm3.setRowCount(0);
try {
while (rs3.next()) {
Object rowData[] = {rs3.getObject("tipo_auto"), rs3.getObject("tarifa")};
tm3.addRow(rowData);
}
} catch (SQLException ex) {
Logger.getLogger(VentanaInformes.class.getName()).log(Level.SEVERE, null, ex);
}
}
private javax.swing.JButton btnCerrar;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JScrollPane scrollPaneCocheras;
private javax.swing.JScrollPane scrollPaneTabla;
private javax.swing.JScrollPane scrollPaneTarifas;
private javax.swing.JTable tablaCocheras;
private javax.swing.JTable tablaHistorial;
private javax.swing.JTable tablaTarifas;
}
TicketEntrada.java
package com.dansan.ticket;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
/**
*
* @author dansan
*/
public class TicketEntrada implements Printable {
private String hora_entrada;
private int piso;
private char tipo;
private String patente;
public TicketEntrada(String hora, int piso, char tipo, String patente) {
this.hora_entrada = hora;
this.piso = piso;
this.tipo = tipo;
this.patente = patente;
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
if (pageIndex == 0) {
graphics.drawString("De Entrada", 200, 80);
graphics.drawString("Entrada", 120, 120);
graphics.drawString(hora_entrada, 180, 120);
graphics.drawString("Piso", 120, 140);
graphics.drawString("" + piso, 180, 140);
graphics.drawString("Tipo", 120, 160);
graphics.drawString("" + tipo, 180, 160);
graphics.drawString("Patente", 120, 180);
graphics.drawString(patente, 180, 180);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
}
TicketSalida.java
package com.dansan.ticket;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.text.DecimalFormat;
/**
*
* @author dansan
*/
public class TicketSalida implements Printable {
private String hora_entrada;
private int piso;
private char tipo;
private String patente;
private String hora_salida;
private double importe;
public TicketSalida(String hora, int piso, char tipo, String patente, String hora_salida, double importe) {
this.hora_entrada = hora;
this.piso = piso;
this.tipo = tipo;
this.patente = patente;
this.hora_salida = hora_salida;
this.importe = importe;
}
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
if (pageIndex == 0) {
graphics.drawString("De Salida", 200, 80);
graphics.drawString("Entrada", 120, 120);
graphics.drawString(hora_entrada, 180, 120);
graphics.drawString("Piso", 120, 140);
graphics.drawString("" + piso, 180, 140);
graphics.drawString("Tipo", 120, 160);
graphics.drawString("" + tipo, 180, 160);
graphics.drawString("Patente", 120, 180);
graphics.drawString(patente, 180, 180);
graphics.drawString("Salida", 120, 200);
graphics.drawString(hora_salida, 180, 200);
graphics.drawString("Importe", 120, 220);
DecimalFormat df = new DecimalFormat("#.##");
graphics.drawString("" + df.format(importe), 180, 220);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
}
Ticket de entrada y salida
El siguiente .rar tiene el .jar ejecutable y el script para generar la base de datos.
Para ejecutar: en consola escribir java -jar plazadeestacionamiento.jar
https://drive.google.com/file/d/0B0sBXdZ8aJgdb1d2MGpkM1h5dk0/edit?usp=sharing
MUCHAS GRACIAS AMIGOPOR COMARTIR TU CONOCIMIENT CON LOS DEMAS SALUDOS HERMANO
ResponderBorrarcomo le ejecuto por consola en donde escribo java -jar plazadeestacionamiento.jar en que clases
ResponderBorrarthanks a lot!
ResponderBorrarthanks a lot!
ResponderBorrarthanks this is the best program did hay see about parking
ResponderBorrarmuchas gracias man, ojala todos fueran como tu
ResponderBorrarComo conecto la base de datos ??
ResponderBorrarHola, no tienes un vídeo explicando el código?
ResponderBorrar