Tela Adicionar_Imprimir
ackage br.com.gem.telas;
import br.com.gem.dal.ExcelAdapter;
import br.com.gem.dal.ModuloConexao;
import java.awt.print.PrinterException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
/**
*
//Chamando Tela Pesquisar PEP
private void pesquisar() {
String sql = " Select * from tblgem where pepaux=? order by lista desc";
try {
pst = conexao.prepareStatement(sql);
pst.setString(1, txtPepPesq.getText());
rs = pst.executeQuery();
if (rs.next()) {
txtNumList.setText(rs.getString(1));
} else {
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
private void adicionar() {
String sql = "insert into tblgem(lista,dat,pep,listec,item,material,txtbre,qtde,um,rncrm,necob,natnf,local,pepaux,projeto) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
try {
pst = conexao.prepareStatement(sql);
pst.setString(1, jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString());
pst.setString(2, jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString());
pst.setString(3, jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString());
pst.setString(4, jTable1.getValueAt(jTable1.getSelectedRow(), 3).toString());
pst.setString(5, jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString());
pst.setString(6, jTable1.getValueAt(jTable1.getSelectedRow(), 5).toString());
pst.setString(7, jTable1.getValueAt(jTable1.getSelectedRow(), 6).toString());
pst.setString(8, jTable1.getValueAt(jTable1.getSelectedRow(), 7).toString());
pst.setString(9, jTable1.getValueAt(jTable1.getSelectedRow(), 8).toString());
pst.setString(10, jTable1.getValueAt(jTable1.getSelectedRow(), 9).toString());
pst.setString(11, jTable1.getValueAt(jTable1.getSelectedRow(), 10).toString());
pst.setString(12, jTable1.getValueAt(jTable1.getSelectedRow(), 11).toString());
pst.setString(13, jTable1.getValueAt(jTable1.getSelectedRow(), 12).toString());
pst.setString(14, jTable1.getValueAt(jTable1.getSelectedRow(), 13).toString());
pst.setString(15, jTable1.getValueAt(jTable1.getSelectedRow(), 14).toString());
int adicionado = pst.executeUpdate();
if (adicionado > 0) {
JOptionPane.showMessageDialog(null, "Requisições adicionadas com sucesso!");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
private void imprimir(){
try {
jTable1.print(javax.swing.JTable.PrintMode.FIT_WIDTH,
new java.text.MessageFormat("Logistica Movimentação de Materiais"), // titulo da pagina
new java.text.MessageFormat("Page {0}"));
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this, "Erro ao tentar imprimir!\n"
+ e.getMessage());
}
}
/**
* 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() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
txtPepPesq = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
txtNumList = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Adicionar/Impressão");
jTable1.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, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, 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 [] {
"lista", "dat", "pep", "listec", "item", "material", "txtbre", "qtde", "um", "rncrm", "necob", "natnf", "local", "pepaux", "projeto"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
jTable1.getTableHeader().setReorderingAllowed(false);
jScrollPane1.setViewportView(jTable1);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gem/icones/create.png"))); // NOI18N
jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton1.setPreferredSize(new java.awt.Dimension(80, 80));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gem/icones/print.png"))); // NOI18N
jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton2.setPreferredSize(new java.awt.Dimension(80, 80));
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel1.setText("Lista:");
txtNumList.setEditable(false);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel2.setText("PEP");
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gem/icones/pesquisar.png"))); // NOI18N
jButton3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("jButton4");
jButton4.setPreferredSize(new java.awt.Dimension(80, 80));
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(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()
.addGap(31, 31, 31)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1180, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtPepPesq, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)))
.addGroup(layout.createSequentialGroup()
.addGap(78, 78, 78)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jButton3)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(txtNumList, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(124, 124, 124))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(42, 42, 42)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(59, 59, 59))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(25, 25, 25)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 440, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(106, 106, 106)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(30, 30, 30)
.addComponent(txtNumList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(55, 55, 55)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3))
.addGap(30, 30, 30)
.addComponent(txtPepPesq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(46, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// chamando metodo pesquisar
pesquisar();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// gerando impressão
int confirma = JOptionPane.showConfirmDialog(null, "Confirma a impressão?", "Atenção", JOptionPane.YES_NO_OPTION);
if (confirma == JOptionPane.YES_OPTION);
{
//imprimindo relatório
try {
// usando a classe JasperPrint para preparar a impressao de um relatório
JasperPrint print = JasperFillManager.fillReport("C:/reports/report4.jasper", null, conexao);
// a linha abaixo exibe o relatório através da classe JasperViewer
JasperViewer.viewReport(print, false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// chamaando metodo adicionar
adicionar();
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
jTable1.print(javax.swing.JTable.PrintMode.FIT_WIDTH,
new java.text.MessageFormat("Agenda de Contatos"), // titulo da pagina
new java.text.MessageFormat("Page {0}"));
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this, "Erro ao tentar imprimir!\n"
+ e.getMessage());
}