/*
 * 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.Servlets;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pe.siso.horario.Beans.Grado;
import pe.siso.horario.Services.GradoServices;

/**
 *
 * @author fcelestino
 */
public class ServletGrado extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String param=request.getParameter("Accion");
        if("listadoGrado".equals(param)){
            listadoGrado(request,response);
        }else if("listadoGradoBusqueda".equals(param)){
            listadoGradoBusqueda(request,response);
        }else if("registargrado".equals(param)){
            registargrado(request,response);
        }else if("cambiarEstado".equals(param)){
            cambiarEstado(request,response);
        }else if("cargarGrado".equals(param)){
            cargarGrado(request,response);
        }else if("armarEditar".equals(param)){
            armarEditar(request,response);
        }else if("actualizar".equals(param)){
            actualizar(request,response);
        }else if("cargarGradoBlo".equals(param)){
            cargarGradoBlo(request,response);
        }else if("cantidadGradoUso".equals(param)){
            cantidadGradoUso(request,response);
        }
        
    }

    private void listadoGrado(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GradoServices servicios = new GradoServices();
        ArrayList<Grado> lista = null;
       
        int cantidad= Integer.parseInt(request.getParameter("cantidad"));
        int pagina= Integer.parseInt(request.getParameter("pagina"));
        int inicio = (pagina-1)*cantidad;
        
       lista=servicios.listarGrado(inicio, cantidad);
       int cantRegistro=0;
        
        cantRegistro=servicios.cantidadGrado();
         
        //--------------CALCULO DE PAGINADO---------
        int numero = cantRegistro/cantidad;
        int resto = cantRegistro%cantidad;
        if(resto>0){
            numero = numero+1;
        }
        /* */
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        
        
        pw.println("<div style=\"border: 1px solid #CCCCCC;\">\n" +
"                       <div class=\"table-header\">\n" +
"                           <table width=\"100%\" >"
                + "             <tbody>"
                + "                 <tr>"
                + "                     <td>Listado de Grados</td>"
                + "                     <td align=\"right\">"
                + "                     </td>"
                + "                     <td width=\"10\"></td>"
                + "                 </tr>"
                + "             </tbody>"
                + "         </table>" +
"                       </div>\n" +
"                       <div>\n" +
"                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">\n" +

"                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >\n" +
"                                   <thead>\n" +
"                                       <tr role=\"row\">\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\" >N°</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">TIPO CENTRO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">CENTRO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">NIVEL</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">TIPO GRADO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">GRADO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">EDICIÓN</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">ESTADO</th>\n" +
"                                       </tr>\n" +
"                                   </thead>\n" +
"                                   <tbody>");
        
        int cont_ini = 0;
        int cont_fin = 0;
        int cont= inicio+1;
        for(int i=0; i< lista.size(); i++) {
            if(i==0){cont_ini=cont;}
            if(cont%2==0){
                pw.println("<tr class=\"alt\" >");
            }else{
                pw.println("<tr ><tr>");
            }
           
            String estado="";
            if(lista.get(i).getEstadoGrado()==1){
                estado="<a href=\"javascript:validar_estado(0,"+pagina+","+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n" +
                            "<img src=\"imagenes/icons/lightbulb.png\" />\n" +
                        "</a>";
            }else{
                estado="<a href=\"javascript:validar_estado(1,"+pagina+","+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n" +
                            "<img src=\"imagenes/icons/lightbulb_off.png\" />\n" +
                        "</a>";
            }
            
             pw.println("    <td align='center'>"+cont+"</td>"
                     + "    <td>"+lista.get(i).getNombreTipoCentro()+"</td>"
                     + "    <td>"+lista.get(i).getNombreCentro()+"</td>"
                     + "    <td>"+lista.get(i).getNombreNivel()+"</td>"
                     + "    <td>"+lista.get(i).getNombreTipoGrado()+"</td>"
                     + "    <td>"+lista.get(i).getNombreGrado()+"</td>"
                     + "    <td  align='center'><a href=\"javascript:armarEdicion("+pagina+","+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n"
                     + "            <img src=\"imagenes/icons/page_edit.png\" />\n"
                     + "        </a>"
                     + "    </td>"
                     + "    <td align='center' valign='middle'>"+estado+"</td>"
                     + " </tr>");
            
            cont++;
        }
        cont_fin = cont - 1;
        if(cont==1){
            pw.println("<tr><td colspan='8' align='center'>No hay Grados registrados</td></tr>");
        } 
          
         pw.println("   </tbody>\n" +
                    "</table>");
         
         
         //::::::::::::::: PIE ::::::::::::::::

        
        if (cantRegistro >= cantidad) {
            
            pw.println("<div class='row'>" + 
                            "<div class='col-xs-6'>" +
                                "<div class='dataTables_info' id='sample-table-2_info' role='status' aria-live='polite'> " +
                                    "Mostrando del "+cont_ini+" al "+cont_fin+" de "+cantRegistro+" Aulas" +
                                "</div> " +
                            "</div> " +
                            "<div class='col-xs-6'> " +
                                "<div class='dataTables_paginate paging_simple_numbers' id='sample-table-2_paginate'>" +
                                    "<ul class='pagination'>");
            
            int anterior = pagina - 1;
            int siguiente = pagina + 1;
            if (pagina > 1) {
                pw.println("<li tabindex='0' class='paginate_button previous' id='sample-table-2_previous' aria-controls='sample-table-2'> " +
                                "<a href='javascript:listarGrado(" + 1 + ");'> << </a>" +
                           "</li>");
                pw.println("<li tabindex='0' class='paginate_button previous' id='sample-table-2_previous' aria-controls='sample-table-2'> " +
                                "<a href='javascript:listarGrado(" + anterior + ");'>Anterior</a>" +
                           "</li>");
                
                //pw.println("<li><a href=\"javascript:buscarAula(" + anterior + ");\"><span>Anterior</span></a></li>");
            }else{
                pw.println("<li tabindex='0' class='paginate_button previous disabled' id='sample-table-2_previous' aria-controls='sample-table-2'> " +
                                "<a> << </a>" +
                           "</li>");
                pw.println("<li tabindex='0' class='paginate_button previous disabled' id='sample-table-2_previous' aria-controls='sample-table-2'> " +
                                "<a>Anterior</a>" +
                           "</li>");
            }

            //for(int i = 1; i<=numero; i++){
            if (numero > 5) {
                if (pagina > 2) {
                    if (numero >= pagina + 5) {
                        for (int i = pagina - 2; i < pagina + 3; i++) {
                            if (pagina == i) {
                                pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                            "</li>");
                                //pw.println("<li ><a href=\"javascript:buscarAula(" + i + ");\" style='background-color:#00A9FB'><span>" + i + "</span></a></li>");
                            } else {
                                pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                            "</li>");
                                //pw.println("<li><a href=\"javascript:buscarAula(" + i + ");\" ><span>" + i + "</span></a></li>");
                            }
                        }
                    } else {
                        if (pagina == numero) {
                            for (int i = pagina - 4; i <= numero; i++) {
                                if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                            }
                        } else if (pagina == numero - 1) {
                            for (int i = pagina - 3; i <= numero; i++) {
                                if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                            }
                        } else if (pagina == numero - 2) {
                            for (int i = pagina - 2; i <= numero; i++) {
                                if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                            }
                        } else if (pagina == numero - 3) {
                            for (int i = pagina - 1; i <= numero; i++) {
                                if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                            }
                        } else if (pagina == numero - 4) {
                            for (int i = pagina; i <= numero; i++) {
                                if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                            }
                        }
                    }
                } else {
                    if (pagina == 1) {
                        for (int i = pagina; i < pagina + 5; i++) {
                            if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                        }
                    } else {
                        for (int i = pagina - 1; i < pagina + 4; i++) {
                            if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                        }
                    }
                }
            } else {
                for (int i = 1; i <= numero; i++) {
                    if (pagina == i) {
                                    pw.println("<li tabindex='0' class='paginate_button active' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                } else {
                                    pw.println("<li tabindex='0' class='paginate_button' aria-controls='sample-table-2'>" +
                                                    "<a href='javascript:listarGrado(" + i + ");'>" + i + "</a>" +
                                                "</li>");
                                }
                }
            }
                                                                //}

            if (pagina < numero) {
                pw.println("<li tabindex='0' class='paginate_button next' id='sample-table-2_next' aria-controls='sample-table-2'>" +
                                "<a href='javascript:listarGrado(" + siguiente + ");'>Siguiente</a>" +
                            "</li>");
                pw.println("<li tabindex='0' class='paginate_button next' id='sample-table-2_next' aria-controls='sample-table-2'>" +
                                "<a href='javascript:listarGrado(" + numero + ");'> >> </a>" +
                            "</li>");
            }else{
                pw.println("<li tabindex='0' class='paginate_button next disabled' id='sample-table-2_next' aria-controls='sample-table-2'>" +
                                "<a>Siguiente</a>" +
                            "</li>");
                pw.println("<li tabindex='0' class='paginate_button next disabled' id='sample-table-2_next' aria-controls='sample-table-2'>" +
                                "<a> >> </a>" +
                            "</li>");
            }
            pw.println(         "</ul>" +
                            "</div>" +
                        "</div>" +
                    "</div>");
        }
        
        
        
        //::::::::::::::: PIE ::::::::::::::::
        pw.println("</div>" +
            "</div>" +
        "</div>");
         
         
         
    }

    private void listadoGradoBusqueda(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GradoServices servicios = new GradoServices();
        ArrayList<Grado> lista = null;
        String codCentro = request.getParameter("codCentro");
        String codnivel = request.getParameter("codnivel");
         String codTipoGrado = request.getParameter("codTipoGrado");
        lista=servicios.listarGrado(codCentro, codnivel, codTipoGrado);
        
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        
        pw.println("<div style=\"border: 1px solid #CCCCCC;\">\n" +
"                       <div class=\"table-header\">\n" +
"                           <table width=\"100%\" >"
                + "             <tbody>"
                + "                 <tr>"
                + "                     <td>Listado de Grados</td>"
                + "                     <td align=\"right\">"
                + "                     </td>"
                + "                     <td width=\"10\"></td>"
                + "                 </tr>"
                + "             </tbody>"
                + "         </table>" +
"                       </div>\n" +
"                       <div>\n" +
"                           <div class=\"dataTables_wrapper form-inline no-footer\" id=\"sample-table-2_wrapper\">\n" +

"                               <table class=\"table table-striped table-bordered table-hover dataTable no-footer\" id=\"sample-table-2\" role=\"grid\" aria-describedby=\"sample-table-2_info\" >\n" +
"                                   <thead>\n" +
"                                       <tr role=\"row\">\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\" >N°</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">TIPO CENTRO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">CENTRO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">NIVEL</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">TIPO GRADO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">GRADO</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">EDICIÓN</th>\n" +
"                                           <th tabindex=\"0\" class=\"center\" rowspan=\"1\" colspan=\"1\">ESTADO</th>\n" +
"                                       </tr>\n" +
"                                   </thead>\n" +
"                                   <tbody>");
        int cont= 1;
        for(int i=0; i< lista.size(); i++) {
           
            if(cont%2==0){
                pw.println("<tr class=\"alt\" >");
            }else{
                pw.println("<tr >");
            }
            
            String estado="";
            if(lista.get(i).getEstadoGrado()==1){
                estado="<a href=\"javascript:validar_estadoBusqueda(0,"+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n" +
                            "<img src=\"imagenes/icons/lightbulb.png\" />\n" +
                        "</a>";
            }else{
                estado="<a href=\"javascript:validar_estadoBusqueda(1,"+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n" +
                            "<img src=\"imagenes/icons/lightbulb_off.png\" />\n" +
                        "</a>";
            }
            
             pw.println("   <td align='center'>"+cont+"</td>"
                     + "    <td>"+lista.get(i).getNombreTipoCentro()+"</td>"
                     + "    <td>"+lista.get(i).getNombreCentro()+"</td>"
                     + "    <td>"+lista.get(i).getNombreNivel()+"</td>"
                     + "    <td>"+lista.get(i).getNombreTipoGrado()+"</td>"
                     + "    <td>"+lista.get(i).getNombreGrado()+"</td>"
                     + "    <td  align='center'><a href=\"javascript:armarEdicionBusqueda("+lista.get(i).getCodigoGrado()+");\" class=\"regular\" >\n"
                     + "            <img src=\"imagenes/icons/page_edit.png\" />\n"
                     + "        </a>"
                     + "    </td>"
                     + "    <td align='center' valign='middle'>"+estado+"</td>"
                     + " </tr>");
            cont++;
        }
        
        if(cont==1){
            pw.println("<tr><td colspan='8' align='center'>No Tipo centros registrados</td></tr>");
        } 
          
         pw.println("</tbody>\n" +
                    "</table>");
         
         pw.println("       </div>" +
                    "   </div>"
                 +  "</div>");
    }

    private void registargrado(HttpServletRequest request, HttpServletResponse response) {
        GradoServices servicios = new GradoServices();      
        String grado = request.getParameter("grado");
        String codigoTipoGrado = request.getParameter("codTipoGrado");
        String codigoNivel = request.getParameter("codNivel");
        String codigoCentro = request.getParameter("codCentro");
        servicios.registrarGrado(grado, codigoCentro, codigoNivel, codigoTipoGrado);
    }

    private void cambiarEstado(HttpServletRequest request, HttpServletResponse response) {
        GradoServices servicios = new GradoServices();
        String dato = request.getParameter("dato");
        String codGrado = request.getParameter("codGrado");
        servicios.cambiarEstado(dato, codGrado);
    }

    private void cargarGrado(HttpServletRequest request, HttpServletResponse response) throws IOException {
        
        GradoServices servicios = new GradoServices();
        ArrayList<Grado> lista = null;
        String accion = request.getParameter("accion");
        String nombre = request.getParameter("nombre");
        String codCentro = request.getParameter("codCentro");
        String codNivel = request.getParameter("codNivel");
        String codTipoGrado = request.getParameter("codTipoGrado");
        
        lista=servicios.cargarGrado(codCentro, codNivel, codTipoGrado);
        
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        
        pw.println("<select id='"+nombre+"' class='form-control validate[required]' onChange='"+accion+"'>");
        pw.println("<option value=''>[Seleccione]</option>");
        for(int i=0; i< lista.size(); i++) {
            pw.println("<option value='"+lista.get(i).getCodigoGrado()+"'>"+lista.get(i).getNombreGrado()+"</option>");
        }

        pw.println("</select>");
        
        
    }
    
    private void armarEditar(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GradoServices servicios=new GradoServices();
        Grado grado = new Grado();
       
        String codGrado = request.getParameter("codGrado");
        
        grado=servicios.nombreGrado(codGrado);
        
        
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        
         pw.println("<table  width='100%'>"
               + "<tr>"
               + "<td align='center'> "
               + "<table>"
               + "      <tr>"
               + "          <td><b>Tipo Centro </b></td>"
               + "          <td width='10'></td>"
               + "          <td><label>"+grado.getNombreTipoCentro()+"</label></td>"
               + "      </tr>"  
               + "      <tr>"  
               + "          <td colspan='3' height='15'></td>"  
               + "      </tr>"  
               + "      <tr>"
               + "          <td><b>Centro </b></td>"
               + "          <td width='10'></td>"
               + "          <td><label>"+grado.getNombreCentro()+"</label></td>"
               + "      </tr>"
               + "      <tr>"  
               + "          <td colspan='3' height='15'></td>"  
               + "      </tr>"  
               + "      <tr>"
               + "          <td><b>Nivel </b></td>"
               + "          <td width='10'></td>"
               + "          <td><label>"+grado.getNombreNivel()+"</label></td>"
               + "      </tr>"
               + "      <tr>"  
               + "          <td colspan='3' height='15'></td>"  
               + "      </tr>"  
               + "      <tr>"
               + "          <td><b>Tipo Grado </b></td>"
               + "          <td width='10'></td>"
               + "          <td><label>"+grado.getNombreTipoGrado()+"</label></td>" 
               + "      </tr>"
               + "      <tr>"  
               + "          <td colspan='3' height='15'></td>"  
               + "      </tr>"  
               + "      <tr>"  
               + "          <td><b>Grado </b> <span style='color:red;'>*</span></td>"
               + "          <td width='10'></td>"
               + "          <td><input id='txt_nom_grado' type='text' class='validate[required]' value='"+grado.getNombreGrado()+"' onChange='conMayusculas(this);'></td>"
               + "      </tr>"
               + "  </table>"
               + "</td>"
               + "</tr>"
               + "</table>");   
    }

    private void actualizar(HttpServletRequest request, HttpServletResponse response) {
       GradoServices servicio= new GradoServices();
       String codGrado= request.getParameter("codGrado");
       String nombre=request.getParameter("nombre");
       servicio.actualizar(nombre, codGrado);
    }

    private void cargarGradoBlo(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GradoServices servicios = new GradoServices();
        ArrayList<Grado> lista = null;
        String accion = request.getParameter("accion");
        String nombre = request.getParameter("nombre");
        String codCentro = request.getParameter("codCentro");
        String codNivel = request.getParameter("codNivel");
        String codTipoGrado = request.getParameter("codTipoGrado");
        String codSede = request.getParameter("codSede");
        String codTipoCentro = request.getParameter("codTipoCentro");
        
        lista=servicios.cargarGrado(codSede, codTipoCentro, codCentro, codNivel, codTipoGrado);
        
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        
        pw.println("<select id='"+nombre+"' class='form-control' onChange='"+accion+"'>");
        pw.println("<option value=''>[Seleccione]</option>");
        for(int i=0; i< lista.size(); i++) {
            pw.println("<option value='"+lista.get(i).getCodigoGrado()+"'>"+lista.get(i).getNombreGrado()+"</option>");
        }

        pw.println("</select>");
    }

    private void cantidadGradoUso(HttpServletRequest request, HttpServletResponse response) throws IOException {
        GradoServices servicios = new GradoServices();
        String codGrado=request.getParameter("codGrado");
        response.setContentType("text/html");
        PrintWriter pw = response.getWriter();
        int dato=servicios.cantidadGrado(codGrado);
            if(dato==0){
              pw.println("0");
            }else {
              pw.println("1");
            }
    }
    

}