/*
 * 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 Calculos_automaticos;
import arql2020.*;
import static arql2020.ARQL2020.capa_nivel;
import static arql2020.ARQL2020.cuadro;
import static arql2020.ARQL2020.episodio_estruct_planta;
import static arql2020.ARQL2020.estruct_arq;
import static arql2020.ARQL2020.indexMP;
import static arql2020.ARQL2020.localidad;
import static arql2020.ARQL2020.microsector;
import static arql2020.ARQL2020.nombre_estruct_planta;
import static arql2020.ARQL2020.piso_subcapa;
import static arql2020.ARQL2020.siglasitio;
import static arql2020.ARQL2020.sitio;
import static arql2020.ARQL2020.tipo_estruct_planta;
import static arql2020.ARQL2020.zona_ambiental;
//import static arql2020.DT_sintalon.peso;
import clases.conexion;
import static clases.conexion.ingresado;
import com.mysql.jdbc.PreparedStatement;
import java.awt.event.ItemEvent;
import static java.lang.Float.parseFloat;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class Procedencia_Muestras extends javax.swing.JFrame {

int faltante = 0;
    public Procedencia_Muestras() {
        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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        zona_ambiental = new javax.swing.JComboBox<>();
        jLabel3 = new javax.swing.JLabel();
        localidad = new javax.swing.JComboBox<>();
        jLabel4 = new javax.swing.JLabel();
        sitio = new javax.swing.JComboBox<>();
        agregar_zona = new javax.swing.JButton();
        agregar_localidad = new javax.swing.JButton();
        agregar_SITIO = new javax.swing.JButton();
        agregar_siglasitio = new javax.swing.JButton();
        siglasitio = new javax.swing.JComboBox<>();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        capa = new javax.swing.JComboBox<>();
        agregar_capa = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        piso_subcapa = new javax.swing.JComboBox<>();
        agregar_piso_subcapa = new javax.swing.JButton();
        agregar_estructura_arq = new javax.swing.JButton();
        estructura_arq = new javax.swing.JComboBox<>();
        jLabel9 = new javax.swing.JLabel();
        estructura_pl = new javax.swing.JComboBox<>();
        agregar_estructura_pl = new javax.swing.JButton();
        tipo_estruc_pl = new javax.swing.JComboBox<>();
        agregar_episodio = new javax.swing.JButton();
        episodio_estruc_pl = new javax.swing.JComboBox<>();
        jLabel10 = new javax.swing.JLabel();
        cuadro = new javax.swing.JComboBox<>();
        agregar_cuadro = new javax.swing.JButton();
        agregar_microsector = new javax.swing.JButton();
        microsector = new javax.swing.JComboBox<>();
        jLabel11 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbl_muestra = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(51, 51, 51));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Zona ambiental");

        zona_ambiental.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        zona_ambiental.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                zona_ambientalItemStateChanged(evt);
            }
        });
        zona_ambiental.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zona_ambientalActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Localidad arqueológica");

        localidad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        localidad.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                localidadItemStateChanged(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Sitio");

        sitio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        sitio.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                sitioItemStateChanged(evt);
            }
        });

        agregar_zona.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_zona.setText("+");
        agregar_zona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_zonaActionPerformed(evt);
            }
        });

        agregar_localidad.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_localidad.setText("+");
        agregar_localidad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_localidadActionPerformed(evt);
            }
        });

        agregar_SITIO.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_SITIO.setText("+");
        agregar_SITIO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_SITIOActionPerformed(evt);
            }
        });

        agregar_siglasitio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_siglasitio.setText("+");
        agregar_siglasitio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_siglasitioActionPerformed(evt);
            }
        });

        siglasitio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Sigla sitio");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Capa o nivel");

        capa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        capa.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                capaItemStateChanged(evt);
            }
        });

        agregar_capa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_capa.setText("+");
        agregar_capa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_capaActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 0));
        jLabel7.setText("Estructura arquitectónica");

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 255, 0));
        jLabel13.setText("Piso o subcapa de la estructura arquitectónica");

        piso_subcapa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        agregar_piso_subcapa.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_piso_subcapa.setText("+");
        agregar_piso_subcapa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_piso_subcapaActionPerformed(evt);
            }
        });

        agregar_estructura_arq.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_estructura_arq.setText("+");
        agregar_estructura_arq.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_estructura_arqActionPerformed(evt);
            }
        });

        estructura_arq.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        estructura_arq.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                estructura_arqItemStateChanged(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 102, 0));
        jLabel9.setText("Denominación de la estructura de planta");

        estructura_pl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        estructura_pl.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                estructura_plItemStateChanged(evt);
            }
        });

        agregar_estructura_pl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_estructura_pl.setText("+");
        agregar_estructura_pl.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_estructura_plActionPerformed(evt);
            }
        });

        tipo_estruc_pl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tipo_estruc_pl.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Seleccione el tipo de estruc. en planta", "Acumulación de vegetales", "Acumulación de restos faunísticos", "Acumulación líticos", "Estructura de combustión", "Estructura de cavado", "Otra 1", "Otra 2", "Otra 3", "Otra 4", "Otra 5", "CN" }));
        tipo_estruc_pl.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                tipo_estruc_plItemStateChanged(evt);
            }
        });

        agregar_episodio.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_episodio.setText("+");
        agregar_episodio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_episodioActionPerformed(evt);
            }
        });

        episodio_estruc_pl.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(0, 255, 204));
        jLabel10.setText("Cuadro");

        cuadro.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cuadro.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cuadroItemStateChanged(evt);
            }
        });

        agregar_cuadro.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_cuadro.setText("+");
        agregar_cuadro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_cuadroActionPerformed(evt);
            }
        });

        agregar_microsector.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        agregar_microsector.setText("+");
        agregar_microsector.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregar_microsectorActionPerformed(evt);
            }
        });

        microsector.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(0, 255, 204));
        jLabel11.setText("Microsector");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Procedencia");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 102, 0));
        jLabel8.setText("Tipo de estructura de planta");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel12.setForeground(new java.awt.Color(255, 102, 0));
        jLabel12.setText("Episodio de la estructura de planta");

        tbl_muestra.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tbl_muestra.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ZONA AMBIENTAL", "LOCALIDAD", "SITIO", "SIGLA SITIOl", "NIVEL", "EST.ARQ.", "PISO_SUBCAPA", "EST.PL.", "TIPO EST.PL.", "EPISODIO EST.PL.", "CUADRO", "MICROSECTOR"
            }
        ));
        tbl_muestra.setRowHeight(20);
        jScrollPane2.setViewportView(tbl_muestra);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton1.setText("Seleccionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton2.setText("Guardar muestra");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(125, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addGap(18, 18, 18)
                                .addComponent(microsector, javax.swing.GroupLayout.PREFERRED_SIZE, 337, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cuadro, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(agregar_microsector)
                            .addComponent(agregar_cuadro))
                        .addGap(608, 608, 608))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(localidad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(zona_ambiental, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sitio, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(siglasitio, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 507, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(agregar_SITIO)
                            .addComponent(agregar_siglasitio)
                            .addComponent(agregar_localidad)
                            .addComponent(agregar_zona))
                        .addGap(416, 416, 416))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(215, 215, 215)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tipo_estruc_pl, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(episodio_estruc_pl, javax.swing.GroupLayout.PREFERRED_SIZE, 397, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(agregar_episodio))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(28, 28, 28)
                                .addComponent(estructura_pl, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(agregar_estructura_pl))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(47, 47, 47)
                                .addComponent(jLabel6)
                                .addGap(18, 18, 18)
                                .addComponent(capa, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(agregar_capa))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel13)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addGap(298, 298, 298)
                                            .addComponent(piso_subcapa, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGap(18, 18, 18)
                                    .addComponent(agregar_piso_subcapa))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel7)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(estructura_arq, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(agregar_estructura_arq)))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jSeparator1))
                                .addGap(875, 875, 875))
                            .addComponent(jScrollPane2)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel2)
                    .addComponent(zona_ambiental, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(agregar_zona))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel3)
                    .addComponent(localidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(agregar_localidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(agregar_SITIO)
                    .addComponent(sitio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel5)
                    .addComponent(siglasitio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(agregar_siglasitio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(capa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(agregar_capa))
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(agregar_estructura_arq)
                    .addComponent(estructura_arq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(agregar_piso_subcapa)
                    .addComponent(piso_subcapa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addGap(23, 23, 23)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(agregar_estructura_pl)
                    .addComponent(estructura_pl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel8)
                    .addComponent(tipo_estruc_pl, 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.CENTER)
                    .addComponent(agregar_episodio)
                    .addComponent(episodio_estruc_pl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cuadro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(agregar_cuadro)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(agregar_microsector)
                    .addComponent(microsector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(22, 22, 22)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(80, Short.MAX_VALUE))
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1050, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1)
                .addGap(0, 0, 0))
        );

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

 private void agregarCN(JComboBox combo){

int itemscount =  combo.getItemCount();
int contieneCN = 0; 
     for (int i = 0; i < itemscount; i++) {
         if(combo.getItemAt(i).equals("CN")){
             contieneCN=-1;
         }
     }
     if(contieneCN>-1){
         combo.addItem("CN");
     }

 }
    private void zona_ambientalItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_zona_ambientalItemStateChanged

        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.zona_ambiental.getSelectedIndex()>0){

                localidad.removeAllItems();
                localidad.addItem("Seleccione la localidad");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT LOCALIDAD FROM PROCEDENCIA WHERE ZONA_AMBIENTAL='"+zona_ambiental.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        localidad.addItem(rs.getString("LOCALIDAD"));
                    }

                    c.closeconnection();
                    agregarCN(localidad);
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

            }else{
                localidad.removeAllItems();
            }
        }
        
        sitio.removeAllItems();
        siglasitio.removeAllItems();
        capa.removeAllItems();
        estructura_arq.removeAllItems();
        piso_subcapa.removeAllItems();
        estructura_pl.removeAllItems();
        episodio_estruc_pl.removeAllItems();
        cuadro.removeAllItems();
        microsector.removeAllItems();
        tipo_estruc_pl.setSelectedIndex(0);
        
        
    }//GEN-LAST:event_zona_ambientalItemStateChanged

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

    }//GEN-LAST:event_zona_ambientalActionPerformed

    private void localidadItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_localidadItemStateChanged
        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.localidad.getSelectedIndex()>0){

                sitio.removeAllItems();
                sitio.addItem("Seleccione el sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT SITIO FROM PROCEDENCIA WHERE LOCALIDAD='"+localidad.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        sitio.addItem(rs.getString("SITIO"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        }

        agregarCN(sitio);
        siglasitio.removeAllItems();
        capa.removeAllItems();
        estructura_arq.removeAllItems();
        piso_subcapa.removeAllItems();
        estructura_pl.removeAllItems();
        episodio_estruc_pl.removeAllItems();
        cuadro.removeAllItems();
        microsector.removeAllItems();
        tipo_estruc_pl.setSelectedIndex(0);
    }//GEN-LAST:event_localidadItemStateChanged

    private void sitioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sitioItemStateChanged
        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.sitio.getSelectedIndex()>0){

                siglasitio.removeAllItems();
                siglasitio.addItem("Seleccione la sigla del sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT SIGLA_SITIO FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        siglasitio.addItem(rs.getString("SIGLA_SITIO"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

                agregarCN(siglasitio);
                //Carga las capas
                capa.removeAllItems();
                capa.addItem("Seleccione la capa o nivel del sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT CAPA_NIVEL FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        capa.addItem(rs.getString("CAPA_NIVEL"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }
                agregarCN(capa);

                //Carga las estructuras arquitectonicas
                estructura_arq.removeAllItems();
                estructura_arq.addItem("Seleccione la estructura arq. del sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT ESTRUC_ARQ FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        estructura_arq.addItem(rs.getString("ESTRUC_ARQ"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

                agregarCN(estructura_arq);
                //Carga las estructuras de planta
                estructura_pl.removeAllItems();
                estructura_pl.addItem("Seleccione la estructura de planta del sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT NOMBRE_ESTRUC_PLANTA FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        estructura_pl.addItem(rs.getString("NOMBRE_ESTRUC_PLANTA"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

                agregarCN(estructura_pl);
                //Carga lOS CUADROS
                cuadro.removeAllItems();
                cuadro.addItem("Seleccione el cuadro del sitio");
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT CUADRO FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"'");

                    while(rs.next()){
                        cuadro.addItem(rs.getString("CUADRO"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        }
        agregarCN(cuadro);
        tipo_estruc_pl.setSelectedIndex(0);
        microsector.removeAllItems();
        microsector.addItem("Seleccione un microsector del cuadro");
        agregarCN(microsector);
        episodio_estruc_pl.removeAllItems();
        episodio_estruc_pl.addItem("Seleccione un episodio de la estruc. en planta");
        agregarCN(episodio_estruc_pl);
        piso_subcapa.removeAllItems();
        piso_subcapa.addItem("Seleccione un piso o subcapa de la estruc. arq.");
        agregarCN(piso_subcapa);

    }//GEN-LAST:event_sitioItemStateChanged
                                                     

    private void capaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_capaItemStateChanged

    }//GEN-LAST:event_capaItemStateChanged

    private void estructura_arqItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_estructura_arqItemStateChanged

        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.estructura_arq.getSelectedIndex()>0){

                piso_subcapa.removeAllItems();
                piso_subcapa.addItem("Seleccione un piso o subcapa de la estruc. arq.");

                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT PISO_SUBCAPA FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"' AND  ESTRUC_ARQ='"+estructura_arq.getSelectedItem().toString()+"'" );

                    while(rs.next()){
                        piso_subcapa.addItem(rs.getString("PISO_SUBCAPA"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        agregarCN(piso_subcapa);
    }//GEN-LAST:event_estructura_arqItemStateChanged

    private void estructura_plItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_estructura_plItemStateChanged
        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.estructura_pl.getSelectedIndex()>0){

                episodio_estruc_pl.removeAllItems();
                episodio_estruc_pl.addItem("Seleccione un episodio de la estruc. en planta");

                //CARGA EPISODIOS DE LA ESTRUCTURA DE PLANTA
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT EPISODIO_ESTRUC_PLANTA FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"' AND  NOMBRE_ESTRUC_PLANTA='"+estructura_pl.getSelectedItem().toString()+"'" );

                    while(rs.next()){
                        episodio_estruc_pl.addItem(rs.getString("EPISODIO_ESTRUC_PLANTA"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }
                //CARGA TIPO DE LA ESTRUCTURA DE PLANTA
                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT ESTRUC_PLANTA FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"' AND  NOMBRE_ESTRUC_PLANTA='"+estructura_pl.getSelectedItem().toString()+"'" );

                    if(rs.next()){
                        tipo_estruc_pl.setSelectedItem(rs.getString("ESTRUC_PLANTA"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
        }
        agregarCN(episodio_estruc_pl);
    }//GEN-LAST:event_estructura_plItemStateChanged

    private void tipo_estruc_plItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_tipo_estruc_plItemStateChanged

        //                        if(evt.getStateChange() == ItemEvent.SELECTED){
            //            if(this.sitio.getSelectedIndex()>0){
                //                   siglasitio.removeAllItems();
                ////                   buscarsiglasitio();
                //            }
            //    }
    }//GEN-LAST:event_tipo_estruc_plItemStateChanged
                                                  

    private void cuadroItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cuadroItemStateChanged

        if(evt.getStateChange() == ItemEvent.SELECTED){
            if(this.cuadro.getSelectedIndex()>0){

                microsector.removeAllItems();
                microsector.addItem("Seleccione un microsector del cuadro");

                try {
                    conexion c = new conexion();
                    c.getConexion();

                    ResultSet rs = c.consulta("SELECT DISTINCT MICROSECTOR FROM PROCEDENCIA WHERE SITIO='"+sitio.getSelectedItem().toString()+"' AND  CUADRO='"+cuadro.getSelectedItem().toString()+"'" );

                    while(rs.next()){
                        microsector.addItem(rs.getString("MICROSECTOR"));
                    }

                    c.closeconnection();
                } catch (SQLException ex) {
                    Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        agregarCN(microsector);
    }//GEN-LAST:event_cuadroItemStateChanged

    private void agregar_cuadroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_cuadroActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca un nuevo cuadro:" );
if(!entradaUsuario.equals("")){
        cuadro.addItem(entradaUsuario.toUpperCase());
}
    
    }//GEN-LAST:event_agregar_cuadroActionPerformed

    private void agregar_microsectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_microsectorActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca un nuevo microsector para la cuadrícula seleccionada:" );
if(!entradaUsuario.equals("")){
        microsector.addItem(entradaUsuario.toUpperCase());
}
    
    }//GEN-LAST:event_agregar_microsectorActionPerformed
private void verificarcamposnulos(JComboBox combo, String variable){
    
    if((combo.getItemCount()==0)||(combo.getSelectedIndex()==0)){
        JOptionPane.showMessageDialog(null, "No puede dejar el campo" + "'" + variable +"'" + " vacío. Seleccione la opción de 'CN'");
        faltante=-1;
    }
    
}    private void buscarvariedadzonaambiental (){

zona_ambiental.removeAllItems();
zona_ambiental.addItem("Seleccione la zona ambiental");
    try {
            conexion c = new conexion();
            c.getConexion();
            
            ResultSet rs = c.consulta("SELECT DISTINCT ZONA_AMBIENTAL FROM PROCEDENCIA");
            
            while(rs.next()){
               zona_ambiental.addItem(rs.getString("ZONA_AMBIENTAL")); 
            }       
        
        c.closeconnection();
        } catch (SQLException ex) {
            Logger.getLogger(procedencia.class.getName()).log(Level.SEVERE, null, ex);
        }
zona_ambiental.addItem("CN");    

    }
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

buscarvariedadzonaambiental();

zona_ambiental.setSelectedItem(ARQL2020.zona_ambiental);
localidad.setSelectedItem(ARQL2020.localidad);
sitio.setSelectedItem(ARQL2020.sitio);
siglasitio.setSelectedItem(ARQL2020.siglasitio);
capa.setSelectedItem(ARQL2020.capa_nivel);
estructura_arq.setSelectedItem(ARQL2020.estruct_arq);
piso_subcapa.setSelectedItem(ARQL2020.piso_subcapa);
estructura_pl.setSelectedItem(ARQL2020.nombre_estruct_planta);
tipo_estruc_pl.setSelectedItem(ARQL2020.tipo_estruct_planta);
episodio_estruc_pl.setSelectedItem(ARQL2020.episodio_estruct_planta);
cuadro.setSelectedItem(ARQL2020.cuadro);
microsector.setSelectedItem(ARQL2020.microsector);
    }//GEN-LAST:event_formWindowOpened

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
int a = 0 ; 
a = a + verificarcbx(zona_ambiental);
a = a + verificarcbx(localidad);
a = a + verificarcbx(sitio);
a = a + verificarcbx(siglasitio);
a = a + verificarcbx(capa);
a = a + verificarcbx(estructura_arq);
a = a + verificarcbx(piso_subcapa);
a = a + verificarcbx(estructura_pl);
a = a + verificarcbx(tipo_estruc_pl);
a = a + verificarcbx(episodio_estruc_pl);
a = a + verificarcbx(cuadro);
a = a + verificarcbx(microsector);
 System.out.println("a:" +a);  
if(a==0){
   DefaultTableModel dtm = (DefaultTableModel) tbl_muestra.getModel();
    Object []fila = new Object[12];
    
    fila[0]=zona_ambiental.getSelectedItem();
    fila[1]=localidad.getSelectedItem();
    fila[2]=sitio.getSelectedItem();
    fila[3]=siglasitio.getSelectedItem();
    fila[4]=capa.getSelectedItem();
    fila[5]=estructura_arq.getSelectedItem();
    fila[6]=piso_subcapa.getSelectedItem();
    fila[7]=estructura_pl.getSelectedItem();
    fila[8]=tipo_estruc_pl.getSelectedItem();
    fila[9]=episodio_estruc_pl.getSelectedItem();
    fila[10]=cuadro.getSelectedItem();
    fila[11]=microsector.getSelectedItem();
    
    dtm.addRow(fila);
       }else{
    JOptionPane.showMessageDialog(null, "Para seleccionar la muestra todos los casilleros deben estar llenos. \n Si desea omitir un campo, seleccione la opción 'CN'");
}
    }//GEN-LAST:event_jButton1ActionPerformed

    private void agregar_episodioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_episodioActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca un nuevo episodio para la estructura en planta seleccionada:" );
        if(!entradaUsuario.equals("")){

            episodio_estruc_pl.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_episodioActionPerformed

    private void agregar_estructura_plActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_estructura_plActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca una nueva estructura de planta:" );
        if(!entradaUsuario.equals("")){
            estructura_pl.addItem(entradaUsuario.toUpperCase());
        }

    }//GEN-LAST:event_agregar_estructura_plActionPerformed

    private void agregar_piso_subcapaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_piso_subcapaActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca un nuevo piso o subcapa de la estructura arq. seleccionada:" );
        if(!entradaUsuario.equals("")){
            piso_subcapa.addItem(entradaUsuario.toUpperCase());
        }

    }//GEN-LAST:event_agregar_piso_subcapaActionPerformed

    private void agregar_estructura_arqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_estructura_arqActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca una nueva estructura arquitectónica:" );
        if(!entradaUsuario.equals("")){

            estructura_arq.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_estructura_arqActionPerformed

    private void agregar_capaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_capaActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca una capa para el sitio:" );
        if(!entradaUsuario.equals("")){
            capa.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_capaActionPerformed

    private void agregar_siglasitioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_siglasitioActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca la sigla del sitio seleccionado:" );
        if(!entradaUsuario.equals("")){
            siglasitio.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_siglasitioActionPerformed

    private void agregar_SITIOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_SITIOActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca un nuevo sitio:" );
        if(!entradaUsuario.equals("")){
            sitio.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_SITIOActionPerformed

    private void agregar_localidadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_localidadActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca una nueva localidad:" );
        if(!entradaUsuario.equals("")){
            localidad.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_localidadActionPerformed

    private void agregar_zonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregar_zonaActionPerformed
        String entradaUsuario = JOptionPane.showInputDialog ( "Introduzca una nueva zona ambiental:" );
        if(!entradaUsuario.equals("")){
            zona_ambiental.addItem(entradaUsuario.toUpperCase());
        }
    }//GEN-LAST:event_agregar_zonaActionPerformed

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


    
String sentencia = "WHERE ";
int filas = tbl_muestra.getRowCount();
String aux;
if(filas==1){
     aux = fabricarsentencia(0);
     sentencia = sentencia + aux; 
    }if(filas>1){
        for (int i = 0; i < tbl_muestra.getRowCount(); i++) {
            if(filas-1==i){
            aux = fabricarsentencia(i);
            sentencia = sentencia + aux;    
            }else{
            aux = fabricarsentencia(i);
            sentencia = sentencia + aux + " OR ";    

            }
            }
        }
Muestras mu = new Muestras();
mu.setVisible(true);
mu.txt_sentencia.setText(sentencia);
mu.btn_guardar.setEnabled(true);
        


    }//GEN-LAST:event_jButton2ActionPerformed
private String fabricarsentencia(int fila){
    String sent = "(";
    if(!tbl_muestra.getValueAt(fila, 0).toString().equals("CN")){
    sent = sent + "f.ZONA_AMBIENTAL='" + tbl_muestra.getValueAt(fila, 0).toString() + "' ";
}

    if(!tbl_muestra.getValueAt(fila, 1).toString().equals("CN")){
    sent =  sent + "AND f.LOCALIDAD='" + tbl_muestra.getValueAt(fila, 1).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 2).toString().equals("CN")){
    sent =  sent + "AND f.SITIO='" + tbl_muestra.getValueAt(fila, 2).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 3).toString().equals("CN")){
    sent =  sent + "AND f.SIGLA_SITIO='" + tbl_muestra.getValueAt(fila, 3).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 4).toString().equals("CN")){
    sent =  sent + "AND f.CAPA_NIVEL='" + tbl_muestra.getValueAt(fila, 4).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 5).toString().equals("CN")){
    sent =  sent + "AND f.ESTRUC_ARQ='" + tbl_muestra.getValueAt(fila, 5).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 6).toString().equals("CN")){
    sent =  sent + "AND f.PISO_SUBCAPA='" + tbl_muestra.getValueAt(fila, 6).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 7).toString().equals("CN")){
    sent =  sent + "AND f.NOMBRE_ESTRUC_PLANTA='" + tbl_muestra.getValueAt(fila, 7).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 8).toString().equals("CN")){
    sent =  sent + "AND f.ESTRUC_PLANTA='" + tbl_muestra.getValueAt(fila, 8).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 9).toString().equals("CN")){
    sent =  sent + "AND f.EPISODIO_ESTRUC_PLANTA='" + tbl_muestra.getValueAt(fila, 9).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 10).toString().equals("CN")){
    sent =  sent + "AND f.CUADRO='" + tbl_muestra.getValueAt(fila, 10).toString() + "' ";
}
    if(!tbl_muestra.getValueAt(fila, 11).toString().equals("CN")){
    sent =  sent + "AND f.MICROSECTOR='" + tbl_muestra.getValueAt(fila, 11).toString() + "' ";
}
    
    
    sent= sent+")";
    return sent;
}
private int verificarcbx(JComboBox cbx){
    int aux =0;
    
    if(cbx.getSelectedIndex()==0){
        aux=1;
    }

    return aux;
}
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Procedencia_Muestras.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Procedencia_Muestras.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Procedencia_Muestras.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Procedencia_Muestras.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Procedencia_Muestras().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregar_SITIO;
    private javax.swing.JButton agregar_capa;
    private javax.swing.JButton agregar_cuadro;
    private javax.swing.JButton agregar_episodio;
    private javax.swing.JButton agregar_estructura_arq;
    private javax.swing.JButton agregar_estructura_pl;
    private javax.swing.JButton agregar_localidad;
    private javax.swing.JButton agregar_microsector;
    private javax.swing.JButton agregar_piso_subcapa;
    private javax.swing.JButton agregar_siglasitio;
    private javax.swing.JButton agregar_zona;
    private javax.swing.JComboBox<String> capa;
    private javax.swing.JComboBox<String> cuadro;
    private javax.swing.JComboBox<String> episodio_estruc_pl;
    private javax.swing.JComboBox<String> estructura_arq;
    private javax.swing.JComboBox<String> estructura_pl;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    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.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JComboBox<String> localidad;
    private javax.swing.JComboBox<String> microsector;
    private javax.swing.JComboBox<String> piso_subcapa;
    private javax.swing.JComboBox<String> siglasitio;
    private javax.swing.JComboBox<String> sitio;
    private javax.swing.JTable tbl_muestra;
    private javax.swing.JComboBox<String> tipo_estruc_pl;
    private javax.swing.JComboBox<String> zona_ambiental;
    // End of variables declaration//GEN-END:variables
}
