/*
 * 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 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 arql2020.ARQL2020;
import static arql2020.ARQL2020.WHERE;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author chuen
 */
public class H_Grupos_tipologicosMP extends javax.swing.JInternalFrame {

 CalculosBD calculos = new CalculosBD();
        
 
    public H_Grupos_tipologicosMP() {
        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();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbx_mp = new javax.swing.JComboBox<>();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        cbx_grupo = new javax.swing.JComboBox<>();
        jLabel6 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        cbx_grupos2 = new javax.swing.JComboBox<>();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable4 = new javax.swing.JTable();
        jButton7 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        txt_sentencia = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        txt_muestra = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Grupos y subgrupos por variedad de MP");

        jTable1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Grupos y subgrupos"
            }
        ));
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTable1.setRowHeight(25);
        jTable1.setShowGrid(true);
        jScrollPane2.setViewportView(jTable1);

        jPanel2.setBackground(new java.awt.Color(153, 255, 204));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Grupos y subgrupos tipológicos según MP", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        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

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

            },
            new String [] {
                "Grupos tipológicos", "Cantidad", "Total"
            }
        ));
        jTable2.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTable2.setRowHeight(25);
        jTable2.setShowGrid(true);
        jScrollPane3.setViewportView(jTable2);

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

            },
            new String [] {
                "Subgrupos tipológicos", "Cantidad", "% (sobre este grupo tipológico)"
            }
        ));
        jTable3.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable3.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTable3.setRowHeight(25);
        jTable3.setShowGrid(true);
        jScrollPane4.setViewportView(jTable3);

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

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Subgrupos de");

        jButton5.setBackground(new java.awt.Color(204, 255, 0));
        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        jButton5.setEnabled(false);
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setBackground(new java.awt.Color(204, 255, 0));
        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        jButton6.setEnabled(false);
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

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

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

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, 795, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane4)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(cbx_grupo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(106, 106, 106)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.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(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(cbx_grupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addGap(18, 18, Short.MAX_VALUE)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
        );

        jPanel3.setBackground(new java.awt.Color(255, 204, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Variedades de MP según grupos tipológicos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Grupos tipológicos");

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

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

            },
            new String [] {
                "MP", "Cantidad", "% (sobre este grupo tipológico)"
            }
        ));
        jTable4.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable4.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTable4.setRowHeight(25);
        jTable4.setShowGrid(true);
        jScrollPane5.setViewportView(jTable4);

        jButton7.setBackground(new java.awt.Color(204, 255, 0));
        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        jButton7.setEnabled(false);
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

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

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(cbx_grupos2, javax.swing.GroupLayout.PREFERRED_SIZE, 757, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(cbx_grupos2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(47, 47, 47)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE)
                .addContainerGap())
        );

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

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

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

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/arbol.png"))); // NOI18N
        jButton2.setToolTipText("Abrir árbol de piezas");
        jButton2.setEnabled(false);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

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

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

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

        jButton1.setBackground(new java.awt.Color(204, 255, 0));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/lentes.png"))); // NOI18N
        jButton1.setToolTipText("Realizar análisis");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(27, 27, 27))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txt_muestra, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(txt_sentencia, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(42, 42, 42)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1169, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1723, Short.MAX_VALUE)
        );

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

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        info_frame info = new info_frame();
        info.setVisible(true);
        info.info_mp.setText("Todas las materias primas presentes en la muestra.");
        info.info_analisis.setText("Grupos y subgrupos tipológicos según MP, para la muestra seleccionada");
        info.info_procedencia.setText("ETIQUETA---->"+txt_muestra.getText()+"\nSENTENCIA---->"+txt_sentencia.getText());
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Arbol ar = new Arbol();
ar.setVisible(true);

        for (int i = 0; i < jTable1.getRowCount()-1; i++) {
        CalculosBD calc = new CalculosBD();
        String mp = jTable1.getValueAt(i, 0).toString();
        calc.cargarArbolCriterioFORMATIZADOSf(ar.arbol_analisis_FORM, "FORMATIZADOS f", mp, "f.ID_FORMATIZADOS", "ID_FORMATIZADOS", "f.PIEZA", "PIEZA", "Gen", WHERE+" AND ( f.MP= '"+mp+"')", txt_muestra.getText());
     
        }
ar.txt_mp.setText("Todas las materias primas presentes en la muestra");

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable1, txt_muestra.getText(), WHERE, "Grupos tipológicos presentes en la muestra, según materias primas", "");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(WHERE.equals("")){
            JOptionPane.showMessageDialog(null, "Debe seleccionar una muestra previamente");
        }else{

            txt_muestra.setText(ARQL2020.etiqueta_muestra);
            txt_sentencia.setText(ARQL2020.WHERE);


cargarMPgrupos();
            jButton5.setEnabled(true);
            jButton6.setEnabled(true);
            jButton7.setEnabled(true);
            jButton2.setEnabled(true);
            jButton10.setEnabled(true);
            jButton9.setEnabled(true);
            jButton8.setEnabled(true);
            jButton3.setEnabled(true);

            }

//
//            CalculosBD calculos = new CalculosBD();
//            calculos.INTEGRAR_RESULTADOS_TABLA(jTable1);

//            cargartbl2();
//        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
         contarGRUPOS_MP("GRUPO", txt_sentencia.getText(), cbx_mp.getSelectedItem().toString(), jTable2);
    
    }//GEN-LAST:event_jButton5ActionPerformed

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

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
     String opcion = cbx_grupo.getSelectedItem().toString();
    if(opcion.equals("PP-Punta de proyectil")){
      contarSUBGRUPOS_MP("SUBGRUPO", txt_sentencia.getText()+ " AND (s.GRUPO='"+cbx_grupo.getSelectedItem().toString()+"') ", cbx_mp.getSelectedItem().toString(), jTable3, " PUNTAS_DE_PROYECTIL2 ");  
    }else if (opcion.equals("Nu-Núcleo")){
          contarSUBGRUPOS_MP("SUBGRUPO", txt_sentencia.getText()+ " AND (s.GRUPO='"+cbx_grupo.getSelectedItem().toString()+"') ", cbx_mp.getSelectedItem().toString(), jTable3, " NUCLEOS ");  

    }else{
          contarSUBGRUPOS_MP("SUBGRUPO", txt_sentencia.getText()+ " AND (s.GRUPO='"+cbx_grupo.getSelectedItem().toString()+"') ", cbx_mp.getSelectedItem().toString(), jTable3, " SEGMENTAL_ESTANDAR2 ");  
    }
        
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
           String opcion = cbx_grupos2.getSelectedItem().toString();
    if(opcion.equals("PP-Punta de proyectil")){
contarMP_EN_GRUPOS(txt_sentencia.getText(), jTable4, " PUNTAS_DE_PROYECTIL2");
    }else if (opcion.equals("Nu-Núcleo")){
contarMP_EN_GRUPOS(txt_sentencia.getText(), jTable4, " NUCLEOS ");
    }else{
contarMP_EN_GRUPOS(txt_sentencia.getText(), jTable4, " SEGMENTAL_ESTANDAR2 ");    
    }
        
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
       Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable2, txt_muestra.getText(), WHERE, "Grupos tipológicos presentes en la MP: "+ cbx_mp.getSelectedItem().toString(), "");

    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
           Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable3, txt_muestra.getText(), WHERE, "Subgrupos tipológicos de: "+ cbx_grupo.getSelectedItem().toString(), "");

    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
            Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable4, txt_muestra.getText(), WHERE, "Materias primas para el grupo tipológico: "+ cbx_grupos2.getSelectedItem().toString(), "");

    }//GEN-LAST:event_jButton10ActionPerformed
private void cargarMPgrupos(){

 

JTable tbl_aux2 = new javax.swing.JTable();

tbl_aux2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "1", "2"
            }
        ));  
    
    
   cbx_mp.removeAllItems();
    cbx_grupos2.removeAllItems();
 cbx_grupos2.addItem("Seleccione un grupo tipológico");
    calculos.cargarmpformdistinct(cbx_mp, WHERE);
   
   calculos.LIMPIARTABLA(jTable1);
   calculos.LIMPIARTABLA(tbl_aux2);
   DefaultTableModel dm = (DefaultTableModel) tbl_aux2.getModel();

calculos.LIMPIARTABLA(tbl_aux2);
 ResultSet rs = null; 
     String consulta= "SELECT f.MP, s.GRUPO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"SEGMENTAL_ESTANDAR2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText();

String []fila = new String[2];

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

            while(rs.next()){
                fila[0] = rs.getString("MP");
                fila[1] = rs.getString("GRUPO");
                dm.addRow(fila);
        
                
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
         
         /////////nucleos
 consulta= "SELECT f.MP, s.GRUPO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"NUCLEOS s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText();



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

            while(rs.next()){
                fila[0] = rs.getString("MP");
                fila[1] = rs.getString("GRUPO");
                dm.addRow(fila);
              }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
         /////////nucleos
 consulta= "SELECT f.MP, s.GRUPO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"PUNTAS_DE_PROYECTIL2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText();



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

            while(rs.next()){
                fila[0] = rs.getString("MP");
                fila[1] = rs.getString("GRUPO");
                dm.addRow(fila);
              }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
   
        calculos.TABLA_FRECUENCIAS_DOS_VALORES("MP", tbl_aux2, jTable1);
        for (int i = 1; i < jTable1.getColumnCount()-1; i++) {
            cbx_grupos2.addItem(jTable1.getColumnName(i));
        
    }
 
}


    private void contarGRUPOS_MP (String atributo, String where, String MP, JTable tbl){
 calculos.LIMPIARTABLA(tbl);
 cbx_grupo.removeAllItems();
 cbx_grupo.addItem("Seleccione un grupo tipológico");

  DefaultTableModel dm = (DefaultTableModel) tbl.getModel();
    int cant = 0;
     ResultSet rs = null; 
     String consulta= "SELECT s."+atributo+", COUNT(s."+atributo+")AS CANTIDAD from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"SEGMENTAL_ESTANDAR2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+where + " AND (f.MP='"+MP+"') GROUP BY (s."+atributo+")";

Object []fila = new Object[3];
fila[2]=0;
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                fila[0] = rs.getString(atributo);
                fila[1] = rs.getInt("CANTIDAD");
                dm.addRow(fila);
                cbx_grupo.addItem(fila[0].toString());
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
         ///nucleos
consulta= "SELECT s."+atributo+", COUNT(s."+atributo+")AS CANTIDAD from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"NUCLEOS s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+where + " AND (f.MP='"+MP+"') GROUP BY (s."+atributo+")";


fila[2]=0;
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                fila[0] = rs.getString(atributo);
                fila[1] = rs.getInt("CANTIDAD");
                dm.addRow(fila);
                cbx_grupo.addItem(fila[0].toString());
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
         ///PUNTAS DE PORY
consulta= "SELECT s."+atributo+", COUNT(s."+atributo+")AS CANTIDAD from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"PUNTAS_DE_PROYECTIL2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+where + " AND (f.MP='"+MP+"') GROUP BY (s."+atributo+")";


fila[2]=0;
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                fila[0] = rs.getString(atributo);
                fila[1] = rs.getInt("CANTIDAD");
                dm.addRow(fila);
                cbx_grupo.addItem(fila[0].toString());
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    calculos.INTEGRAR_RESULTADOS_TABLA(tbl);
    
}
    private void contarMP_EN_GRUPOS (String where,  JTable tbl, String tabla){
 calculos.LIMPIARTABLA(jTable4);
 cbx_grupo.removeAllItems();
 cbx_grupo.addItem("Seleccione un grupo tipológico");

  DefaultTableModel dm = (DefaultTableModel) jTable4.getModel();
    int cant = 0;
     ResultSet rs = null; 
     String consulta= "SELECT f.MP, COUNT(f.MP)AS CANTIDAD from FORMATIZADOS f \n" +
"INNER JOIN \n" +
tabla + "  s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+where + " AND (s.GRUPO='"+cbx_grupos2.getSelectedItem().toString()+"') GROUP BY (f.MP)";

Object []fila = new Object[3];
fila[2]=0;
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                fila[0] = rs.getString("MP");
                fila[1] = rs.getInt("CANTIDAD");
                dm.addRow(fila);
                cbx_grupo.addItem(fila[0].toString());
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
     
    calculos.INTEGRAR_RESULTADOS_TABLA(tbl);
    
}
    private void contarSUBGRUPOS_MP (String atributo, String where, String MP, JTable tbl, String tabla){
 calculos.LIMPIARTABLA(tbl);

  DefaultTableModel dm = (DefaultTableModel) tbl.getModel();
    int cant = 0;
     ResultSet rs = null; 
     String consulta= "SELECT s."+atributo+", COUNT(s."+atributo+")AS CANTIDAD from FORMATIZADOS f \n" +
"INNER JOIN\n" +
tabla +" s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+where + " AND (f.MP='"+MP+"') GROUP BY (s."+atributo+")";

Object []fila = new Object[3];
fila[2]=0;
         try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta(consulta);

            while(rs.next()){
                fila[0] = rs.getString(atributo);
                fila[1] = rs.getInt("CANTIDAD");
                dm.addRow(fila);

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


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox<String> cbx_grupo;
    private javax.swing.JComboBox<String> cbx_grupos2;
    private javax.swing.JComboBox<String> cbx_mp;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    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.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTable jTable4;
    private javax.swing.JTextField txt_muestra;
    private javax.swing.JTextField txt_sentencia;
    // End of variables declaration//GEN-END:variables
}
