package vehiculosServlet;

import java.io.IOException;
import java.util.StringTokenizer;

import javax.servlet.http.HttpSession;

import m05bBD.m05bVehiculos;
import m05bClasses.m05bFileLog;


/**
 * Inserte aquí la descripción del tipo.
 * Fecha de creación: (16/03/2005)
 */
public class m05bVehModificarDatosServlet extends javax.servlet.http.HttpServlet {m05bFileLog miLog = new m05bFileLog();
/**
 * Process incoming HTTP POST requests
 *
 * @param request Object that encapsulates the request to the servlet
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
	// insert code to initialize the servlet here

}
/**
 * Process incoming requests for information
 *
 * @param request Object that encapsulates the request to the servlet
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

       //String sNombre;
       String sValor="";
       String ArrayLista="";
       String sMatricula="";

       try  {	
       		HttpSession session = request.getSession(false);
		    m05bVehiculos vehiculo = (m05bVehiculos)session.getAttribute("m05bVehiculos");
			ArrayLista=request.getParameter("arrayVehiculos");
		    sMatricula = request.getParameter("Matricula").toUpperCase();
			
			String delimitador= ",";
			StringTokenizer st = new StringTokenizer(ArrayLista,",");
			
		
			//"FMatriculacion"
			    if (st.hasMoreTokens()) { 
				      sValor=(String)st.nextToken();
				      if (sValor=="#") {
				          sValor="";
				      }
				      vehiculo.setVeh_fmatric(sValor);
                }
			//"FAlta"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
				    if (sValor=="#") {
				          sValor="";
				    }
					vehiculo.setVeh_falta(sValor);
	             }
			//"FBaja"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
				    if (sValor=="#") {
				          sValor="";
				    }
					vehiculo.setVeh_fbaja(sValor);
	             }
			//"FecKmAct"
			    if (st.hasMoreTokens()) { 
     			    sValor=(String)st.nextToken();
	    			vehiculo.setVeh_fkmact(sValor);
                }
			//"CRango"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_rango(sValor);
                }
			//"Situacion"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_situacion(sValor);
	            }
			//"KmActuales"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_kmact(sValor);
                }
			//"Modelo"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_modelo(sValor);
                }
			//"Marca"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_marca(sValor);
                }
			//"Dpto"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_coddpto(sValor);
                }
			//"DesDpto"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_desdpto(sValor);
                }
				
			//"Precio"
			    if (st.hasMoreTokens()) { 
				    sValor=(String)st.nextToken();
					vehiculo.setVeh_precio(sValor);
				}


	        session.setAttribute("m05bVehiculos",vehiculo);
	        
    }  catch(Throwable theException) {
		// uncomment the following line when unexpected exceptions
		// are occuring to aid in debugging the problem.
		miLog.addTraza(theException);
		try {
			response.sendRedirect("m05bError.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			miLog.addTraza(e);
		}
	}
}
}