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

import static arql2020.ARQL2020.indexMP;
//import arql2020.DT_sintalon;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class Cargar_MP {
    
public void cargar_todas_mp(JComboBox mp){
  int indice = indexMP;
    mp.removeAllItems();
mp.addItem("Seleccione");
    try {
            conexion c = new conexion();
            c.getConexion();
            
            
            
            ResultSet rs = c.consulta("SELECT DISTINCT NOMBRE_MP, CODIGO_NUM FROM MP ORDER BY CODIGO_NUM");
            while(rs.next()){
            mp.addItem(rs.getString("NOMBRE_MP")); 
            }       
        rs.close();
        c.closeconnection();
        
        mp.setSelectedIndex(indice);
        } catch (SQLException ex) {
//         JOptionPane.showMessageDialog(null, "No se puede cargar la lista de materias primas \nError: " + ex);   
        }
         
        
    
}

public void cargar_todas_mpJtable(JTable tbl){
  int indice = indexMP;
 Object [] fila = new Object[2];
    DefaultTableModel dtm = (DefaultTableModel) tbl.getModel();
        int a = dtm.getRowCount()-1;
        for (int i = a; i >= 0; i--) {          
        dtm.removeRow(dtm.getRowCount()-1);
        }
    try {
            conexion c = new conexion();
            c.getConexion();
            
            
            
            ResultSet rs = c.consulta("SELECT DISTINCT NOMBRE_MP, CODIGO_NUM FROM MP ORDER BY CODIGO_NUM");
            while(rs.next()){
                if(rs.getInt("CODIGO_NUM")<14){
                 fila[0]=   rs.getString("NOMBRE_MP");
                 fila[1]=   "Por defecto en ARQ.L";
                }else{
                 fila[0]=   rs.getString("NOMBRE_MP");
                 fila[1]=   "Usuario";
                }
               
                dtm.addRow(fila);
            }       
        rs.close();
        c.closeconnection();
    

        } catch (SQLException ex) {
//         JOptionPane.showMessageDialog(null, "No se puede cargar la lista de materias primas \nError: " + ex);   
        }
         
        
    
}
}
