/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* NewJDialog.java
*
* Created on 09/02/2011, 13:29:15
*/
package frmcadastosconsulta;
import dao.UnidadeArquivamentoDao;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import logica.UnidadeArquivamento;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanArrayDataSource;
import net.sf.jasperreports.view.JasperViewer;
/**
*
* @author Neto
*/
public class JDialogImprimeEtiquetaAvulso extends javax.swing.JDialog {
List<UnidadeArquivamento> unidadearquivamentos = null;
String usuarioLogado;
String empresa;
String versao;
/** Creates new form NewJDialog */
public JDialogImprimeEtiquetaAvulso(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
public void recebeParametrosRelatorio(String usu, String emp, String ver) {
usuarioLogado = usu;
empresa = emp;
versao = ver;
jL_DisplayUsuario.setText("Usuário: " + usuarioLogado);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jB_Imprimir = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jL_DisplayUsuario = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"680664830802383"},
{"805447496468381"},
{"005629726698071"},
{"605649713685032"},
{"015170330302883"},
{"545210370342003"}
},
new String [] {
"Title 1"
}
));
jScrollPane1.setViewportView(jTable1);
jB_Imprimir.setText("Imprimir");
jB_Imprimir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_ImprimirActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE)
.addComponent(jB_Imprimir, javax.swing.GroupLayout.Alignment.TRAILING))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jB_Imprimir)
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setFont(new java.awt.Font("Tahoma", 3, 18));
jLabel1.setText("Imprimir Etiqueta");
jL_DisplayUsuario.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jL_DisplayUsuario.setText("Usuario");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(78, 78, 78)
.addComponent(jL_DisplayUsuario)
.addContainerGap(15, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(30, Short.MAX_VALUE)
.addComponent(jL_DisplayUsuario))
);
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.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(60, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jB_ImprimirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pesquisarUnidadesArquivamento();
try {
abrirRelatorioEtiqueta();
} catch (SQLException ex) {
Logger.getLogger(JDialogImprimeEtiquetaAvulso.class.getName()).log(Level.SEVERE, null, ex);
} catch (JRException ex) {
Logger.getLogger(JDialogImprimeEtiquetaAvulso.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void pesquisarUnidadesArquivamento() {
String anoFinal, codigoUnidadeArquivamento;
String dataInicial;
dataInicial = "%-%-% %:%:%";
anoFinal = "";
codigoUnidadeArquivamento = "";
anoFinal = "9999";
if (codigoUnidadeArquivamento.equals("")) {
codigoUnidadeArquivamento = "%";
}
int nlinha = jTable1.getRowCount();
--nlinha;
int i = 0;
try {
while (i <= nlinha) {
String unidade = (String) jTable1.getValueAt(i, 0);
UnidadeArquivamentoDao dao = new UnidadeArquivamentoDao();
unidadearquivamentos = dao.getLista(unidade, "%", dataInicial, "%", "%", "%", "%", "%", "%", "%", "%", "%", "%", "%", "%", "%", anoFinal);
++i;
}
} catch (SQLException ex) {
Logger.getLogger(JDialogImprimeEtiquetaAvulso.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void abrirRelatorioEtiqueta() throws SQLException, JRException {
//ENDEREÇO RELATORIO
InputStream relatorioPai = getClass().getResourceAsStream("/relatorioCadastros/EtiquetaUnidadeArquivamento566.jasper");
//PASSAR DADOS
JRDataSource vetorPai = new JRBeanArrayDataSource(unidadearquivamentos.toArray());
//CRIA MAPA
Map<String, Object> parametros = new HashMap<String, Object>();
int quantidadeRegistros;
for (quantidadeRegistros = 0; quantidadeRegistros < unidadearquivamentos.size(); quantidadeRegistros++) {
}
parametros.put("empresa", empresa);
parametros.put("tituloRelatorio", "Imprimir Etiquetas Avulso");
parametros.put("usuario", usuarioLogado);
parametros.put("versao", versao);
parametros.put("quantidadeRegistros", quantidadeRegistros);
//CRIA O PRINT
JasperPrint jasperPrintRelatorioPai = JasperFillManager.fillReport(relatorioPai, parametros, vetorPai);
JDialog viewer = new JDialog(new javax.swing.JFrame(), "Visualização do Relatório", true);
viewer.setSize(1024, 768);
viewer.setLocationRelativeTo(null);
JasperViewer jrViewer = new JasperViewer(jasperPrintRelatorioPai, true);
viewer.getContentPane().add(jrViewer.getContentPane());
viewer.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
JDialogImprimeEtiquetaAvulso dialog = new JDialogImprimeEtiquetaAvulso(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jB_Imprimir;
private javax.swing.JLabel jL_DisplayUsuario;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
// End of variables declaration
}