/*
 * 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.visao.telas.cadastro;

import br.com.conexao.conexao;
import br.com.controle.vendas_e_servicosControl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Rafael Paes Leme
 */
public class vendas_e_servicos extends javax.swing.JInternalFrame {

    /**
     * Creates new form vendas_e_servicos
     */
    public vendas_e_servicos() {
        initComponents();
    }

    /**
     * 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() {

        jPanel3 = new javax.swing.JPanel();
        bt_salvar_cvs = new javax.swing.JButton();
        bt_limpar_cvs = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        id_cvs = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        cbx_tipo_cvs = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        nome_cvs = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cbx_produto_cvs = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        id_pord_cvs = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        local_cvs = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        dt_cvs = new javax.swing.JFormattedTextField();
        jLabel8 = new javax.swing.JLabel();
        hora_cvs = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        vendedor_cvs = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        id_vendedor_cvs = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        obs_cvs = new javax.swing.JTextArea();

        setClosable(true);
        setIconifiable(true);
        setTitle("Cadastro de Vendas e Serviços");

        jPanel3.setBackground(new java.awt.Color(0, 102, 153));

        bt_salvar_cvs.setBackground(new java.awt.Color(0, 153, 204));
        bt_salvar_cvs.setFont(new java.awt.Font("Khmer UI", 1, 14)); // NOI18N
        bt_salvar_cvs.setForeground(new java.awt.Color(255, 255, 255));
        bt_salvar_cvs.setText("SALVAR");
        bt_salvar_cvs.setBorderPainted(false);
        bt_salvar_cvs.setContentAreaFilled(false);
        bt_salvar_cvs.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bt_salvar_cvs.setOpaque(true);
        bt_salvar_cvs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_salvar_cvsActionPerformed(evt);
            }
        });

        bt_limpar_cvs.setBackground(new java.awt.Color(0, 153, 204));
        bt_limpar_cvs.setFont(new java.awt.Font("Khmer UI", 1, 14)); // NOI18N
        bt_limpar_cvs.setForeground(new java.awt.Color(255, 255, 255));
        bt_limpar_cvs.setText("LIMPAR");
        bt_limpar_cvs.setBorderPainted(false);
        bt_limpar_cvs.setContentAreaFilled(false);
        bt_limpar_cvs.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bt_limpar_cvs.setOpaque(true);
        bt_limpar_cvs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpar_cvsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bt_salvar_cvs)
                .addGap(18, 18, 18)
                .addComponent(bt_limpar_cvs)
                .addContainerGap(577, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_salvar_cvs)
                    .addComponent(bt_limpar_cvs))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

        jLabel1.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel1.setText("ID");

        id_cvs.setEditable(false);
        id_cvs.setBackground(new java.awt.Color(255, 255, 204));
        id_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel2.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel2.setText("Tipo");

        cbx_tipo_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        cbx_tipo_cvs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Serviço", "Venda", " " }));

        jLabel3.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel3.setText("Nome");

        nome_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel4.setText("Produto");

        cbx_produto_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        cbx_produto_cvs.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Clique aqui para carregar lista de Fornecedores." }));
        cbx_produto_cvs.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                cbx_produto_cvsComponentAdded(evt);
            }
        });
        cbx_produto_cvs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                cbx_produto_cvsMousePressed(evt);
            }
        });
        cbx_produto_cvs.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                cbx_produto_cvsComponentShown(evt);
            }
        });
        cbx_produto_cvs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbx_produto_cvsActionPerformed(evt);
            }
        });
        cbx_produto_cvs.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cbx_produto_cvsKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel5.setText("ID Produto");

        id_pord_cvs.setEditable(false);
        id_pord_cvs.setBackground(new java.awt.Color(255, 255, 204));
        id_pord_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel6.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel6.setText("Local");

        local_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel7.setText("Data");

        try {
            dt_cvs.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        dt_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel8.setText("Hora");

        try {
            hora_cvs.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##:##:##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        hora_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel9.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel9.setText("Vendedor");

        vendedor_cvs.setEditable(false);
        vendedor_cvs.setBackground(new java.awt.Color(255, 255, 204));
        vendedor_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel10.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("ID Vendedor");

        id_vendedor_cvs.setEditable(false);
        id_vendedor_cvs.setBackground(new java.awt.Color(255, 255, 204));
        id_vendedor_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N

        jLabel11.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        jLabel11.setText("Observação");

        obs_cvs.setColumns(20);
        obs_cvs.setFont(new java.awt.Font("Khmer UI", 0, 11)); // NOI18N
        obs_cvs.setLineWrap(true);
        obs_cvs.setRows(5);
        jScrollPane1.setViewportView(obs_cvs);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel4)
                            .addComponent(jLabel1))
                        .addGap(2, 2, 2))
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(id_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbx_tipo_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nome_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(local_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(cbx_produto_cvs, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(43, 43, 43)))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(dt_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(vendedor_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 435, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, Short.MAX_VALUE)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(hora_cvs, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(id_pord_cvs, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(id_vendedor_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1))
                .addContainerGap(74, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(id_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(cbx_tipo_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(nome_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbx_produto_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(id_pord_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(local_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(dt_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7)
                        .addComponent(hora_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(id_vendedor_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9)
                    .addComponent(vendedor_cvs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(89, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    private void bt_salvar_cvsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_salvar_cvsActionPerformed

        SalvarDados();

        // TODO add your handling code here:
    }//GEN-LAST:event_bt_salvar_cvsActionPerformed

    private void bt_limpar_cvsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpar_cvsActionPerformed

        LimparCampos();

// TODO add your handling code here:
    }//GEN-LAST:event_bt_limpar_cvsActionPerformed

    private void cbx_produto_cvsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbx_produto_cvsMousePressed

        Listar_Produtos_CBX();

// TODO add your handling code here:
    }//GEN-LAST:event_cbx_produto_cvsMousePressed

    private void cbx_produto_cvsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbx_produto_cvsActionPerformed

        ListarProdutos_ID();
        ExibirVendedor();

// TODO add your handling code here:
    }//GEN-LAST:event_cbx_produto_cvsActionPerformed

    private void cbx_produto_cvsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cbx_produto_cvsKeyPressed

        // TODO add your handling code here:
    }//GEN-LAST:event_cbx_produto_cvsKeyPressed

    private void cbx_produto_cvsComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_cbx_produto_cvsComponentAdded

        ListarProdutos_ID();

        // TODO add your handling code here:
    }//GEN-LAST:event_cbx_produto_cvsComponentAdded

    private void cbx_produto_cvsComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_cbx_produto_cvsComponentShown

        // TODO add your handling code here:
    }//GEN-LAST:event_cbx_produto_cvsComponentShown

    public void ListarProdutos_ID() {

        String buscarId = (String) cbx_produto_cvs.getSelectedItem();

        try {

            if (!buscarId.equals("")) {

                Connection conn = conexao.GeraConexao();

                String sql = "SELECT * FROM GOSPAD_BD.produtos WHERE nome = ?";

                PreparedStatement comando = conn.prepareStatement(sql);

                comando.setString(1, buscarId);

                ResultSet rs = comando.executeQuery();

                while (rs.next()) {

                    id_pord_cvs.setText(rs.getString("id"));

                }

            } else {
                JOptionPane.showMessageDialog(null, "Selecione um ID!");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void ExibirVendedor() {

        try {

            Connection conn = conexao.GeraConexao();

            String sql = "SELECT * FROM GOSPAD_BD.vendedor";

            PreparedStatement comando = conn.prepareStatement(sql);

            ResultSet rs = comando.executeQuery();

            while (rs.next()) {

                vendedor_cvs.setText(rs.getString("vendedor"));
                id_vendedor_cvs.setText(rs.getString("id_vendedor"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e);
        }

    }

    public void Listar_Produtos_CBX() {

        try {

            Connection conn = conexao.GeraConexao();

            String sql = "SELECT * FROM GOSPAD_BD.produtos";

            PreparedStatement comando = conn.prepareStatement(sql);

            ResultSet rs = comando.executeQuery();

            cbx_produto_cvs.removeAllItems();

            while (rs.next()) {

                cbx_produto_cvs.addItem(rs.getString("nome"));

            }

        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e);
        }

    }

    public void LimparCampos() {

        id_cvs.setText(null);
        nome_cvs.setText(null);
        cbx_produto_cvs.addItem("");
        id_pord_cvs.setText(null);
        local_cvs.setText(null);
        dt_cvs.setText(null);
        hora_cvs.setText(null);
        vendedor_cvs.setText(null);
        id_vendedor_cvs.setText(null);
        obs_cvs.setText(null);

    }

    public void SalvarDados() {

        ArrayList<String> Registro = new ArrayList<>();
        Registro.add(id_cvs.getText());
        Registro.add((String) cbx_tipo_cvs.getSelectedItem());
        Registro.add(nome_cvs.getText());
        Registro.add((String) cbx_produto_cvs.getSelectedItem());
        Registro.add(id_pord_cvs.getText());
        Registro.add(local_cvs.getText());

        if ("  /  /    ".equals(dt_cvs.getText())) {
            Registro.add("00/00/0000");
        } else {
            Registro.add(dt_cvs.getText());
        }

        Registro.add(hora_cvs.getText());
        Registro.add(vendedor_cvs.getText());
        Registro.add(id_vendedor_cvs.getText());
        Registro.add(obs_cvs.getText());

        vendas_e_servicosControl Controllerves = new vendas_e_servicosControl();
        try {
            //
            Controllerves.Salvar(Registro);
            //

// TODO add your handling code here:
        } catch (ParseException ex) {

            JOptionPane.showMessageDialog(null, "Erro Fatal! Erro, " + ex + ". Informações inseridas incorretamentes!");

            Logger.getLogger(fornecedores.class.getName()).log(Level.SEVERE, null, ex);
        }

        LimparCampos();

    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_limpar_cvs;
    private javax.swing.JButton bt_salvar_cvs;
    private javax.swing.JComboBox cbx_produto_cvs;
    private javax.swing.JComboBox cbx_tipo_cvs;
    private javax.swing.JFormattedTextField dt_cvs;
    private javax.swing.JFormattedTextField hora_cvs;
    private javax.swing.JTextField id_cvs;
    private javax.swing.JTextField id_pord_cvs;
    private javax.swing.JTextField id_vendedor_cvs;
    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.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField local_cvs;
    private javax.swing.JTextField nome_cvs;
    private javax.swing.JTextArea obs_cvs;
    private javax.swing.JTextField vendedor_cvs;
    // End of variables declaration//GEN-END:variables
}
