/*
 * 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 static arql2020.ARQL2020.WHERE;
import static arql2020.ARQL2020.etiqueta_muestra;
import arql2020.Info_familias;
import clases.InteraccionesBD;
import clases.conexion;
import java.beans.PropertyVetoException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author chuen
 */
public class I_conjuntos_forma_base extends javax.swing.JInternalFrame {
CalculosBD calculos = new CalculosBD();


            String lascas = " AND (f.FORMA_BASE IN( 'LsP-Lasca primaria o cortical', " +
            "'LsS-Lasca secundaria o de descortezamiento'," +
            "'LsDN-Lasca con dorso natural(gajo)' ," +
            "'LsAng-Lasca angular' ," +
            "'LsAr-Lasca de arista' ," +
            "'LsPl-Lasca plana' ," +
            "'LsCta-Lasca en cresta' ," +
            "'LsFNu-Lasca de flanco de núcleo' ," +
            "'LsTNu-Lasca de tableta de núcleo' ," +
            "'LsST-Lasca de semitableta de núcleo' ," +
            "'LsBp.Lasca bipolar (doble bulbo de percusión)' ," +
            "'LsND-Lasca no diferenciada' ," +
            "'LsRc-Lasca reciclada'   ))   ";


    String hojas = " AND (f.FORMA_BASE='HoArS-Hoja de arista simple' OR "
                            + "f.FORMA_BASE='HoArM-Hoja de arista doble o múltiple' OR "
                            + "f.FORMA_BASE='HoND-Hoja no diferenciada' OR "
                            + "f.FORMA_BASE='HoRc-Hoja reciclada'  "

                             + ") AND (f.FORMA_BASE not like 'CN' ) ";
    
    
    String nodulos = "  AND (f.FORMA_BASE='NdND-Nódulo no diferenciado' OR "
                            + "f.FORMA_BASE='NdFac-Nódulo a facetas naturales' OR "
                            + "f.FORMA_BASE='NdTR-Nódulo tabular rodado' OR "
                            + "f.FORMA_BASE='NdTB-Nódulo con talla bipolar' OR "
                            + "f.FORMA_BASE='LsNd-Lasc.nodular'  "

                             + ") AND (f.FORMA_BASE not like 'CN' ) ";
    

    public I_conjuntos_forma_base() {
        initComponents();
        
            try {
            this.setMaximum(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(B_Composicion_puntasfilossup.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * 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();
        jLabel3 = new javax.swing.JLabel();
        A = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        B = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        C = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        tbl2_grupos_lasca_hoja_nod = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        D = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        E = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        F = new javax.swing.JButton();
        jLabel12 = new javax.swing.JLabel();
        G = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        H = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tbl1_resumen = new javax.swing.JTable();
        jLabel16 = new javax.swing.JLabel();
        txt_familia_Selec = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cbx_mp = new javax.swing.JComboBox<>();
        jButton1 = new javax.swing.JButton();
        btn_copiar = new javax.swing.JButton();
        btn_arbol = new javax.swing.JButton();
        btn_info = new javax.swing.JButton();
        txt_mp_selec = new javax.swing.JTextField();
        txt_sentencia = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txt_muestra = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        btn_calcular = new javax.swing.JButton();
        jLabel19 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        cbx_grupos_tipologicos_familia = new javax.swing.JComboBox<>();
        jButton3 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txt_grupo_tipologico_seleccionado = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        txt_familia_Selec1 = new javax.swing.JTextField();
        H1 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        btn_copiar1 = new javax.swing.JButton();
        btn_copiar2 = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Relaciones tecno-tipológicas por familias tipológicas y tipología de la forma-base");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Familias tipológicas y morfología de la forma-base");

        A.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        A.setText("Famila A");
        A.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel4.setText("Útiles masivos con filos irregulares, largos o cortos, para trabajos por percussion. Choppers, chopping tools o tajadores. ");

        B.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        B.setText("Familia B");
        B.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel5.setText("Útiles de filos normales o dentados, cortos o largos de variada morfología, para trabajos por presión. Raspadores, raederas,etc.");

        C.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        C.setText("Famila C");
        C.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel6.setText("Útiles  de filos intencionalmente restringidos de variada morfología, para trabajos por presión o percusión con agregado de mangos. Muescas, gubias, escoplos, etc.");

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

            },
            new String [] {
                "Morfología de la forma-base", "Cantidad", "Totales"
            }
        ));
        jTable2.setRowHeight(25);
        jScrollPane2.setViewportView(jTable2);

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

            },
            new String [] {
                "Grupos tipologicos", "FB-Lascas", "FB-Hojas", "Nódulos o ls.nod.", "Total"
            }
        ));
        tbl2_grupos_lasca_hoja_nod.setRowHeight(25);
        jScrollPane4.setViewportView(tbl2_grupos_lasca_hoja_nod);

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Grupos tipológicos presentes de la familia seleccionada según lascas y hojas en formas base");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Grupos tipológicos presentes en la familia seleccionada según variedades de formas-base");

        D.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        D.setText("Familia D");
        D.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel10.setText("Útiles usados como puntas de mano o cabezales de taladros, para trabajos por presión con o sin mangos e intermediarios. Puntas entre muescas, perforadores, artefactos de limbo embotado, etc.");

        E.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        E.setText("Familia E");
        E.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel11.setText("Útiles para punción a distancia, enastilados  y  con elementos intermediarios de impulsión. Puntas de proyectil");

        F.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        F.setText("Familia F");
        F.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel12.setText("Útiles de uso manual con mangos para trabajos por percusión en tierra. Palas, picos.");

        G.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        G.setText("Familia G");
        G.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GActionPerformed(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel13.setText("Artefactos pasivos o activos con superficies para percusión para talla de extracción. Núcleos, nucleiformes y percutores.");

        H.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        H.setText("Familia H");
        H.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel14.setText("Artefactos no diferenciados por fractura (s). ");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setText("Resúmen de todas las familias tipológicas, según lascas y hojas en formas base.");

        tbl1_resumen.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tbl1_resumen.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"A", null, null, null, null},
                {"B", null, null, null, null},
                {"C", null, null, null, null},
                {"D", null, null, null, null},
                {"E", null, null, null, null},
                {"F", null, null, null, null},
                {"G", null, null, null, null},
                {"H", null, null, null, null}
            },
            new String [] {
                "Familia tipológica", "FB-Lascas", "FB-Hojas", "Nódulos o ls.nod.", "Totales"
            }
        ));
        tbl1_resumen.setRowHeight(25);
        jScrollPane5.setViewportView(tbl1_resumen);

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel16.setText("FAMILIA SELECCIONADA:");

        txt_familia_Selec.setEditable(false);
        txt_familia_Selec.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txt_familia_Selec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_familia_SelecActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Materia prima ");

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

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setText("MP PRESENTES EN LA MUESTRA");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        btn_copiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/copiar.png"))); // NOI18N
        btn_copiar.setToolTipText("Copiar valores en el portapapeles");
        btn_copiar.setEnabled(false);
        btn_copiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_copiarActionPerformed(evt);
            }
        });

        btn_arbol.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arbol.png"))); // NOI18N
        btn_arbol.setToolTipText("Arbol: CLASES ARTEFACTUALES PRESENTES EN LA MP SELECCIONADA");
        btn_arbol.setEnabled(false);
        btn_arbol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_arbolActionPerformed(evt);
            }
        });

        btn_info.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/info.png"))); // NOI18N
        btn_info.setToolTipText("Información sobre el análisis");
        btn_info.setEnabled(false);
        btn_info.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_infoActionPerformed(evt);
            }
        });

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

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

        jLabel17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel17.setText("Sentencia:");

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

        jLabel18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel18.setText("Cálculo realizado sobre muestra:");

        btn_calcular.setBackground(new java.awt.Color(204, 255, 0));
        btn_calcular.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        btn_calcular.setToolTipText("Realizar análisis");
        btn_calcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_calcularActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel19.setText("Materia prima:");

        jTextArea1.setEditable(false);
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setText("*NOTA\n\nSE CLASIFICA SEGÚN:\n\n----LASCAS----                                \nLsP-Lasca primaria o cortical\nLsS-Lasca secundaria o de descortezamiento\nLsDN-Lasca con dorso natural(gajo)\nLsAng-Lasca angular\nLsAr-Lasca de arista\nLsPl-Lasca plana\nLsCta-Lasca en cresta\nLsFNu-Lasca de flanco de núcleo\nLsTNu-Lasca de tableta de núcleo\nLsST-Lasca de semitableta de núcleo\nLsBp.Lasca bipolar (doble bulbo de percusión)\nLsND-Lasca no diferenciada\nLsRc-Lasca reciclada\n\n----HOJAS----\nHoArS-Hoja de arista simple\nHoArM-Hoja de arista doble o múltiple\nHoND-Hoja no diferenciada\nHoRc-Hoja reciclada\n\n----NODULOS O LS.NOD----\nNdND-Nódulo no diferenciado\nNdFac-Nódulo a facetas naturales\nNdTR-Nódulo tabular rodado\nLsNd-Lasc.nodular\nNdTB-Nódulo con talla bipolar");
        jScrollPane3.setViewportView(jTextArea1);

        jButton2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton2.setText("Información sobre familias");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        cbx_grupos_tipologicos_familia.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        cbx_grupos_tipologicos_familia.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Grupos tipológicos presentes en la familia seleccionada" }));
        cbx_grupos_tipologicos_familia.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbx_grupos_tipologicos_familiaItemStateChanged(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton3.setText("Cargar morfologías de las formas-base");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Morfologías de las formas base del grupo tipológico:");

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

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel21.setText("FAMILIA SELECCIONADA:");

        txt_familia_Selec1.setEditable(false);
        txt_familia_Selec1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        txt_familia_Selec1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_familia_Selec1ActionPerformed(evt);
            }
        });

        H1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        H1.setText("Familia X");
        H1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                H1ActionPerformed(evt);
            }
        });

        jLabel22.setFont(new java.awt.Font("Tahoma", 2, 14)); // NOI18N
        jLabel22.setText("Abradidores");

        btn_copiar1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/copiar.png"))); // NOI18N
        btn_copiar1.setToolTipText("Copiar valores en el portapapeles");
        btn_copiar1.setEnabled(false);
        btn_copiar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_copiar1ActionPerformed(evt);
            }
        });

        btn_copiar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/copiar.png"))); // NOI18N
        btn_copiar2.setToolTipText("Copiar valores en el portapapeles");
        btn_copiar2.setEnabled(false);
        btn_copiar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_copiar2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane5)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(73, 73, 73))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, 617, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButton1))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel18)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(txt_muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(27, 27, 27)
                                        .addComponent(jLabel17)
                                        .addGap(18, 18, 18)
                                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(14, 14, 14)
                                        .addComponent(btn_info, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(btn_arbol, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btn_copiar, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(C, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(A, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(B, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(9, 9, 9)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addGap(5, 5, 5)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 452, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(D)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(E)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(F)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(G)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(H)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel15)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addGap(18, 18, 18)
                                .addComponent(txt_familia_Selec, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButton2)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(182, 182, 182)
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txt_mp_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 534, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(btn_copiar2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btn_copiar1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(18, 18, 18)
                                        .addComponent(txt_grupo_tipologico_seleccionado))
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(cbx_grupos_tipologicos_familia, javax.swing.GroupLayout.PREFERRED_SIZE, 701, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jButton3)))))
                        .addContainerGap(17, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel21)
                                .addGap(18, 18, 18)
                                .addComponent(txt_familia_Selec1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(H1)
                                .addGap(9, 9, 9)
                                .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(46, 46, 46)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btn_calcular, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel18)
                        .addComponent(txt_muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btn_arbol, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_copiar, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(btn_info, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_mp_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addGap(70, 70, 70)
                .addComponent(jButton2)
                .addGap(27, 27, 27)
                .addComponent(jLabel15)
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addGap(72, 72, 72)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(A)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(B)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(C)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(D)
                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(E)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(F)
                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(G)
                    .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(H)
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(H1)
                    .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(txt_familia_Selec, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7)
                    .addComponent(btn_copiar1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jLabel8)
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel21)
                            .addComponent(txt_familia_Selec1, 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_grupos_tipologicos_familia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton3))
                        .addGap(13, 13, 13)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txt_grupo_tipologico_seleccionado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
                        .addGap(41, 41, 41))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_copiar2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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, 1241, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1867, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private void armartabla1(){
        
        DefaultTableModel dtm1 = (DefaultTableModel) tbl1_resumen.getModel();
        
        if (dtm1.getRowCount()==9){
            dtm1.removeRow(8);
        }
        
        Object valor = 0;
        valor= contarporgrupo(" AND (n.FAMILIA='A') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 0, 1);
        valor= contarporgrupo(" AND (n.FAMILIA='B') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 1, 1);
        valor= contarporgrupo(" AND (n.FAMILIA='C') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 2, 1);
        valor= contarporgrupo(" AND (n.FAMILIA='D') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 3, 1);
        valor= contarporgrupo("  ", lascas, " PUNTAS_DE_PROYECTIL2 ", "*");
        dtm1.setValueAt(valor, 4, 1);
        valor= contarporgrupo(" AND (n.FAMILIA='F') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 5, 1);
        valor= contarporgrupo("", lascas, " NUCLEOS ", "DISTINCT f.ID_FORMATIZADOS");
        dtm1.setValueAt(valor, 6, 1);
        valor= contarporgrupo(" AND (n.FAMILIA='H') ", lascas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 7, 1);

        valor= contarporgrupo(" AND (n.FAMILIA='A') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 0, 2);
        valor= contarporgrupo(" AND (n.FAMILIA='B') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 1, 2);
        valor= contarporgrupo(" AND (n.FAMILIA='C') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 2, 2);
        valor= contarporgrupo(" AND (n.FAMILIA='D') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 3, 2);
        valor= contarporgrupo("", hojas, " PUNTAS_DE_PROYECTIL2 ", "*");
        dtm1.setValueAt(valor, 4, 2);
        valor= contarporgrupo(" AND (n.FAMILIA='F') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 5, 2);
        valor= contarporgrupo(" ", hojas, " NUCLEOS ", "DISTINCT f.ID_FORMATIZADOS");
        dtm1.setValueAt(valor, 6, 2);
        valor= contarporgrupo(" AND (n.FAMILIA='H') ", hojas, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 7, 2);

        valor= contarporgrupo(" AND (n.FAMILIA='A') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 0, 3);
        valor= contarporgrupo(" AND (n.FAMILIA='B') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 1, 3);
        valor= contarporgrupo(" AND (n.FAMILIA='C') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 2, 3);
        valor= contarporgrupo(" AND (n.FAMILIA='D') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 3, 3);
        valor= contarporgrupo(" ", nodulos, "PUNTAS_DE_PROYECTIL2 ", "*");
        dtm1.setValueAt(valor, 4, 3);
        valor= contarporgrupo(" AND (n.FAMILIA='F') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 5, 3);
        valor= contarporgrupo(" ", nodulos, " NUCLEOS ","DISTINCT f.ID_FORMATIZADOS");
        dtm1.setValueAt(valor, 6, 3);
        valor= contarporgrupo(" AND (n.FAMILIA='H') ", nodulos, " SEGMENTAL_ESTANDAR2 ", "*");
        dtm1.setValueAt(valor, 7, 3);
        
        dtm1.setValueAt("0", 0, 4);
        dtm1.setValueAt("0", 1, 4);
        dtm1.setValueAt("0", 2, 4);
        dtm1.setValueAt("0", 3, 4);
        dtm1.setValueAt("0", 4, 4);
        dtm1.setValueAt("0", 5, 4);
        dtm1.setValueAt("0", 6, 4);
        dtm1.setValueAt("0", 7, 4);
        
     CalculosBD calc = new CalculosBD();
            calc.sumartotalesfila(dtm1);
            calc.sumartotalescolumna(dtm1);
            calc.porcentajesfilainferior(dtm1);
        
        
    }
    
    private Object contarporgrupo(String familia, String lasca_hoja_nodulo, String tabla, String distinct){
    Object valor =0;
    ResultSet rs = null;
    ArrayList<Integer> ids = new ArrayList<>();
    String consulta = "SELECT COUNT ("+distinct+")  FROM FORMATIZADOS f \n"  +
        "INNER JOIN \n" +
tabla + "  n \n" +
"ON f.ID_FORMATIZADOS = n.ID_FORMATIZADOS " 
        +txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"') "+ familia +  lasca_hoja_nodulo;
//        System.out.println("---consulta: " + consulta);
     try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            if(rs.next()){
                valor=rs.getInt("1");
                
            }       
        
        c.closeconnection();
        
     
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
   
     return valor;
     
 }   
    
    private void CARGARFILAS_tbl2(String familia){
        cbx_grupos_tipologicos_familia.removeAllItems();
        cbx_grupos_tipologicos_familia.addItem("Grupos tipológicos presentes en la familia " + familia);
        
        DefaultTableModel dtm2 = (DefaultTableModel) tbl2_grupos_lasca_hoja_nod.getModel();
        
//         int a = tbl2_grupos_lasca_hoja_nod.getRowCount()-1;
//        for (int i = a; i >= 0; i--) {          
//        dtm2.removeRow(dtm2.getRowCount()-1);
//        }
        CalculosBD calc = new CalculosBD();
        calc.LIMPIARTABLA(tbl2_grupos_lasca_hoja_nod);
        
        ArrayList<String>grupos = new ArrayList<>();
        grupos=contargruposenfamilia(familia);
        Object[]filainicial = new Object[5];
        filainicial[0]="0";
        filainicial[1]="0";
        filainicial[2]="0";
        filainicial[3]="0";
        filainicial[4]="0";

        for (int i = 0; i < grupos.size(); i++) {
            filainicial[0]= grupos.get(i);
            dtm2.addRow(filainicial);
            cbx_grupos_tipologicos_familia.addItem(filainicial[0].toString());
        }
        String grupo_tipol = "";
        for (int i = 0; i < dtm2.getRowCount(); i++) {
//            Object object = filainicial[i];
            grupo_tipol= dtm2.getValueAt(i, 0).toString();
            if(familia.equals("G")){
                
                contarGrupo_hoja_lasca_nod("DISTINCT f.ID_FORMATIZADOS"," NUCLEOS ", i, 1, grupo_tipol, " ", lascas);
                contarGrupo_hoja_lasca_nod("DISTINCT f.ID_FORMATIZADOS"," NUCLEOS ",i, 2, grupo_tipol, " ", hojas);
                contarGrupo_hoja_lasca_nod("DISTINCT f.ID_FORMATIZADOS"," NUCLEOS ",i, 3, grupo_tipol, " ", nodulos);
        }else if(familia.equals("E")){
                
            contarGrupo_hoja_lasca_nod("*"," PUNTAS_DE_PROYECTIL2 ", i, 1, grupo_tipol, " ", lascas);
                contarGrupo_hoja_lasca_nod("*"," PUNTAS_DE_PROYECTIL2 ",i, 2, grupo_tipol, " ", hojas);
                contarGrupo_hoja_lasca_nod("*"," PUNTAS_DE_PROYECTIL2 ",i, 3, grupo_tipol, " ", nodulos);
        }else{
            
                contarGrupo_hoja_lasca_nod("*"," SEGMENTAL_ESTANDAR2 ", i, 1, grupo_tipol, "AND (n.FAMILIA='"+familia+"') ", lascas);
                contarGrupo_hoja_lasca_nod("*"," SEGMENTAL_ESTANDAR2 ",i, 2, grupo_tipol, "AND (n.FAMILIA='"+familia+"') ", hojas);
                contarGrupo_hoja_lasca_nod("*"," SEGMENTAL_ESTANDAR2 ",i, 3, grupo_tipol, "AND (n.FAMILIA='"+familia+"') ", nodulos);
        }
            }

//        }
        
        CalculosBD calculos = new CalculosBD();

calculos.sumartotalesfila(dtm2);
calculos.sumartotalescolumna(dtm2);
calculos.porcentajesfilainferior(dtm2);
        
        
    }
    private ArrayList<String> contargruposenfamilia(String familia){
 ArrayList<String>grupos = new ArrayList<>();
        if(familia.equals("G")){
    grupos.add("Nu-Núcleo");
}else if (familia.equals("E")){
    grupos.add("PP-Punta de proyectil");
    
}else{
       
    ResultSet rs = null;
    ArrayList<Integer> ids = new ArrayList<>();
    String consulta = "SELECT DISTINCT (n.GRUPO)  FROM FORMATIZADOS f \n"  +
        "INNER JOIN \n" +
"SEGMENTAL_ESTANDAR2 n \n" +
"ON f.ID_FORMATIZADOS = n.ID_FORMATIZADOS " 
        +txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"') AND (n.FAMILIA='"+familia+"') " ;
        
     try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                grupos.add(rs.getString("GRUPO"));
                
            }       
        
        c.closeconnection();
        
     
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
   
     return grupos;
     
 } 
    
    private void contarGrupo_hoja_lasca_nod (String count ,String tabla, int fila, int col, String grupo, String familia, String lasca_hoja_nodulo){
    DefaultTableModel dtm2 = (DefaultTableModel) tbl2_grupos_lasca_hoja_nod.getModel();
        Object valor =0;
    ResultSet rs = null;
    ArrayList<Integer> ids = new ArrayList<>();
    String consulta = "SELECT COUNT ("+count+")  FROM FORMATIZADOS f \n"  +
        "INNER JOIN \n" +
tabla + " n \n" +
"ON f.ID_FORMATIZADOS = n.ID_FORMATIZADOS " 
        +txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"') "+familia+" AND (n.GRUPO='"+grupo+"') " + lasca_hoja_nodulo;
        
     try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            if(rs.next()){
                valor=rs.getInt("1");
                
            }       
        
        c.closeconnection();
        
     
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
   
     dtm2.setValueAt(valor, fila, col);

     
    }
    private void AActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AActionPerformed
        CARGARFILAS_tbl2("A");
        txt_familia_Selec.setText("A");
        txt_familia_Selec1.setText("A");
    }//GEN-LAST:event_AActionPerformed

    private void BActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BActionPerformed
     CARGARFILAS_tbl2("B");
             txt_familia_Selec.setText("B");
             txt_familia_Selec1.setText("B");
    }//GEN-LAST:event_BActionPerformed

    private void CActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CActionPerformed
 CARGARFILAS_tbl2("C");
         txt_familia_Selec.setText("C");
         txt_familia_Selec1.setText("C");
    }//GEN-LAST:event_CActionPerformed

    private void DActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DActionPerformed
    CARGARFILAS_tbl2("D");
            txt_familia_Selec.setText("D");
            txt_familia_Selec1.setText("D");
    }//GEN-LAST:event_DActionPerformed

    private void EActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EActionPerformed
    CARGARFILAS_tbl2("E");
            txt_familia_Selec.setText("E");
            txt_familia_Selec1.setText("E");
    }//GEN-LAST:event_EActionPerformed

    private void FActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FActionPerformed
      CARGARFILAS_tbl2("F");
              txt_familia_Selec.setText("F");
              txt_familia_Selec1.setText("F");
    }//GEN-LAST:event_FActionPerformed

    private void GActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GActionPerformed
    CARGARFILAS_tbl2("G");
            txt_familia_Selec.setText("G");
            txt_familia_Selec1.setText("G");
    }//GEN-LAST:event_GActionPerformed

    private void HActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HActionPerformed
      CARGARFILAS_tbl2("H");
              txt_familia_Selec.setText("H");
              txt_familia_Selec1.setText("H");
    }//GEN-LAST:event_HActionPerformed

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

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        CalculosBD c = new CalculosBD();
        c.cargarmpformdistinct(cbx_mp, WHERE);
    }//GEN-LAST:event_jButton1ActionPerformed

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

        Copiartabla copy = new Copiartabla();
        copy.copiartabla(tbl1_resumen, txt_muestra.getText(), WHERE,
                "Familias tipológicas según lascas y hojas en formas base", "Materia prima: "
                                +txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiarActionPerformed

    private void btn_arbolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_arbolActionPerformed
//        Arbol ar = new Arbol();
//        ar.setVisible(true);
//
//        for (int i = 0; i < tbl2.getRowCount()-1; i++) {
//            CalculosBD calc = new CalculosBD();
//            String claseart = tbl2.getValueAt(i, 0).toString();
//            calc.cargarArbolCriterioFORMATIZADOSf(ar.arbol_analisis_FORM, "FORMATIZADOS f", claseart, "f.ID_FORMATIZADOS", "ID_FORMATIZADOS", "f.PIEZA", "PIEZA", "Gen", WHERE+" AND ( f.MP= '"+txt_mp_selec.getText()+"' AND f.CLASE_ARTEF='"+claseart+"')", txt_muestra.getText()+"/ MP:" + txt_mp_selec.getText());
//
//        }
//        ar.txt_mp.setText(txt_mp_selec.getText());
//        ar.txt_nota.setText("El árbol se conforma de acuerdo a clases artefactuales presentes en la materia prima seleccionada. En este caso, no se discrimina entre filos, puntas y superficies");
    }//GEN-LAST:event_btn_arbolActionPerformed

    private void btn_infoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_infoActionPerformed
        info_frame info = new info_frame();
        info.setVisible(true);
        info.info_procedencia.setText("MUESTRA---->" + txt_muestra.getText() +"\n SENTENCIA---->" +txt_sentencia.getText() );
        info.info_mp.setText(txt_mp_selec.getText());
        info.info_analisis.setText("CLASES ARTEFACTUALES POR MP, FILOS, PUNTAS DE PROYECTIL, PUNTAS DE MANO, SUPERFICIES Y NUCLEOS: Se contabilizan las piezas de acuerdo al 100% de fichas: segmental estandar, núcleos, puntas de proyectil, en base a la muestra y la materia prima seleccionada."
            + "\n"
            + "\n El conteo de la tabla debe entenderse como 'Cantidad de filos, puntas o superficies, realizados sobre diversas clases artefactuales'"
            + "\n - Ejemplo: si la pieza N°22 se registró como <Artefacto Formatizado> en la clase artefactual, y la misma tiene asociada una ficha segmental de Cuchillo y una de Raedera, entonces el conteo de filos en relación a Artefactos formatizados será de 2.");

    }//GEN-LAST:event_btn_infoActionPerformed

    private void btn_calcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_calcularActionPerformed
        
        if(WHERE.equals("")){
            JOptionPane.showMessageDialog(null, "Seleccione previamente una muestra");
        }else{
        if(cbx_mp.getSelectedIndex()==0){
            JOptionPane.showMessageDialog(null, "Seleccione previamente una materia prima");
        }else{
            txt_muestra.setText(etiqueta_muestra);
            txt_sentencia.setText(WHERE);
            txt_mp_selec.setText(cbx_mp.getSelectedItem().toString());

            armartabla1();
            btn_copiar2.setEnabled(true);
            btn_copiar1.setEnabled(true);
            btn_copiar.setEnabled(true);
        }
        }
    }//GEN-LAST:event_btn_calcularActionPerformed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
CalculosBD c = new CalculosBD();
c.cargarmp(cbx_mp);
    }//GEN-LAST:event_formInternalFrameOpened

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
   Info_familias info = new Info_familias();
   info.setVisible(true);
    }//GEN-LAST:event_jButton2ActionPerformed

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

    }//GEN-LAST:event_cbx_grupos_tipologicos_familiaItemStateChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
 int index = cbx_grupos_tipologicos_familia.getSelectedIndex();
 String grupo = cbx_grupos_tipologicos_familia.getSelectedItem().toString();
 if(index>0){
     JOptionPane.showMessageDialog(null, "Cálculo realizado para el grupo tipológico: \n"+grupo);
     txt_grupo_tipologico_seleccionado.setText(grupo);
 
     if(txt_familia_Selec1.getText().equals("E")){
         //puntas
         cargarFormasBase(" PUNTAS_DE_PROYECTIL2 ",  "DISTINCT f.ID_FORMATIZADOS");  
     }else if(txt_familia_Selec1.getText().equals("G")){
         //nucleos
         cargarFormasBase(" NUCLEOS ", "DISTINCT f.ID_FORMATIZADOS");  
     }else{
         //estandar
       cargarFormasBase(" SEGMENTAL_ESTANDAR2 ", "f.FORMA_BASE");  
     }
             
     
     
 }
    }//GEN-LAST:event_jButton3ActionPerformed

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

    private void H1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_H1ActionPerformed
       CARGARFILAS_tbl2("X");
              txt_familia_Selec.setText("X");
              txt_familia_Selec1.setText("X");
    }//GEN-LAST:event_H1ActionPerformed

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

        
        Copiartabla copy = new Copiartabla();
        copy.copiartabla(tbl2_grupos_lasca_hoja_nod, txt_muestra.getText(), WHERE,
                "Grupos tipológicos de la familia seleccionada ("+txt_familia_Selec.getText()+") según lascas y hojas en formas base", "Materia prima: "
                                +txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiar1ActionPerformed

    private void btn_copiar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_copiar2ActionPerformed
             Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable2, txt_muestra.getText(), WHERE,
                "Variedades de formas base en la familia: "+txt_familia_Selec1.getText()+" del grupo tipológico: "+txt_grupo_tipologico_seleccionado.getText(), "Materia prima: "
                                +txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiar2ActionPerformed
private void cargarFormasBase(String tabla, String count){
    
       
        CalculosBD calc = new CalculosBD();
        calc.LIMPIARTABLA(jTable2);

        DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
           
                
    ResultSet rs = null; 
    
Object [] fila = new Object[3];
fila[0]="0";
fila[1]="0";
fila[2]="0";

        
         String consulta = "SELECT  COUNT("+count+"), f.FORMA_BASE from FORMATIZADOS f  \n" +
                  "INNER JOIN \n" +
  tabla +" n \n" +
"ON f.ID_FORMATIZADOS = n.ID_FORMATIZADOS " 
+ txt_sentencia.getText() + " AND (f.MP='"+txt_mp_selec.getText()+"') AND (n.GRUPO='"+cbx_grupos_tipologicos_familia.getSelectedItem().toString()+ "') " +" GROUP BY f.FORMA_BASE ";       


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

            while(rs.next()){
                fila[1]=rs.getInt("1");
                fila[0]=rs.getString("FORMA_BASE");
           
                dtm.addRow(fila);
            }       
        
        c.closeconnection();
        
     
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
            
                
 calc.sumartotalesfila(dtm);
calc.sumartotalescolumna(dtm);
calc.porcentajesfilainferior(dtm);               
                
                
                
        
        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton A;
    private javax.swing.JButton B;
    private javax.swing.JButton C;
    private javax.swing.JButton D;
    private javax.swing.JButton E;
    private javax.swing.JButton F;
    private javax.swing.JButton G;
    private javax.swing.JButton H;
    private javax.swing.JButton H1;
    private javax.swing.JButton btn_arbol;
    private javax.swing.JButton btn_calcular;
    private javax.swing.JButton btn_copiar;
    private javax.swing.JButton btn_copiar1;
    private javax.swing.JButton btn_copiar2;
    private javax.swing.JButton btn_info;
    private javax.swing.JComboBox<String> cbx_grupos_tipologicos_familia;
    private javax.swing.JComboBox<String> cbx_mp;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    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 jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    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.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTable tbl1_resumen;
    private javax.swing.JTable tbl2_grupos_lasca_hoja_nod;
    private javax.swing.JTextField txt_familia_Selec;
    private javax.swing.JTextField txt_familia_Selec1;
    private javax.swing.JTextField txt_grupo_tipologico_seleccionado;
    private javax.swing.JTextField txt_mp_selec;
    private javax.swing.JTextField txt_muestra;
    private javax.swing.JTextField txt_sentencia;
    // End of variables declaration//GEN-END:variables
}
