br.com.tcc.view.MovimentoEntradaView.java Source code

Java tutorial

Introduction

Here is the source code for br.com.tcc.view.MovimentoEntradaView.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.tcc.view;

import Conexao.ConnectionFactory;
import br.com.tcc.entity.Entradaprodutodetalhe;
import br.com.tcc.entity.EntradaprodutodetalhePK;
import br.com.tcc.entity.Entradaprodutoregistro;
import br.com.tcc.entity.Pedidodetalhe;
import br.com.tcc.entity.PedidodetalhePK;
import br.com.tcc.entity.Pedidoregistro;
import br.com.tcc.entity.Produto;
import br.com.tcc.util.EntityManagerUtil;
import br.com.tcc.util.TableModelPadraoParaBean;
import br.com.tcc.util.Uteis;
import br.com.tcc.util.pegaProduto;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author Leonardo P Souza
 */
public class MovimentoEntradaView extends javax.swing.JDialog {

    Boolean editando; // Variavel global responsavel pela ativaes dos componentes da classe(ex: botes, tabelas e campos).
    Double valorTotal = 0.0;
    public String mes, dia, ano, dia_semana, hora;
    public static String sql;

    public MovimentoEntradaView(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        entradaDetalheList.clear();
        editando = false;
        txtCodigo1.setEnabled(false);
        txtDescricao1.setEnabled(false);
        cbxFornecedor2.setEnabled(false);
        cbxUnidade2.setEnabled(false);
        txtCritico.setEnabled(false);
        txtVendaProduto.setEnabled(false);
        txtCompra.setEnabled(true);
        btnCadastrar.setVisible(false);
        btnAdicionaProduto.setEnabled(false);
        btnImprimir.setEnabled(false);
        trataEdicao();
    }

    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = EntityManagerUtil.getEntityManager();
        entradaRegistroQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager.createQuery("SELECT pr FROM Entradaprodutoregistro pr");
        entradaRegistroList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(entradaRegistroQuery.getResultList());
        entradaDetalheQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager.createQuery("SELECT pd FROM Entradaprodutodetalhe pd");
        entradaDetalheList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(entradaDetalheQuery.getResultList());
        fornecedorQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager.createQuery("SELECT f FROM Fornecedor f");
        fornecedorList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(fornecedorQuery.getResultList());
        produtoQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager.createQuery("SELECT f FROM Produto f");
        produtoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(produtoQuery.getResultList());
        atualizaProdutoQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager
                        .createQuery("from Produto where numEstoque <= numEstoqueCritico order by descricao");
        atualizaProdutoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(produtoQuery.getResultList());
        unidadeQuery = java.beans.Beans.isDesignTime() ? null
                : entityManager.createQuery("from Unidade order by descricao");
        unidadeList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList()
                : org.jdesktop.observablecollections.ObservableCollections
                        .observableList(unidadeQuery.getResultList());
        pnlBotoesEntrada = new javax.swing.JPanel();
        btnNovaVenda = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnConfirmar = new javax.swing.JButton();
        btnAdicionaProduto = new javax.swing.JButton();
        btnImprimir = new javax.swing.JButton();
        pnlRegistroEntrada = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtTotalEntrada = new javax.swing.JTextField();
        cbxFornecedor = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        pnlDetalheEntrada = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblDetalhe = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblRegistro = new javax.swing.JTable();
        pnlProduto = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblProduto = new javax.swing.JTable();
        pnlFormProduto1 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tblObjetos1 = new javax.swing.JTable();
        txtCodigo1 = new javax.swing.JTextField();
        txtDescricao1 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cbxFornecedor2 = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        cbxUnidade2 = new javax.swing.JComboBox();
        btnImportar = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        spnEstoque = new javax.swing.JSpinner();
        txtCritico = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtVendaProduto = new javax.swing.JTextField();
        txtCompra = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        btnCadastrar = new javax.swing.JButton();
        pnlPesquisa = new javax.swing.JPanel();
        lblProduto = new javax.swing.JLabel();
        txtPesquisar = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Entrada de Produtos");

        pnlBotoesEntrada.setBackground(new java.awt.Color(204, 204, 255));

        btnNovaVenda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tcc/imagem/Vendax32.png"))); // NOI18N
        btnNovaVenda.setText("Entrada");
        btnNovaVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovaVendaActionPerformed(evt);
            }
        });

        btnExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tcc/imagem/excluir32.png"))); // NOI18N
        btnExcluir.setText("Excluir");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblDetalhe,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), btnExcluir,
                org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        btnConfirmar
                .setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/tcc/imagem/confirmar32.png"))); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });

        btnAdicionaProduto.setText("Adicionar Produto");
        btnAdicionaProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdicionaProdutoActionPerformed(evt);
            }
        });

        btnImprimir.setText("Imprimir");
        btnImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlBotoesEntradaLayout = new javax.swing.GroupLayout(pnlBotoesEntrada);
        pnlBotoesEntrada.setLayout(pnlBotoesEntradaLayout);
        pnlBotoesEntradaLayout.setHorizontalGroup(
                pnlBotoesEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlBotoesEntradaLayout.createSequentialGroup().addContainerGap()
                                .addGroup(pnlBotoesEntradaLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(btnNovaVenda, javax.swing.GroupLayout.DEFAULT_SIZE, 139,
                                                Short.MAX_VALUE)
                                        .addComponent(btnExcluir, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnConfirmar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnAdicionaProduto, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnImprimir, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        pnlBotoesEntradaLayout.setVerticalGroup(pnlBotoesEntradaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlBotoesEntradaLayout.createSequentialGroup().addContainerGap()
                        .addComponent(btnNovaVenda).addGap(18, 18, 18).addComponent(btnExcluir).addGap(18, 18, 18)
                        .addComponent(btnConfirmar).addGap(18, 18, 18).addComponent(btnAdicionaProduto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnImprimir)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pnlRegistroEntrada.setBorder(javax.swing.BorderFactory.createTitledBorder("Registro de Entrada"));

        jLabel1.setText("Cdigo:");

        txtCodigo.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), txtCodigo,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });

        jLabel5.setText("Total Venda R$:");

        txtTotalEntrada.setEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.vlrTotal}"), txtTotalEntrada,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings
                .createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
                        fornecedorList, cbxFornecedor);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblRegistro,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idFornecedor}"), cbxFornecedor,
                org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        jLabel2.setText("Fornecedor");

        javax.swing.GroupLayout pnlRegistroEntradaLayout = new javax.swing.GroupLayout(pnlRegistroEntrada);
        pnlRegistroEntrada.setLayout(pnlRegistroEntradaLayout);
        pnlRegistroEntradaLayout.setHorizontalGroup(pnlRegistroEntradaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlRegistroEntradaLayout.createSequentialGroup().addContainerGap().addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18).addComponent(jLabel2).addGap(18, 18, 18)
                        .addComponent(cbxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel5).addGap(18, 18, 18).addComponent(txtTotalEntrada,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));
        pnlRegistroEntradaLayout.setVerticalGroup(
                pnlRegistroEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(pnlRegistroEntradaLayout.createSequentialGroup().addContainerGap()
                                .addGroup(pnlRegistroEntradaLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel1)
                                        .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel5)
                                        .addComponent(txtTotalEntrada, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(cbxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pnlDetalheEntrada.setBorder(javax.swing.BorderFactory.createTitledBorder("Entrada de Produto"));

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings
                .createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE,
                        entradaDetalheList, tblDetalhe);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(
                org.jdesktop.beansbinding.ELProperty.create("${entradaprodutodetalhePK.idEntradaRegistro}"));
        columnBinding.setColumnName("Cdigo");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(
                org.jdesktop.beansbinding.ELProperty.create("${entradaprodutodetalhePK.idProduto}"));
        columnBinding.setColumnName("Produto");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrUnitario}"));
        columnBinding.setColumnName("Unitario R$");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${qtde}"));
        columnBinding.setColumnName("Quantidade");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrTotal}"));
        columnBinding.setColumnName("Total R$");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(tblDetalhe);

        javax.swing.GroupLayout pnlDetalheEntradaLayout = new javax.swing.GroupLayout(pnlDetalheEntrada);
        pnlDetalheEntrada.setLayout(pnlDetalheEntradaLayout);
        pnlDetalheEntradaLayout
                .setHorizontalGroup(
                        pnlDetalheEntradaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDetalheEntradaLayout
                                        .createSequentialGroup().addContainerGap().addComponent(jScrollPane1,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                                        .addContainerGap()));
        pnlDetalheEntradaLayout.setVerticalGroup(pnlDetalheEntradaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlDetalheEntradaLayout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 455, Short.MAX_VALUE)
                        .addContainerGap()));

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, entradaRegistroList, tblRegistro);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idFornecedor.nome}"));
        columnBinding.setColumnName("Id Fornecedor");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dataEntrada}"));
        columnBinding.setColumnName("Data Entrada");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrTotal}"));
        columnBinding.setColumnName("Vlr Total");
        columnBinding.setColumnClass(Double.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(tblRegistro);

        pnlProduto.setBorder(javax.swing.BorderFactory.createTitledBorder("Produtos"));
        pnlProduto.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, produtoList, tblProduto);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Cdigo");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descricao}"));
        columnBinding.setColumnName("Descrio");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numEstoque}"));
        columnBinding.setColumnName("Estoque");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numEstoqueCritico}"));
        columnBinding.setColumnName("Critico");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idUnidade.descricao}"));
        columnBinding.setColumnName("Unidade");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idFornecedor.nome}"));
        columnBinding.setColumnName(" Fornecedor");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrCompra}"));
        columnBinding.setColumnName("Compra R$");
        columnBinding.setColumnClass(Double.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane3.setViewportView(tblProduto);

        pnlProduto.add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 600, 100));

        jLabel8.setText("Cdigo: ");

        jLabel9.setText("Descrio:");

        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, produtoList, tblObjetos1);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${descricao}"));
        columnBinding.setColumnName("Descricao");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idFornecedor}"));
        columnBinding.setColumnName("Id Fornecedor");
        columnBinding.setColumnClass(br.com.tcc.entity.Fornecedor.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${idUnidade}"));
        columnBinding.setColumnName("Id Unidade");
        columnBinding.setColumnClass(br.com.tcc.entity.Unidade.class);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numEstoque}"));
        columnBinding.setColumnName("Num Estoque");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding
                .addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${numEstoqueCritico}"));
        columnBinding.setColumnName("Num Estoque Critico");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrCompra}"));
        columnBinding.setColumnName("Vlr Compra");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${vlrVenda}"));
        columnBinding.setColumnName("Vlr Venda");
        columnBinding.setColumnClass(Double.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane5.setViewportView(tblObjetos1);

        txtCodigo1.setEditable(false);
        txtCodigo1.setFocusable(false);
        txtCodigo1.setRequestFocusEnabled(false);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.id}"), txtCodigo1,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.descricao}"), txtDescricao1,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtDescricao1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtDescricao1FocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                txtDescricao1FocusLost(evt);
            }
        });
        txtDescricao1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDescricao1KeyPressed(evt);
            }

            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtDescricao1KeyReleased(evt);
            }
        });

        jLabel10.setText("Fornecedor:");

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, fornecedorList, cbxFornecedor2);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idFornecedor}"), cbxFornecedor2,
                org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        cbxFornecedor2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cbxFornecedor2FocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                cbxFornecedor2FocusLost(evt);
            }
        });

        jLabel11.setText("Unidade:");

        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, unidadeList, cbxUnidade2);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.idUnidade}"), cbxUnidade2,
                org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        cbxUnidade2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                cbxUnidade2FocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                cbxUnidade2FocusLost(evt);
            }
        });

        btnImportar.setText("Importar");
        btnImportar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImportarActionPerformed(evt);
            }
        });

        jLabel3.setText("Estoque:");

        spnEstoque.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                spnEstoqueFocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                spnEstoqueFocusLost(evt);
            }
        });

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.numEstoqueCritico}"), txtCritico,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCritico.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCriticoFocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCriticoFocusLost(evt);
            }
        });
        txtCritico.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCriticoKeyTyped(evt);
            }
        });

        jLabel4.setText("Compra:");

        jLabel6.setText("Venda:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.vlrVenda}"), txtVendaProduto,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtVendaProduto.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtVendaProdutoFocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                txtVendaProdutoFocusLost(evt);
            }
        });
        txtVendaProduto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtVendaProdutoKeyTyped(evt);
            }
        });

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tblProduto,
                org.jdesktop.beansbinding.ELProperty.create("${selectedElement.vlrCompra}"), txtCompra,
                org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        txtCompra.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtCompraFocusGained(evt);
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCompraFocusLost(evt);
            }
        });
        txtCompra.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtCompraKeyTyped(evt);
            }
        });

        jLabel7.setText("Critico:");

        btnCadastrar.setText("Cadastrar");
        btnCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCadastrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlFormProduto1Layout = new javax.swing.GroupLayout(pnlFormProduto1);
        pnlFormProduto1.setLayout(pnlFormProduto1Layout);
        pnlFormProduto1Layout.setHorizontalGroup(pnlFormProduto1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlFormProduto1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlFormProduto1Layout
                                        .createSequentialGroup()
                                        .addGroup(pnlFormProduto1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel9).addComponent(jLabel8).addComponent(jLabel3))
                                        .addGap(27, 27, 27)
                                        .addGroup(pnlFormProduto1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(txtDescricao1)
                                                .addGroup(pnlFormProduto1Layout.createSequentialGroup()
                                                        .addComponent(spnEstoque,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(42, 42, 42).addComponent(jLabel7)
                                                        .addGap(0, 0, Short.MAX_VALUE))))
                                .addGroup(pnlFormProduto1Layout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addGroup(pnlFormProduto1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addGroup(pnlFormProduto1Layout.createSequentialGroup()
                                                        .addComponent(btnCadastrar)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(btnImportar))
                                                .addGroup(pnlFormProduto1Layout.createSequentialGroup()
                                                        .addGroup(pnlFormProduto1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel10)
                                                                .addGroup(pnlFormProduto1Layout
                                                                        .createSequentialGroup()
                                                                        .addComponent(jScrollPane5,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                0,
                                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                        .addPreferredGap(
                                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                        .addComponent(jLabel4)))
                                                        .addGap(18, 18, 18)
                                                        .addGroup(pnlFormProduto1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        false)
                                                                .addComponent(cbxFornecedor2, 0,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(txtCodigo1,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 100,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(txtCompra))
                                                        .addGap(42, 42, 42)
                                                        .addGroup(pnlFormProduto1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel11).addComponent(jLabel6))
                                                        .addGap(18, 18, 18)
                                                        .addGroup(pnlFormProduto1Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(txtCritico,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(cbxUnidade2,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(txtVendaProduto,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 100,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))))
                        .addGap(220, 220, 220)));
        pnlFormProduto1Layout.setVerticalGroup(pnlFormProduto1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pnlFormProduto1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8).addComponent(txtCodigo1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9).addComponent(txtDescricao1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(spnEstoque, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txtCritico, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(pnlFormProduto1Layout.createSequentialGroup().addGap(21, 21, 21)
                                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(pnlFormProduto1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(pnlFormProduto1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel4).addComponent(jLabel6)
                                                .addComponent(txtVendaProduto,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(txtCompra, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(cbxFornecedor2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11).addComponent(cbxUnidade2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
                        .addGroup(pnlFormProduto1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnImportar).addComponent(btnCadastrar))
                        .addContainerGap()));

        pnlProduto.add(pnlFormProduto1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 400, 240));

        javax.swing.GroupLayout pnlPesquisaLayout = new javax.swing.GroupLayout(pnlPesquisa);
        pnlPesquisa.setLayout(pnlPesquisaLayout);
        pnlPesquisaLayout.setHorizontalGroup(pnlPesquisaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 620, Short.MAX_VALUE));
        pnlPesquisaLayout.setVerticalGroup(pnlPesquisaLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 40, Short.MAX_VALUE));

        pnlProduto.add(pnlPesquisa, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 380, 620, 40));

        lblProduto.setText("Produto:");
        pnlProduto.add(lblProduto, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        txtPesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisarKeyReleased(evt);
            }
        });
        pnlProduto.add(txtPesquisar, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 20, 435, -1));

        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()
                        .addComponent(pnlBotoesEntrada, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(pnlProduto, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(pnlRegistroEntrada, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnlDetalheEntrada, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(pnlBotoesEntrada, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                layout.createSequentialGroup()
                                        .addComponent(pnlRegistroEntrada, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(pnlProduto, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                layout.createSequentialGroup()
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(pnlDetalheEntrada, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addContainerGap()));

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNovaVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovaVendaActionPerformed
        editando = true;
        trataEdicao();
        entradaDetalheList.clear();
        entradaRegistroList.add((Entradaprodutoregistro) new Entradaprodutoregistro());
        int row = entradaRegistroList.size() - 1;
        tblRegistro.setRowSelectionInterval(row, row);
    }//GEN-LAST:event_btnNovaVendaActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        if (Uteis.confirmar("Confirma Excluo?")) {
            int linhaClicada = tblDetalhe.getSelectedRow();
            if (linhaClicada < 0) {
                JOptionPane.showMessageDialog(null, "Selecione um registro para excluir");
            } else {
                try {

                    //                    entityManager.getTransaction().begin();
                    //                    entityManager.getTransaction().isActive();
                    //                    entityManager.getTransaction().rollback();
                    Entradaprodutodetalhe obj = entradaDetalheList.get(linhaClicada);
                    valorTotal = valorTotal - obj.getVlrTotal();
                    System.err.println("euhhueuhe"
                            + entradaDetalheList.get(linhaClicada).getEntradaprodutodetalhePK().getIdProduto());
                    Produto produto = entityManager.find(Produto.class,
                            entradaDetalheList.get(linhaClicada).getEntradaprodutodetalhePK().getIdProduto());

                    entityManager.getTransaction().begin();
                    produto.setNumEstoque(produto.getNumEstoque() - entradaDetalheList.get(linhaClicada).getQtde());
                    entityManager.getTransaction().commit();
                    txtTotalEntrada.setText(String.valueOf(valorTotal));
                    entradaDetalheList.remove(linhaClicada);
                    produtoList.clear();
                    produtoList.addAll(produtoQuery.getResultList());
                    //////                    txtTotalVenda.setText(String.valueOf(valorsugerido));
                    //                    entityManager.getTransaction().begin();
                    //                    entityManager.remove(obj);
                    //                    entityManager.getTransaction().commit();
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null, "Erro ao Excluir \n" + e.getMessage());
                    //                    if (entityManager.getTransaction().isActive() == false) {
                    //                        entityManager.getTransaction().begin();
                    //                    }
                    //                    entityManager.getTransaction().rollback();
                }
            }
        }
        //        if (Uteis.confirmar("Confirma Excluo?")) {
        //            int linhaClicada = tblDetalhe.getSelectedRow();
        //            if (linhaClicada < 0) {
        //                JOptionPane.showMessageDialog(null, "Selecione um registro para excluir");
        //            } else {
        //                try {
        //                    Entradaprodutodetalhe obj = entradaDetalheList.get(linhaClicada);
        //                    valorTotal = valorTotal - obj.getVlrTotal();
        //                    entradaDetalheList.remove(linhaClicada);
        //                    txtTotalEntrada.setText(String.valueOf(valorTotal));
        //                    entityManager.getTransaction().begin();
        //                    entityManager.remove(obj);
        //                    entityManager.getTransaction().commit();
        //                } catch (Exception e) {
        //                    JOptionPane.showMessageDialog(null, "Erro ao Excluir \n" + e.getMessage());
        //                    if (entityManager.getTransaction().isActive() == false) {
        //                        entityManager.getTransaction().begin();
        //                    }
        //                    entityManager.getTransaction().rollback();
        //                }
        //            }
        //        }
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
        try {
            int row = entradaDetalheList.size() - 1;
            //            int id = entradaRegistroList.get(row).getId();
            if (row >= 0) {
                entityManager.getTransaction().begin();
                entityManager.getTransaction().commit();
                JOptionPane.showMessageDialog(null, "Entrada Realizada com Sucesso");
                btnImprimir.setEnabled(true);

            } else {
                JOptionPane.showMessageDialog(null, "Insira um produto");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Erro ao Gravar \n" + e.getMessage());
        }
    }//GEN-LAST:event_btnConfirmarActionPerformed

    private void btnAdicionaProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdicionaProdutoActionPerformed
        txtCodigo1.setEnabled(true);
        txtDescricao1.requestFocus();
        txtDescricao1.setEnabled(true);
        cbxFornecedor2.setEnabled(true);
        cbxUnidade2.setEnabled(true);
        spnEstoque.setEnabled(true);
        txtCritico.setEnabled(true);
        txtVendaProduto.setEnabled(true);
        txtCompra.setEnabled(true);
        btnCadastrar.setVisible(true);
        btnImportar.setVisible(false);
        produtoList.add((Produto) new Produto());
        int row = produtoList.size() - 1;
        tblProduto.setRowSelectionInterval(row, row);

        //        JDialog form = new AdicionaProdutoView(null, true);
        //        form.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        //        form.setLocationRelativeTo(null);
        //        form.setResizable(false);
        //        form.setVisible(true);
        //        atualizaTabelaProduto();
        //        produtoQuery = entityManager.createQuery("from Produto where numEstoque <= numEstoqueCritico order by descricao");
        ////        produtoList.clear();
        //        produtoQuery.executeUpdate();
        //        produtoQuery.getResultList();
        //        produtoList.addAll(produtoQuery.getResultList());
        //        int linha = tblProduto.getRowCount() - 1;
        //        tblProduto.setRowSelectionInterval(linha, linha);
        //        tblProduto.scrollRectToVisible(tblProduto.getCellRect(linha, 0, true));

    }//GEN-LAST:event_btnAdicionaProdutoActionPerformed

    private void txtPesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisarKeyReleased
        atualizaGridProduto();
        if (txtPesquisar.getText().isEmpty()) {
            //            produtoList.clear();
        }
    }//GEN-LAST:event_txtPesquisarKeyReleased

    private void txtDescricao1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescricao1FocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_txtDescricao1FocusGained

    private void txtDescricao1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtDescricao1FocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_txtDescricao1FocusLost

    private void cbxFornecedor2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbxFornecedor2FocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_cbxFornecedor2FocusGained

    private void cbxFornecedor2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbxFornecedor2FocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_cbxFornecedor2FocusLost

    private void cbxUnidade2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbxUnidade2FocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_cbxUnidade2FocusGained

    private void cbxUnidade2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_cbxUnidade2FocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_cbxUnidade2FocusLost

    private void btnImportarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImportarActionPerformed
        if (validaCampos()) {
            try {
                salvarRegistroEntrada();

                //                int linhaClicada = tblProduto.getSelectedRow();
                int indexRegistro = tblRegistro.getSelectedRow();

                //                entityManager.getTransaction().begin();
                //                entityManager.getTransaction().commit();
                salvarRegistroEntrada(); // chama mtodo para salvar a entrada e assim podendo inserir itens a entrada
                Entradaprodutodetalhe vd = new Entradaprodutodetalhe();
                EntradaprodutodetalhePK vdpk = new EntradaprodutodetalhePK();

                int indexProduto = tblProduto.getSelectedRow(); // seleciona o registro da jTable produto

                vdpk.setIdEntradaRegistro(entradaRegistroList.get(indexRegistro).getId());
                vdpk.setIdProduto(produtoList.get(indexProduto).getId());
                vd.setEntradaprodutodetalhePK(vdpk);

                int quantidade = (Integer) spnEstoque.getValue();
                if (quantidade >= 1) {

                    /////////////

                    int linhaClicada = tblProduto.getSelectedRow();
                    Produto obj = produtoList.get(linhaClicada);
                    int produtoExtra = (Integer) spnEstoque.getValue();
                    int entradaEstoque = produtoList.get(indexProduto).getNumEstoque() + quantidade;
                    obj.setNumEstoque(entradaEstoque);
                    entityManager.getTransaction().begin();
                    entityManager.persist(obj);
                    entityManager.getTransaction().commit();
                    /////////////

                    vd.setQtde(quantidade);
                    //                    vd.setQtde(obj.getNumEstoque());
                    vd.setVlrUnitario(Double.parseDouble(txtCompra.getText()));
                    double totalEntrada = Double.parseDouble(txtCompra.getText()) * quantidade;
                    vd.setVlrTotal(totalEntrada);
                    System.err.println("Valor: " + vd.getVlrTotal());
                    System.err.println("Valor: " + vd.getVlrUnitario());
                    valorTotal = valorTotal + vd.getVlrTotal();
                    txtTotalEntrada.setText(String.valueOf(valorTotal));
                    entityManager.getTransaction().begin();
                    entityManager.persist(vd);
                    entradaDetalheList.add(vd);
                    entityManager.getTransaction().commit();
                    spnEstoque.setValue(0);
                } else {
                    JOptionPane.showMessageDialog(null, "Adicione um valor ao estoque");
                }

            } catch (Exception e) {

            }
        }
    }//GEN-LAST:event_btnImportarActionPerformed

    private void txtDescricao1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescricao1KeyReleased
        //        atualizaGridProduto();
    }//GEN-LAST:event_txtDescricao1KeyReleased

    private void txtDescricao1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDescricao1KeyPressed
        //        atualizaGridProduto();
    }//GEN-LAST:event_txtDescricao1KeyPressed

    private void btnCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCadastrarActionPerformed
        salvarProduto();
        spnEstoque.setValue(0);
        txtCodigo1.setEnabled(false);
        txtDescricao1.setEnabled(false);
        cbxFornecedor2.setEnabled(false);
        cbxUnidade2.setEnabled(false);
        txtCritico.setEnabled(false);
        txtVendaProduto.setEnabled(false);
        txtCompra.setEnabled(true);
        btnCadastrar.setVisible(false);
        btnImportar.setVisible(true);
    }//GEN-LAST:event_btnCadastrarActionPerformed

    private void txtCriticoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCriticoFocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_txtCriticoFocusGained

    private void spnEstoqueFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_spnEstoqueFocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_spnEstoqueFocusGained

    private void txtCompraFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCompraFocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_txtCompraFocusLost

    private void txtCompraFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCompraFocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_txtCompraFocusGained

    private void txtVendaProdutoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtVendaProdutoFocusGained
        Uteis.entraCampo(evt);
    }//GEN-LAST:event_txtVendaProdutoFocusGained

    private void spnEstoqueFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_spnEstoqueFocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_spnEstoqueFocusLost

    private void txtCriticoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCriticoFocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_txtCriticoFocusLost

    private void txtVendaProdutoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtVendaProdutoFocusLost
        Uteis.saiCampo(evt);
    }//GEN-LAST:event_txtVendaProdutoFocusLost

    private void txtCriticoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCriticoKeyTyped
        Uteis.validaCampoNumericoInteger(evt);
    }//GEN-LAST:event_txtCriticoKeyTyped

    private void txtCompraKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCompraKeyTyped
        Uteis.validaCampoNumericoDouble(evt);
    }//GEN-LAST:event_txtCompraKeyTyped

    private void txtVendaProdutoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtVendaProdutoKeyTyped
        Uteis.validaCampoNumericoDouble(evt);
    }//GEN-LAST:event_txtVendaProdutoKeyTyped

    private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed
        int row = tblRegistro.getSelectedRow();
        int id = entradaRegistroList.get(row).getId();
        sql = "SELECT produto.descricao, entradaprodutodetalhe.qtde, entradaprodutodetalhe.vlrUnitario, entradaprodutodetalhe.vlrTotal from entradaprodutodetalhe as entradaprodutodetalhe INNER JOIN produto as produto ON (entradaprodutodetalhe.idProduto = produto.ID) where idEntradaRegistro = "
                + id;
        System.out.println(sql);
        try {
            relat(sql);
        } catch (SQLException ex) {
            Logger.getLogger(MovimentoEntradaView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DocumentException ex) {
            Logger.getLogger(MovimentoEntradaView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MovimentoEntradaView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnImprimirActionPerformed

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCodigoActionPerformed

    private void atualizaGridProduto() {

        String sql = "from Produto";
        String ordem = "";
        ordem = "descricao";
        String filtro = txtPesquisar.getText();
        if (filtro.length() > 0 && filtro != null) {
            sql += " where upper(" + ordem + ") like '" + filtro.toUpperCase() + "%' ";
        }
        sql += " order by " + ordem;
        System.out.println("SQL Gerado: " + sql);
        produtoQuery = entityManager.createQuery(sql);
        produtoList.clear();
        produtoList.addAll(produtoQuery.getResultList());
        int row = produtoList.size() - 1;
        //        if (row >= 0) {
        //            tblProduto.setRowSelectionInterval(row, row);
        //            tblProduto.scrollRectToVisible(tblProduto.getCellRect(row, row, true));
        //        }

    }

    private void atualizaGridProdutoEstoque() {
        Produto p = new Produto();
        String sql = "from Produto where numEstoque <= numEstoqueCritico";
        String ordem = "";
        ordem = "descricao";
        String filtro = txtPesquisar.getText();
        if (filtro.length() > 0 && filtro != null) {
            sql += " where upper(" + ordem + ") like '" + filtro.toUpperCase() + "%' ";
        }
        sql += " order by " + ordem;
        System.err.println("SQL Gerado: " + sql);
        produtoQuery = entityManager.createQuery(sql);
        produtoList.clear();
        produtoList.addAll(produtoQuery.getResultList());
        int row = produtoList.size() - 1;
        if (row >= 0) {
            tblProduto.setRowSelectionInterval(row, row);
            tblProduto.scrollRectToVisible(tblProduto.getCellRect(row, row, true));
            tblProduto.revalidate();
        }

    }

    private void salvarRegistroEntrada() {
        int linhaClicada = tblRegistro.getSelectedRow();
        Entradaprodutoregistro obj = entradaRegistroList.get(linhaClicada);
        Date data = new Date(System.currentTimeMillis());
        obj.setDataEntrada(data);
        entityManager.getTransaction().begin();
        entityManager.persist(obj);
        entityManager.getTransaction().commit();
    }

    private void salvarProduto() {
        int linhaClicada = tblProduto.getSelectedRow();
        Produto obj = produtoList.get(linhaClicada);
        //        int produtoExtra = (Integer) spnEstoque.getValue();
        obj.setNumEstoque(0);
        entityManager.getTransaction().begin();
        entityManager.persist(obj);
        entityManager.getTransaction().commit();
    }

    private void trataEdicao() {
        // botes e campos de filtro
        btnConfirmar.setEnabled(editando);
        tblDetalhe.setEnabled(editando);
        tblProduto.setEnabled(editando);
        txtPesquisar.setEnabled(editando);
        btnImportar.setEnabled(editando);
        cbxFornecedor.setEnabled(editando);
        btnAdicionaProduto.setEnabled(editando);
    }

    /**
     * Mtodo que valida o campos de preenchimento de formulrio
     *
     * @return
     */
    private boolean validaCampos() {
        if (cbxFornecedor.getSelectedIndex() < 0) {
            JOptionPane.showMessageDialog(null, "Selecione um Fornecedor");
            cbxFornecedor.requestFocus();
            return false;
        }
        if (cbxFornecedor2.getSelectedIndex() < 0) {
            JOptionPane.showMessageDialog(null, "Selecione um Fornecedor para Produto");
            cbxFornecedor2.requestFocus();
            return false;
        }
        if (cbxUnidade2.getSelectedIndex() < 0) {
            JOptionPane.showMessageDialog(null, "Selecione um Tipo de Unidade");
            cbxUnidade2.requestFocus();
            return false;
        }
        return true;

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static java.util.List<br.com.tcc.entity.Produto> atualizaProdutoList;
    public static javax.persistence.Query atualizaProdutoQuery;
    private javax.swing.JButton btnAdicionaProduto;
    private javax.swing.JButton btnCadastrar;
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnImportar;
    private javax.swing.JButton btnImprimir;
    private javax.swing.JButton btnNovaVenda;
    private javax.swing.JComboBox cbxFornecedor;
    private javax.swing.JComboBox cbxFornecedor2;
    private javax.swing.JComboBox cbxUnidade2;
    private javax.persistence.EntityManager entityManager;
    private java.util.List<br.com.tcc.entity.Entradaprodutodetalhe> entradaDetalheList;
    private javax.persistence.Query entradaDetalheQuery;
    private java.util.List<br.com.tcc.entity.Entradaprodutoregistro> entradaRegistroList;
    private javax.persistence.Query entradaRegistroQuery;
    private java.util.List<br.com.tcc.entity.Fornecedor> fornecedorList;
    private javax.persistence.Query fornecedorQuery;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JLabel lblProduto;
    private javax.swing.JPanel pnlBotoesEntrada;
    private javax.swing.JPanel pnlDetalheEntrada;
    private javax.swing.JPanel pnlFormProduto1;
    private javax.swing.JPanel pnlPesquisa;
    private javax.swing.JPanel pnlProduto;
    private javax.swing.JPanel pnlRegistroEntrada;
    private java.util.List<br.com.tcc.entity.Produto> produtoList;
    private javax.persistence.Query produtoQuery;
    private javax.swing.JSpinner spnEstoque;
    private javax.swing.JTable tblDetalhe;
    private javax.swing.JTable tblObjetos1;
    private javax.swing.JTable tblProduto;
    private javax.swing.JTable tblRegistro;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtCodigo1;
    private javax.swing.JTextField txtCompra;
    private javax.swing.JTextField txtCritico;
    private javax.swing.JTextField txtDescricao1;
    private javax.swing.JTextField txtPesquisar;
    private javax.swing.JTextField txtTotalEntrada;
    private javax.swing.JTextField txtVendaProduto;
    private java.util.List<br.com.tcc.entity.Unidade> unidadeList;
    private javax.persistence.Query unidadeQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void relat(String sql) throws SQLException, DocumentException, FileNotFoundException, IOException {
        /* Create Connection objects */
        Connection con = new ConnectionFactory().getConnection();
        Statement stmt = con.createStatement();

        int row = tblRegistro.getSelectedRow();
        int id = entradaRegistroList.get(row).getId();
        SimpleDateFormat horaformatada = new SimpleDateFormat("HH:mm:ss");
        Date horaAtual = new Date();
        hora = horaformatada.format(horaAtual);
        Date data = new Date();
        //  mes    = ""+Data.getMonth();//0 a 11 
        dia = "" + data.getDate();
        ano = "" + (1900 + data.getYear());
        switch (data.getMonth()) {
        case 0:
            mes = "Janeiro";
            break;
        case 1:
            mes = "Fevereiro";
            break;
        case 2:
            mes = "Maro";
            break;
        case 3:
            mes = "Abril";
            break;
        case 4:
            mes = "Maio";
            break;
        case 5:
            mes = "Junho";
            break;
        case 6:
            mes = "Julho";
            break;
        case 7:
            mes = "Agosto";
            break;
        case 8:
            mes = "Setembro";
            break;
        case 9:
            mes = "Outubro";
            break;
        case 10:
            mes = "Novembro";
            break;
        case 11:
            mes = "Dezembro";
            break;
        }

        /* Define the SQL query */
        //         sql = "SELECT cliente.nome, funcionario.nome, tipopagamento.descricao, vendaregistro.dataVenda, vendaregistro.vlrSugerido, vendaregistro.totalVenda, vendaregistro.parcela, vendaregistro.1vencimento, vendaregistro.ativo FROM vendaregistro as vendaregistro INNER JOIN cliente as cliente ON (vendaregistro.idCliente = cliente.id) \n" +
        //"INNER JOIN funcionario as funcionario ON (vendaregistro.idFuncionario = funcionario.id) INNER JOIN tipopagamento as tipopagamento ON (vendaregistro.idTipoPagamento = tipopagamento.id) WHERE  dataVenda = CURRENT_DATE";
        ResultSet query = stmt.executeQuery(sql);
        /* Step-2: Initialize PDF documents - logical objects */
        Document PDFLogReport = new Document();
        PdfWriter.getInstance(PDFLogReport,
                new FileOutputStream("C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".pdf"));
        PDFLogReport.open();

        Paragraph cabecalho = new Paragraph("AGRO EMPRESARIAL - SISTEMA DE GERENCIAMENTO\n"
                + "RUA GONALVES CHAVES, 602 PELOTAS/RS\n" + "FONE:(53) 3232-3232 BAIRRO: CENTRO\n"
                + "CNPJ: 12.345.678/1011-12\n" + "-------------------------------------------\n" + dia + "/" + mes
                + "/" + ano + "   " + hora + "   COD: " + id + " \n\n");
        cabecalho.setAlignment(Element.ALIGN_CENTER);

        PDFLogReport.add(cabecalho);
        //we have two columns in our table  
        PdfPTable LogTable = new PdfPTable(4);

        // Ttulo para a tabela
        Paragraph tableHeader = new Paragraph("Relatrio de Entrada de Estoque");

        PdfPCell header = new PdfPCell(tableHeader);

        // Definindo que o header vai ocupar as 2 colunas
        header.setColspan(4);
        // Definindo alinhamento do header
        header.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        // Adicionando o header  tabela

        Font fonte = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD, BaseColor.BLACK);
        Font fonteDados = new Font(Font.FontFamily.TIMES_ROMAN, 6, Font.NORMAL, BaseColor.BLACK);

        LogTable.addCell(header);
        LogTable.addCell(new Paragraph("Produto ", fonte));
        LogTable.addCell(new Paragraph("Quantidade", fonte));
        LogTable.addCell(new Paragraph("Valor Unitrio", fonte));
        LogTable.addCell(new Paragraph("Valor Total", fonte));
        //create a cell object  
        //         PdfPCell table_cell;  
        while (query.next()) {
            String produto = query.getString("produto.descricao");
            LogTable.addCell(new Paragraph(produto, fonteDados));
            String quantidade = query.getString("qtde");
            LogTable.addCell(new Paragraph(quantidade, fonteDados));
            String vlrSugerido = query.getString("vlrUnitario");
            LogTable.addCell(new Paragraph(vlrSugerido, fonteDados));
            String vlrTotal = query.getString("vlrTotal");
            LogTable.addCell(new Paragraph(vlrTotal, fonteDados));
        }
        /* Attach report table to PDF */
        PDFLogReport.add(LogTable);
        double valor = entradaRegistroList.get(row).getVlrTotal();
        Paragraph paragrafoValor = new Paragraph("Valor R$: " + valor);
        paragrafoValor.setAlignment(Element.ALIGN_RIGHT);
        PDFLogReport.add(paragrafoValor);

        PDFLogReport.close();
        /* Close all DB related objects */
        query.close();
        stmt.close();
        con.close();
        String file;
        file = "C:\\Users\\Leonardo P Souza\\Desktop\\Relat\\Entrada " + id + ".pdf";
        Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file);
    }
}