/*
 * 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 pe.siso.horario.MySqlDAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import pe.siso.horario.Beans.Modulo;
import pe.siso.horario.DAO.ModuloDAO;

/**
 *
 * @author fcelestino
 */
public class MySqlModuloDAO implements ModuloDAO {

    @Override
    public ArrayList<Modulo> listarModulo(int codigoTipoUsuario) throws Exception {
        String Base = "horario";
        
        ArrayList<Modulo> lista = new ArrayList<Modulo>();
        Connection cnx = null;
        try{
         cnx = MySqlDAOFactory.obtenerConexion(Base);
        Statement st = cnx.createStatement();
        
        String query ;
        query = "select modu.cod_mod, modu.nom_mod, modu.acc_mod, modu.ord_mod, modu.ico_mod, modu.est_mod  " +
                "from modulo as modu " +
                "INNER JOIN config_modulo AS conf ON conf.cod_mon=modu.cod_mod " +
                "WHERE modu.est_mod='1' and conf.cod_tip_usu='"+codigoTipoUsuario+"' ORDER BY modu.ord_mod";

//        System.out.println(query);
        ResultSet rs = st.executeQuery(query);
        
        
        
        while(rs.next()){
            Modulo modulo= new Modulo();
            modulo.setIdModulo(rs.getInt("cod_mod"));
            modulo.setNombreModulo(rs.getString("nom_mod"));
            modulo.setAccionModulo(rs.getString("acc_mod"));
            modulo.setOrdenModulo(rs.getInt("ord_mod"));
            modulo.setIconoModulo(rs.getString("ico_mod"));
            modulo.setEstadoModulo(rs.getInt("est_mod"));
            lista.add(modulo);
        }
        } catch (Exception e){
            e.printStackTrace();
        } finally{
            cnx.close();
        }
        return lista;
    }

    @Override
    public ArrayList<Modulo> listarModulo() throws Exception {
        String Base = "horario";
        ArrayList<Modulo> lista = new ArrayList<Modulo>();
        Connection cnx = null;
        try{
         cnx = MySqlDAOFactory.obtenerConexion(Base);
        Statement st = cnx.createStatement();
        
        
        String query ;
        query = "SELECT " +
                "modu.cod_mod, " +
                "modu.nom_mod, " +
                "modu.acc_mod, " +
                "modu.ord_mod, " +
                "modu.ico_mod, " +
                "modu.est_mod " +
                "FROM " +
                "modulo AS modu " +
                "where modu.est_mod='1' ORDER BY modu.ord_mod";
        
        System.out.println(query);
        ResultSet rs = st.executeQuery(query);
        
        
        
        while(rs.next()){
            Modulo modulo= new Modulo();
            modulo.setIdModulo(rs.getInt("cod_mod"));
            modulo.setNombreModulo(rs.getString("nom_mod"));
            modulo.setAccionModulo(rs.getString("acc_mod"));
            modulo.setOrdenModulo(rs.getInt("ord_mod"));
            modulo.setIconoModulo(rs.getString("ico_mod"));
            modulo.setEstadoModulo(rs.getInt("est_mod"));
            lista.add(modulo);
        }
        } catch (Exception e){
            e.printStackTrace();
        } finally{
            cnx.close();
        }
        return lista;
    }

    @Override
    public ArrayList<Modulo> listarModuloDocente(int codigoNivel) throws Exception {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
