<%@ page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,java.text.*,m05bClasses.*" %>
<%
	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if ((session.getAttribute("objetoSeguridad")) == null)  { 
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%> <%
	} 
%>	
<%@ include file="/m05bIdioma.inc"%>
<HTML>

<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
<title><%= resTit.getString("titLstVehiPorRango")%></title>
	
<SCRIPT language=JavaScript>
		function fncRetornar() {
				 document.formSolicitud.action="/m05bParqueMovilWar/m05bVehiPorRangoJsp.jsp" ;
				 document.formSolicitud.submit();
		}
</SCRIPT>
</HEAD>	

<!-- Hojas de Estilo -->
<%	String VehiculosRango = m05bFicheroProperties.getInstance().getParameter("PDF.VehiculosRango"); %>
<% m05bFileLog miLog = new m05bFileLog();%>
<BODY style="cursor: wait" onload="document.body.style.cursor='default';document.all['general'].style.visibility='visible';document.all['general'].style.cursor='default';" onunload="document.body.style.cursor='wait';document.all['general'].style.cursor='wait';">
<div  id="general" style="POSITION: absolute;visibility:hidden;cursor: wait">
<form NAME="formSolicitud" METHOD="POST">
<%
	m05bComun miComun=new m05bComun();
	String sCentro = request.getParameter("CodCentro");
	String sSituacion = request.getParameter("SituacionTexto");
	String sOrdenado = request.getParameter("Ordenado");
	String sAgrupado = request.getParameter("Agrupado");
	String sGRango = request.getParameter("GRango");
	String sRango = request.getParameter("CodRango");
	String srcPDF = VehiculosRango + "?CodCentro="+sCentro +"&Situacion="+sSituacion+"&GRango="+sGRango
	+"&Rango="+sRango+"&Ordenado="+sOrdenado+"&Agrupado="+sAgrupado;
	
	java.sql.Connection conn=null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
      try
      {  //HttpSession session = request.getSession(true);
			m05bConexion miConex = new m05bConexion();
			conn = miConex.getConnection();
   String sSentencia=" SELECT  1 "+
" FROM "+
m05bConstantes.TAB_DEPARTAMENTOS+","+	
m05bConstantes.TAB_VEHICULOS+","+		
m05bConstantes.TAB_MODELOS+","+		
m05bConstantes.TAB_DESCRIPCIONES+"  M,"+
m05bConstantes.TAB_CENTROS+","+	
m05bConstantes.TAB_TARJETAS+
" WHERE " +		
m05bConstantes.COL_34_MATRICULA+"="+m05bConstantes.COL_31_MATRICULA +" AND " +
m05bConstantes.COL_34_MODELO+"="+m05bConstantes.COL_17_CODMOD +" AND M." +
m05bConstantes.COL_99_CODTABLA+"="+m05bConstantes.DESC_MARCAS + " AND "+ 		
m05bConstantes.COL_34_MARCA+"= M."+m05bConstantes.COL_99_CODDESC +" AND " +	
m05bConstantes.COL_06_CODDPTO+"=" +m05bConstantes.COL_34_CODDPTO + " AND " +	
m05bConstantes.COL_05_CODIGO+"="+m05bConstantes.COL_31_CENTRO ;

    	   miLog.addTraza("BEGO" , "m05bVehiculosPorRango" , "sSentencia: " + sSentencia, m05bConstantes.LOG_NIVEL_BAJO);    	
if (!(sSituacion.equals(""))){
        sSituacion=miComun.ListaCaracteres(sSituacion);
	
    	sSentencia= sSentencia + " AND " + m05bConstantes.COL_34_SITUACION+ " in ("+sSituacion+")";}
if (!(sCentro.equals(""))){
    	sSentencia= sSentencia + " AND " + m05bConstantes.COL_31_CENTRO+ " = '"+sCentro+"'" ;}
    	    	   miLog.addTraza("BEGO" , "m05bVehiculosPorRango" , "sSentenciaCentro: " + sSentencia, m05bConstantes.LOG_NIVEL_BAJO);    	
if (!(sRango.equals(""))){
    	sSentencia= sSentencia + " AND " + m05bConstantes.COL_34_RANGO+ " = '"+sRango+"'" ;}
else if (!(sGRango.equals(""))){
    	String sSentenciaGrupo=" SELECT "+ m05bConstantes.COL_36_RANGOS+
    	                " FROM " + m05bConstantes.TAB_GRUPOS + 
    	                " WHERE " + m05bConstantes.COL_36_CODIGO + " = '" +sGRango+"'";
    	pstmt = conn.prepareStatement(sSentenciaGrupo);
		rs = pstmt.executeQuery();
        if (rs.next()){
		    sGRango=rs.getString(1)==null ? "":rs.getString(1);	
            sGRango=miComun.ListaCaracteres(sGRango);
    	sSentencia= sSentencia + " AND " + m05bConstantes.COL_34_RANGO+ " in ( "+sGRango + ")";

            }
}
                     pstmt = conn.prepareStatement(sSentencia);
		                     rs = pstmt.executeQuery();
%>
	
<TABLE class="general">
  <tr>
       <td width="90%" align="right">
          <!--INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Retornar" ONCLICK="JavaScript:fncRetornar();" onMouseOver="top.status='Retornar'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/retornar.gif"-->
          <input type="button" class="boton" name="<%= res.getString("etBOT_RETORNAR")%>" value="<%= res.getString("etBOT_RETORNAR")%>" ONCLICK="JavaScript:fncRetornar();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSRETORNAR")%>'; return false" onMouseOut="top.status=''; return false" />				                
       </td>
    
  </tr>
  <tr>
    <td colspan="2">
    <% if (rs.next() == true){ %>
      
		<embed name='pdfVehiculosRango' src='<%=srcPDF%>' type="application/pdf" width='736' height='500'></embed>
    <%} else {%>
		<embed name='pdfVehiculosRango' src='/parquemovil/SinDatos.pdf' type="application/pdf" width='736' height='500'></embed>
    <%}%>
	<%	} catch (Exception SQLException) {
			miLog.addTraza(SQLException);
		} 	finally{
				if (rs != null)
					rs.close();			
				if (pstmt != null)
					pstmt.close();
				if (conn != null)
					conn.close();}%>
  	</td>
  </tr>
</TABLE>
</form>
<script type="text/javascript" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05bMsControl.js"></script>
 
</div>		
</body>
</html>
