<%@page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,m05bClasses.*" %>
<%@include file="/mantenimientosJSP/includes/m05b.inc"%>
<HTML>
<%
	// _______________________________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"%> 
<%
	} 
	String persona = (String) session.getAttribute("persona");
%>
<%@ include file="/m05bIdioma.inc"%>
	
<head>
			<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
			<script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/formateador.js"></script>
</head>
<%
  String sql="";
  String strMatricula="", modelo="", color="", kmrev="", marca="", rango="", mesrev="", situacion="";
  String kmAct="", fKmAct="";
  m05bFileLog miLog = new m05bFileLog();
  strMatricula=request.getParameter("Matricula")==null?"":request.getParameter("Matricula");
  java.sql.Connection conn=null;
  PreparedStatement pstmt = null;
  ResultSet rs = null;
  
  try {
  	 if (!strMatricula.equals("")) {
	      sql="select NVL(C." + campoTexto+ m05bConstantes.COL_99_DESCRIPCION + ",C." + m05bConstantes.COL_99_DESCRIPCION + "),"
		      	  + "NVL(R." +campoTexto+ m05bConstantes.COL_99_DESCRIPCION +",R." + m05bConstantes.COL_99_DESCRIPCION 
		      	  + "),M." + m05bConstantes.COL_99_DESCRIPCION + ","
		          + m05bConstantes.COL_34_KMACTUALES + ",TO_CHAR("+ m05bConstantes.COL_34_FKMACT + ",'"+formatoFecha+"')," + m05bConstantes.COL_17_DESCRIP + ","
		          + m05bConstantes.COL_34_KMREVIS + "," + m05bConstantes.COL_34_MESREVIS + ", "
		          + m05bConstantes.COL_34_SITUACION + 
	          " FROM "+ m05bConstantes.TAB_VEHICULOS + ","+ m05bConstantes.TAB_DESCRIPCIONES + 
		          " C, "+ m05bConstantes.TAB_DESCRIPCIONES + " 	R , "+ m05bConstantes.TAB_DESCRIPCIONES +
		          " M," + m05bConstantes.TAB_MODELOS + 
	          " where "+ m05bConstantes.COL_34_MATRICULA + "='"+ strMatricula + 
		          "' AND "+ m05bConstantes.COL_34_MODELO + " = " + m05bConstantes.COL_17_CODMOD +
		          //" AND " + m05bConstantes.COL_34_SITUACION+" = '"+ m05bConstantes.VEH_ALTA + "' " +
		          " AND C." + m05bConstantes.COL_99_CODTABLA + "(+) ='" + m05bConstantes.DESC_COLORES + 
		      	  "' AND C."  + m05bConstantes.COL_99_CODDESC + "(+) =" + m05bConstantes.COL_34_COLOR + 
		          " AND M." + m05bConstantes.COL_99_CODTABLA + "='" + m05bConstantes.DESC_MARCAS + 
		      	  "' AND M." + m05bConstantes.COL_99_CODDESC + "=" + m05bConstantes.COL_34_MARCA + 
		      	  " AND" + " R." + m05bConstantes.COL_99_CODTABLA + "='" + m05bConstantes.DESC_RANGOS + 
		      	  "' AND R." + m05bConstantes.COL_99_CODDESC + "=" + m05bConstantes.COL_34_RANGO  ;
	       miLog.addTraza(persona, "Revi Frame", "SQL: " + sql, m05bConstantes.LOG_NIVEL_BAJO);
	       //m05bbBeginSelect(sql);
		   //m05bRS = m05bPStmt.executeQuery();
		    m05bConexion miConex = new m05bConexion();
            conn = miConex.getConnection();
            conn.setAutoCommit(false);  // Al final si todo ha ido bien se hace commit	 
		    pstmt = conn.prepareStatement(sql);
		    rs = pstmt.executeQuery();		   
	       if (rs.next() == true){
	               color=rs.getString(1)==null?"":rs.getString(1); 			//color
                   rango=rs.getString(2);										//Rango
	               marca=rs.getString(3); 										//Marca
	               kmAct=rs.getString(4); 										//Km Actuales
	               fKmAct=rs.getString(5); 										//Fecha Km Actuales
	               modelo=rs.getString(6);     									//Modelo
	               kmrev=rs.getString(7);  										//KmRevision
	               mesrev=rs.getString(8);  									//MesRevision
	               situacion=rs.getString(9);  									//Situacion
	       }
  	 }
  } catch (Exception SQLException){
   		miLog.addTraza(SQLException);
  } finally {
	    //m05bEndSelect();
		       if (rs != null)
			   rs.close();
		       if (pstmt != null)
			   pstmt.close();
		       if (conn != null)
			   conn.close();

	    
  }
  	  %>
             <script>
                 top.formRevision.Marca.value="<%=marca%>"; 
                 top.formRevision.Modelo.value="<%=modelo%>";
                 top.formRevision.Color.value="<%=color%>";
                 top.formRevision.Rango.value="<%=rango%>";  
                 top.formRevision.RevKm.value="<%=kmrev%>";
                 top.formRevision.Revikm.value="<%=kmrev%>";
                 top.formRevision.RevMes.value="<%=mesrev%>";
                 top.formRevision.KmAct.value="<%=kmAct%>";
                 top.formRevision.FKmAct.value="<%=fKmAct%>";
                 top.formRevision.Situacion.value="<%=situacion%>";
				 formatNumero(top.formRevision.RevKm);
				 formatNumero(top.formRevision.RevMes);
             </script>

<BODY bgcolor="white" onkeydown="cancelaEnter();">
</BODY>
</HTML>