/*
 * 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 java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import arql2020.ARQL2020;
import static arql2020.ARQL2020.WHERE;
import static arql2020.ARQL2020.etiqueta_muestra;
import arql2020.Info_familias;
import clases.InteraccionesBD;
import clases.conexion;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author chuen
 */
public class J_Relacion_diseños_tamaños extends javax.swing.JInternalFrame {

    /**
     * Creates new form H_conjuntos_forma_base
     */
    public J_Relacion_diseños_tamaños() {
        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();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        cbx_mp = new javax.swing.JComboBox<>();
        btn_calcular = new javax.swing.JButton();
        jLabel18 = new javax.swing.JLabel();
        txt_muestra = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txt_mp_selec = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        txt_sentencia = new javax.swing.JTextField();
        btn_info = new javax.swing.JButton();
        btn_arbol = new javax.swing.JButton();
        btn_copiar = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        cbx_familia = new javax.swing.JComboBox<>();
        jLabel20 = new javax.swing.JLabel();
        txt_familia_selec = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jButton12 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        btn_copiar1 = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Relaciones diseños/tamaños");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Relación diseños/tamaños");

        jTable2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Grupos tipológicos", "Tamaño 1", "Tamaño 2", "Tamaño 3", "Tamaño 4", "Total"
            }
        ));
        jTable2.setRowHeight(25);
        jScrollPane2.setViewportView(jTable2);

        jTable3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Grupos tipológicos", "Espesor (fino)", "Espesor (medio)", "Espesor (grueso)", "Total"
            }
        ));
        jTable3.setRowHeight(25);
        jScrollPane3.setViewportView(jTable3);

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

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

        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);
            }
        });

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

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

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

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

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

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

        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);
            }
        });

        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_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);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("Tamaños (sensu Aschero) (de ficha general)");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel12.setText("Módulos ancho/espesor (de ficha general)");

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

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

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

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

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

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

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

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setText("Nota: en el caso de puntas de proyectil y núcleos, se detallarán sus subgrupos tipológicos.");

        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);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 1150, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel15))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel12)
                                    .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))
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel9)
                                        .addComponent(jLabel14))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(cbx_mp, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(cbx_familia, javax.swing.GroupLayout.PREFERRED_SIZE, 757, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, 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(jSeparator1))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(177, 177, 177)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txt_familia_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 534, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .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.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton12)))
                .addContainerGap(715, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jButton12)
                .addGap(28, 28, 28)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(17, 17, 17)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(cbx_mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(cbx_familia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton11))
                .addGap(29, 29, 29)
                .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))
                    .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))
                    .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)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .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))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txt_familia_selec, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addGap(41, 41, 41)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel15)
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(109, 109, 109)
                        .addComponent(jLabel12))
                    .addComponent(btn_copiar1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(94, 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)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1174, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 980, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

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

    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)||(cbx_familia.getSelectedIndex()==0)){
                JOptionPane.showMessageDialog(null, "Seleccione previamente una materia prima y una familia");
            }else if((cbx_mp.getItemCount()>1)&&(cbx_familia.getItemCount()>1)){
                txt_muestra.setText(etiqueta_muestra);
                txt_sentencia.setText(WHERE);
                txt_mp_selec.setText(cbx_mp.getSelectedItem().toString());
                txt_familia_selec.setText(cbx_familia.getSelectedItem().toString());
//
                if(cbx_familia.getSelectedItem().toString().equals("E")){
              contaratributo_familia("punta");
              contaraespesor_familia("punta");
                }else{
                if(cbx_familia.getSelectedItem().toString().equals("G")){
              contaratributo_familia("nucleo");
              contaraespesor_familia("nucleo");
                    
                }
                else{
                    contaratributo_familia("otro");
                    contaraespesor_familia("otro");
                }
                }
                btn_copiar.setEnabled(true);
                btn_copiar1.setEnabled(true);
            }else{
                JOptionPane.showMessageDialog(null, "Seleccione previamente una materia prima y una familia");
            }
        }
    }//GEN-LAST:event_btn_calcularActionPerformed

    private void contaratributo_familia(String tabla){
        CalculosBD calculos = new CalculosBD();
     JTable tbl_aux2 = new javax.swing.JTable();

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

            },
            new String [] {
                "1", "2"
            }
        ));  
    
    
  
   calculos.LIMPIARTABLA(jTable2);
   calculos.LIMPIARTABLA(tbl_aux2);
   DefaultTableModel dm = (DefaultTableModel) tbl_aux2.getModel();

calculos.LIMPIARTABLA(tbl_aux2);
 ResultSet rs = null; 
 

     String consultaSEGMENTAL= "SELECT s.GRUPO, f.TAMAÑO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"SEGMENTAL_ESTANDAR2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') "
             + "AND (s.FAMILIA='"+txt_familia_selec.getText()+"')";
     
     
     String consultaPUNTAS= "SELECT s.SUBGRUPO, f.TAMAÑO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"PUNTAS_DE_PROYECTIL2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+ txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') ";


     
     String consultaNUCLEOS= "SELECT DISTINCT(f.ID_FORMATIZADOS), s.SUBGRUPO, f.TAMAÑO from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"NUCLEOS s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') ";

     String consultaselec = "";
     String atributo_a_obtener = "";


if(tabla.equals("punta")){
    consultaselec = consultaPUNTAS;
    atributo_a_obtener="SUBGRUPO";
   
}
if(tabla.equals("nucleo")){
    consultaselec = consultaNUCLEOS;
    atributo_a_obtener="SUBGRUPO";
    
}
if(tabla.equals("otro")){
    consultaselec = consultaSEGMENTAL;
    atributo_a_obtener="GRUPO";
    
}



String []fila = new String[2];

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

            while(rs.next()){
    
                fila[0] = rs.getString(atributo_a_obtener);
                fila[1] = "TAMAÑO: "+ rs.getString("TAMAÑO");

//                
                dm.addRow(fila);
  
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
   
        calculos.TABLA_FRECUENCIAS_DOS_VALORES("GRUPOS O SUBGRUPOS", tbl_aux2, jTable2);

       
        
    }
    private void contaraespesor_familia(String tabla){
        CalculosBD calculos = new CalculosBD();
     JTable tbl_aux2 = new javax.swing.JTable();

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

            },
            new String [] {
                "1", "2"
            }
        ));  
    
    
  
   calculos.LIMPIARTABLA(jTable3);
   calculos.LIMPIARTABLA(tbl_aux2);
   DefaultTableModel dm = (DefaultTableModel) tbl_aux2.getModel();

calculos.LIMPIARTABLA(tbl_aux2);
 ResultSet rs = null; 
 

     String consultaSEGMENTAL= "SELECT s.GRUPO, f.MODULO_ANCHO_ESPESOR from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"SEGMENTAL_ESTANDAR2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') "
             + "AND (s.FAMILIA='"+txt_familia_selec.getText()+"')";
     
     
     String consultaPUNTAS= "SELECT s.SUBGRUPO, f.MODULO_ANCHO_ESPESOR from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"PUNTAS_DE_PROYECTIL2 s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+ txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') ";


     
     String consultaNUCLEOS= "SELECT DISTINCT(f.ID_FORMATIZADOS), s.SUBGRUPO, f.MODULO_ANCHO_ESPESOR from FORMATIZADOS f \n" +
"INNER JOIN\n" +
"NUCLEOS s\n" +
"ON f.ID_FORMATIZADOS = s.ID_FORMATIZADOS "+txt_sentencia.getText()+ 
             " AND (f.MP='"+txt_mp_selec.getText()+"') ";

     String consultaselec = "";
     String atributo_a_obtener = "";


if(tabla.equals("punta")){
    consultaselec = consultaPUNTAS;
    atributo_a_obtener="SUBGRUPO";
   
}
if(tabla.equals("nucleo")){
    consultaselec = consultaNUCLEOS;
    atributo_a_obtener="SUBGRUPO";
  
}
if(tabla.equals("otro")){
    consultaselec = consultaSEGMENTAL;
    atributo_a_obtener="GRUPO";
    
}



String []fila = new String[2];

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

            while(rs.next()){
    
                fila[0] = rs.getString(atributo_a_obtener);
                fila[1] = "ANCHO/ESP: "+ rs.getString("MODULO_ANCHO_ESPESOR");

//                
                dm.addRow(fila);
  
                
            }       
        
        c.closeconnection();
        
        
        } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
   
        calculos.TABLA_FRECUENCIAS_DOS_VALORES("GRUPOS O SUBGRUPOS", tbl_aux2, jTable3);

       
        
    }
    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_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_copiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_copiarActionPerformed
        Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable2, txt_muestra.getText(), WHERE,
                "Para la familia seleccionada ("+txt_familia_selec.getText()+"): grupos tipológicos según tamaño", "Materia prima: "
                                +txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiarActionPerformed

    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 jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
  Info_familias fam = new Info_familias();
  fam.setVisible(true);
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
    CalculosBD c = new CalculosBD();
    c.cargarFAMILIASdistinct(cbx_familia, cbx_mp, WHERE);    
    }//GEN-LAST:event_jButton11ActionPerformed

    private void btn_copiar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_copiar1ActionPerformed
         Copiartabla copy = new Copiartabla();
        copy.copiartabla(jTable3, txt_muestra.getText(), WHERE,
                "Para la familia seleccionada ("+txt_familia_selec.getText()+"): grupos tipológicos según módulos ancho/espesor", "Materia prima: "
                                +txt_mp_selec.getText());
    }//GEN-LAST:event_btn_copiar1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    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_info;
    private javax.swing.JComboBox<String> cbx_familia;
    private javax.swing.JComboBox<String> cbx_mp;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextField txt_familia_selec;
    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
}
