/*
 * 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 arql2020;


import static arql2020.ARQL2020.sumadora_llevar_peso;
import clases.Cargar_MP;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import static arql2020.ARQL2020.indexMP;
import clases.Limpiar_campos;
import clases.ValidarCampos;
import clases.conexion;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;


import static arql2020.ARQL2020.capa_nivel;
import static arql2020.ARQL2020.cuadro;
import static arql2020.ARQL2020.episodio_estruct_planta;
import static arql2020.ARQL2020.estruct_arq;

import static arql2020.ARQL2020.localidad;
import static arql2020.ARQL2020.microsector;
import static arql2020.ARQL2020.nombre_estruct_planta;
import static arql2020.ARQL2020.piso_subcapa;
import static arql2020.ARQL2020.siglasitio;
import static arql2020.ARQL2020.sitio;
import static arql2020.ARQL2020.tipo_estruct_planta;
import static arql2020.ARQL2020.zona_ambiental;
import static arql2020.DT_frame.arbol_DT;

import static arql2020.DT_frame.selectednodeparaeliminar;
import clases.InteraccionesBD;
import java.sql.SQLException;
import javax.swing.JOptionPane;



public class Internal_DT_sintalon extends javax.swing.JInternalFrame {

int num =0;
    public Internal_DT_sintalon() {
        initComponents();
                try {
            this.setMaximum(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(DT_frame.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();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel2 = new javax.swing.JPanel();
        st0_codigo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        st1_lote = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        st2_mp = new javax.swing.JComboBox<>();
        jLabel2 = new javax.swing.JLabel();
        st3_n = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        st4_peso = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel47 = new javax.swing.JLabel();
        st5_corteza = new javax.swing.JComboBox<>();
        jButton2 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        INGRESAR = new javax.swing.JButton();
        limpiarcampos = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        st6_observaciones = new javax.swing.JTextArea();
        btn_eliminarregistro_Dt_sintalon = new javax.swing.JButton();

        setResizable(true);
        setTitle("Desechos de talla sin talón");
        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);
            }
        });

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

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLabel1.setText("DT sin talón");

        jPanel2.setBackground(new java.awt.Color(255, 255, 204));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Códigos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

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

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Código de DT sin talón: ");

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

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

        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.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(st1_lote)
                    .addComponent(st0_codigo))
                .addGap(31, 31, 31))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(st0_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(st1_lote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 204));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Características de la pieza o lote", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N

        st2_mp.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        st2_mp.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Seleccione" }));
        st2_mp.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                st2_mpItemStateChanged(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("N° fracturadas sin talón");

        st3_n.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        st3_n.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                st3_nKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Peso* (gramos)");

        st4_peso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        st4_peso.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                st4_pesoKeyTyped(evt);
            }
        });

        jButton1.setBackground(new java.awt.Color(255, 153, 0));
        jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jButton1.setText("Sumadora de pesos");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel47.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel47.setText("Proporción de corteza*");

        st5_corteza.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        st5_corteza.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Seleccione", "A-0%", "B-0.1-25%", "C-25.1-50%", "D-50.1-75%", "E-75.1-99%", "F-100%", "CN" }));

        jButton2.setText("+");

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

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(st2_mp, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2)
                        .addGap(100, 100, 100))
                    .addComponent(jLabel7)))
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jLabel47))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(st3_n, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(st4_peso, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jButton1))
                    .addComponent(st5_corteza, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(74, 74, 74))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButton2)
                    .addComponent(st2_mp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(st3_n, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(st4_peso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(28, 28, 28)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(st5_corteza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel47))
                .addContainerGap(26, Short.MAX_VALUE))
        );

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

        limpiarcampos.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        limpiarcampos.setText("Limpiar campos");
        limpiarcampos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiarcamposActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Observaciones (500 caracteres)");

        st6_observaciones.setColumns(20);
        st6_observaciones.setFont(new java.awt.Font("Monospaced", 0, 16)); // NOI18N
        st6_observaciones.setLineWrap(true);
        st6_observaciones.setRows(5);
        st6_observaciones.setWrapStyleWord(true);
        st6_observaciones.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                st6_observacionesKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                st6_observacionesKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(st6_observaciones);

        btn_eliminarregistro_Dt_sintalon.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btn_eliminarregistro_Dt_sintalon.setText("Eliminar registro");
        btn_eliminarregistro_Dt_sintalon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_eliminarregistro_Dt_sintalonActionPerformed(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()
                .addGap(55, 55, 55)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .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(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addGap(331, 331, 331)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 347, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(limpiarcampos, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(152, 152, 152)
                                .addComponent(btn_eliminarregistro_Dt_sintalon, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(INGRESAR, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(172, 172, 172))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(5, 5, 5)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(limpiarcampos, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_eliminarregistro_Dt_sintalon, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(INGRESAR, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, 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, 866, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
public void cargaridDT_sintalon(int ID){

     java.sql.ResultSet rs=null;       
        try {
            conexion c = new conexion();
            c.getConexion();
            
             rs = c.consulta("SELECT * FROM DT_SINTALON2 WHERE (ID_DT_SINTALON="+ID+")");
             
             while(rs.next()){
                 st0_codigo.setText(String.valueOf(rs.getInt("ID_DT_SINTALON")));
                 st1_lote.setText(rs.getString("LOTE"));
                 st2_mp.setSelectedItem(rs.getString("MP"));
                 st3_n.setText(rs.getString("N"));
                 st4_peso.setText(rs.getString("PESO"));
                 st5_corteza.setSelectedItem(rs.getString("CORTEZA"));
                 st6_observaciones.setText(rs.getString("OBSERVACIONES"));
                 
                 
                 zona_ambiental=rs.getString("ZONA_AMBIENTAL");
                 localidad=rs.getString("LOCALIDAD");
                 sitio=rs.getString("SITIO");
                 siglasitio=rs.getString("SIGLA_SITIO");
                 capa_nivel=rs.getString("CAPA_NIVEL");
                 estruct_arq=rs.getString("ESTRUC_ARQ");
                 piso_subcapa=rs.getString("PISO_SUBCAPA");
                 tipo_estruct_planta=rs.getString("ESTRUC_PLANTA");
                 nombre_estruct_planta=rs.getString("NOMBRE_ESTRUC_PLANTA");
                 episodio_estruct_planta=rs.getString("EPISODIO_ESTRUC_PLANTA");
                 cuadro=rs.getString("CUADRO");
                 microsector=rs.getString("MICROSECTOR");
                }
        
        c.closeconnection();
       } catch (SQLException ex) {
            Logger.getLogger(InteraccionesBD.class.getName()).log(Level.SEVERE, null, ex);
        }
    
    
    
}

public void eliminaridDT_SINTALON(int ID_PIEZA){
int confirma =0;
String sql = "DELETE FROM DT_SINTALON2 WHERE ID_DT_SINTALON="+ID_PIEZA;    
            try {
            conexion c = new conexion();
            c.getConexion();

            confirma = c.eliminar_actualizar(sql);
            c.closeconnection();
         
         if(confirma>0){
         JOptionPane.showMessageDialog(null, "Se eliminó el registro de la pieza: "+ID_PIEZA +"\n Nota: La procedencia de la misma está activa para un ingreso nuevo \n Si no desea trabajar con la misma, diríjase a la sección de procedencias");
         InteraccionesBD interac = new InteraccionesBD();
         interac.eliminarhojaarbol(arbol_DT, selectednodeparaeliminar);
         limpiarcampos();
         consultarid();
         btn_eliminarregistro_Dt_sintalon.setEnabled(false);
         }

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "No se pudo eliminar el registro asociado a la pieza " + ID_PIEZA + ex);
        }
         
    
}


    private void st2_mpItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_st2_mpItemStateChanged
indexMP = st2_mp.getSelectedIndex();

    }//GEN-LAST:event_st2_mpItemStateChanged

    private void st3_nKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_st3_nKeyTyped
        char caracter = evt.getKeyChar();
        if (((caracter < '0') || (caracter > '9')) && (caracter != evt.VK_BACK_SPACE)
        ) {
            evt.consume();
        }
    }//GEN-LAST:event_st3_nKeyTyped

    private void st4_pesoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_st4_pesoKeyTyped
        char caracter = evt.getKeyChar();
        if (((caracter < '0') || (caracter > '9')) && (caracter != evt.VK_BACK_SPACE)
            && (caracter != '.') ) {
            evt.consume();
        }
    }//GEN-LAST:event_st4_pesoKeyTyped

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        sumadora_pesos sum = new sumadora_pesos();
        sum.setVisible(true);
        sumadora_llevar_peso="sin_talon";

    }//GEN-LAST:event_jButton1ActionPerformed

private void validarcampos(){
    ValidarCampos v = new ValidarCampos();
    v.validarcampostxt(st0_codigo);
    v.validarcampostxt(st1_lote);
    v.validarcampostxt(st3_n);
    v.validarcampostxt(st4_peso);

    v.validarcamposcbx(st2_mp);
    v.validarcamposcbx(st5_corteza);
    
    v.validarcampostxtarea(st6_observaciones);
}
    
    private void INGRESARActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_INGRESARActionPerformed
validarcampos();

if(selectednodeparaeliminar==null){
 
    guardarregistro();

}else{
    actualizarregistro();
}





    }//GEN-LAST:event_INGRESARActionPerformed

private void actualizarregistro(){
    int respuesta = 0;
    try {
     conexion c = new conexion();
    c.getConexion();

    respuesta = c.eliminar_actualizar("UPDATE DT_SINTALON2 SET "
            + ""
//            
            
            + "ZONA_AMBIENTAL='"+zona_ambiental+"', "
            + "LOCALIDAD='"+localidad+"', "
            + "SITIO='"+sitio+"', "
            + "SIGLA_SITIO='"+siglasitio+"', "
            + "CAPA_NIVEL='"+capa_nivel+"', "
            + "ESTRUC_ARQ='"+estruct_arq+"', "
            + "PISO_SUBCAPA='"+piso_subcapa+"', "
            + "ESTRUC_PLANTA='"+tipo_estruct_planta+"', "
            + "NOMBRE_ESTRUC_PLANTA='"+nombre_estruct_planta+"', "
            + "EPISODIO_ESTRUC_PLANTA='"+episodio_estruct_planta+"', "
            + "CUADRO='"+cuadro+"', "
            + "MICROSECTOR='"+microsector+"', "
            + "LOTE='"+st1_lote.getText()+"', "
            + "MP='"+st2_mp.getSelectedItem()+"', "
            + "N='"+st3_n.getText()+"', "
            + "PESO='"+st4_peso.getText()+"', "
            + "CORTEZA='"+st5_corteza.getSelectedItem()+"', "
            + "OBSERVACIONES='"+st6_observaciones.getText()+"' "



            


         +" WHERE ID_DT_SINTALON="+Integer.parseInt(st0_codigo.getText()));
    

    c.closeconnection();



    
    } catch (NumberFormatException | SQLException e) {
    JOptionPane.showMessageDialog(null, "No se pudieron guardar las modificaciones en el lote: " + e);
        }
    
            if(respuesta>0){
                    JOptionPane.showMessageDialog(null, "Se han actualizado los datos del lote: "+ st1_lote.getText());
    
                    InteraccionesBD interac = new InteraccionesBD();
                    interac.actualizarhoja(arbol_DT, selectednodeparaeliminar, "ST", st0_codigo.getText(),st1_lote.getText());
                    limpiarcampos();
                    consultarid();
                    btn_eliminarregistro_Dt_sintalon.setEnabled(false);

        }
  
}
    
private void guardarregistro(){
    int respuesta=0;

        try {
            conexion c = new conexion();
            c.getConexion();
            respuesta = c.insert("insert into DT_SINTALON2(ID_DT_SINTALON, "
                + "ZONA_AMBIENTAL,"
                + "LOCALIDAD,"
                + "SITIO,"
                + "SIGLA_SITIO,"
                + "CAPA_NIVEL,"
                + "ESTRUC_ARQ,"
                + "PISO_SUBCAPA,"
                + "ESTRUC_PLANTA,"
                + "NOMBRE_ESTRUC_PLANTA,"
                + "EPISODIO_ESTRUC_PLANTA,"
                + "CUADRO,"
                + "MICROSECTOR,"
                + "LOTE,"
                + "MP,"
                + "N,"
                + "PESO,"
                + "CORTEZA,"
                + "OBSERVACIONES"
                +") Values ("+Integer.parseInt(st0_codigo.getText())+","
                +"'"+zona_ambiental+"',"
                +"'"+localidad+"',"
                +"'"+sitio+"',"
                +"'"+siglasitio+"',"
                +"'"+capa_nivel+"',"
                +"'"+estruct_arq+"',"
                +"'"+piso_subcapa+"',"
                +"'"+tipo_estruct_planta+"',"
                +"'"+nombre_estruct_planta+"',"
                +"'"+episodio_estruct_planta+"',"
                +"'"+cuadro+"',"
                +"'"+microsector+"',"
                +"'"+st1_lote.getText()+"',"
                +"'"+st2_mp.getSelectedItem().toString()+"',"
                +"'"+st3_n.getText()+"',"
                +"'"+st4_peso.getText()+"',"
                +"'"+st5_corteza.getSelectedItem().toString()+"',"
                +"'"+st6_observaciones.getText()+"'"


                + ")");

            c.closeconnection();


        } catch (SQLException ex) {
            Logger.getLogger(DT_frame.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(respuesta>0){
                    cargarhojanueva();
                    limpiarcampos();
                    consultarid();
                    btn_eliminarregistro_Dt_sintalon.setEnabled(false);
        }
}    
    
    
    
    
private void cargarhojanueva(){
DefaultTreeModel model = (DefaultTreeModel) DT_frame.arbol_DT.getModel();        
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
DefaultMutableTreeNode leaf = (DefaultMutableTreeNode) root.getChildAt(0);
MutableTreeNode hoja = new DefaultMutableTreeNode("ST-"+st0_codigo.getText()+"/"+st1_lote.getText());
leaf.insert(hoja, leaf.getChildCount());
model.reload();

int j = DT_frame.arbol_DT.getRowCount();
       int i = 0;
       while(i < j) {
           DT_frame.arbol_DT.expandRow(i);
           i += 1;
           j = DT_frame.arbol_DT.getRowCount();
       }

}


private void consultarid(){
    InteraccionesBD inter = new InteraccionesBD();
    int id = inter.obtenersiguienteID("DT_SINTALON2", "ID_DT_SINTALON");
    st0_codigo.setText(String.valueOf(id));
}    
    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
Cargar_MP cargartodasMP = new Cargar_MP();
cargartodasMP.cargar_todas_mp(st2_mp);

consultarid();

    }//GEN-LAST:event_formInternalFrameOpened

    private void limpiarcamposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiarcamposActionPerformed
limpiarcampos();
    }//GEN-LAST:event_limpiarcamposActionPerformed
private void limpiarcampos(){
Limpiar_campos aux = new Limpiar_campos();
aux.limpiartxt(st1_lote);
aux.limpiartxt(st3_n);
aux.limpiartxt(st4_peso);
aux.limpiarcbx(st5_corteza);
aux.limpiartxtarea(st6_observaciones);

    
}
    private void st6_observacionesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_st6_observacionesKeyPressed
if (evt.getKeyChar() != evt.VK_ENTER && evt.getKeyChar() != evt.VK_TAB)
				{
				} else {
   
    evt.consume();
    }
    }//GEN-LAST:event_st6_observacionesKeyPressed

    private void btn_eliminarregistro_Dt_sintalonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_eliminarregistro_Dt_sintalonActionPerformed
eliminaridDT_SINTALON(Integer.parseInt(st0_codigo.getText()));  
// TODO add your handling code here:
    }//GEN-LAST:event_btn_eliminarregistro_Dt_sintalonActionPerformed

    private void st6_observacionesKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_st6_observacionesKeyTyped
if (st6_observaciones.getText().length()== 500){
    evt.consume();
}
    }//GEN-LAST:event_st6_observacionesKeyTyped


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton INGRESAR;
    public static javax.swing.JButton btn_eliminarregistro_Dt_sintalon;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    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.JSeparator jSeparator1;
    private javax.swing.JButton limpiarcampos;
    private javax.swing.JTextField st0_codigo;
    private javax.swing.JTextField st1_lote;
    private javax.swing.JComboBox<String> st2_mp;
    private javax.swing.JTextField st3_n;
    public static javax.swing.JTextField st4_peso;
    private javax.swing.JComboBox<String> st5_corteza;
    private javax.swing.JTextArea st6_observaciones;
    // End of variables declaration//GEN-END:variables
}
