Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-02-2017
Avatar de noshy
noshy noshy is offline
Miembro
 
Registrado: jul 2003
Posts: 139
Poder: 21
noshy Va por buen camino
Código Delphi [-]
begin
  //Recibimos la cadena
  try
    vDespDatoRec := AContext.Connection.IOHandler.ReadLn();
  except
    Exit;
  end;

  if vDespDatoRec.Length < 5 then
  begin
    Exit;
  end;

  //Mostramos la cadena en el log
  logInt(vDespDatoRec,1);


  //Verificamos el tipo de campo que manda el JSON
  vDespTipoDato := 0; //Por defecto tipo de dato 0 (nada)

  //Mensaje de error por defecto en blanco
  vDespMsgError := '';


  vDespJSONDato := TlkJSON.ParseText(vDespDatoRec) as TlkJSONobject;
  try
    try
      vDespUsuario  := vartostr(vDespJSONDato.Field['login'].Field['user'].Value);
      vDespTipoDato := 1; //login
    except

    end;

    try
      vDespLoginVersion := vartostr(vDespJSONDato.Field['login'].Field['version'].Value);
    except
      vDespLoginVersion := '1';
    end;

    try
      vDespMovil := StrToInt(vartostr(vDespJSONDato.Field['posicion'].Field['movil'].Value));
      vDespTipoDato := 2; //Posicion
    except

    end;

    try
      vDespMovil   := StrToInt(vartostr(vDespJSONDato.Field['viajeaceptado'].Field['movil'].Value));
      vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajeaceptado'].Field['idviaje'].Value));
      vDespTipoDato := 3; //Viaje Aceptado
    except

    end;

    try
      vDespMovil   := StrToInt(vartostr(vDespJSONDato.Field['viajerechazado'].Field['movil'].Value));
      vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajerechazado'].Field['idviaje'].Value));
      vDespTipoDato := 4; //Viaje Rechazado
    except

    end;

    try
      vDespMovil   := StrToInt(vartostr(vDespJSONDato.Field['viajetimeout'].Field['movil'].Value));
      vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajetimeout'].Field['idviaje'].Value));
      vDespTipoDato := 5; //Viaje time out
    except

    end;

    try
      vDespMovil := StrToInt(vartostr(vDespJSONDato.Field['historialviajes'].Field['movil'].Value));
      vDespTipoDato := 6; //Historial de Viajes
    except

    end;

    try
      vDespMovil := StrToInt(vartostr(vDespJSONDato.Field['estadoqapqrx'].Field['movil'].Value));
      vDespTipoDato := 7; //Estado del Móvil
    except

    end;

  finally
    vDespJSONDato.Free;
  end;


  //Si no trae algun dato salimos de la funcion
  if vDespTipoDato = 0  then
  begin
    Exit;
  end;


  //Procesamos los datos
  case vDespTipoDato of
  1: begin  //LOGIN
        //Armamos el JSON para enviar como respuesta
        vDespJSONRespuestaLogin  := TlkJSONobject.Create;
        try
          //Chequeamos el login y guardamos el resultado
          vDespRespLogin := LoginInt(vDespDatoRec);

          //Control de Version segun Config
          if vDespConfig_ControlVersion then
          begin
            try
              if StrToFloat(vDespLoginVersion) < vDespConfig_VersionActual then
              begin
                vDespRespLogin := 9;
                vDespMsgError := 'Esta utilizando una version obsoleta. Debe Actualizar la App...';
              end;
            except
              vDespRespLogin := 0;
            end;
          end;

          //Controlamos si hay otro usuario logueado
          {if LoginOtroUsuario(UsuarioMovil(vUsuario)) then
          begin
            vRespLogin := 9;
            vMsgError := 'Existe otro Usuario Logueado en el mismo Movil...';
          end;   }

          //permiso a la aplicacion
          vDespJSONRespuestaLogin.Add('permiso'          , IntToStr(vDespRespLogin) );
          //Config (segundos para el time out)
          vDespJSONRespuestaLogin.Add('segTimeOut'       , IntToStr(vDespConfig_AutoTimeOut) );       //armar la funcion con el setup
          vDespJSONRespuestaLogin.Add('movil'            , IntToStr(UsuarioMovilInt(vDespUsuario)) ); //enviamos el movil del usuario logueado
          vDespJSONRespuestaLogin.Add('intervaloreporte' , IntToStr(vDespConfig_IntervaloReporte) );  //Intervalo en seg para el reporte
          vDespJSONRespuestaLogin.Add('segfinalizarviaje', IntToStr(vDespConfig_FinalizarViaje) );    //Intervalo en seg para el reporte
          vDespJSONRespuestaLogin.Add('msgerror'         , vDespMsgError);                            //Intervalo en seg para el reporte
          //Enviamos el JSOn con la respuesta
          AContext.Connection.IOHandler.WriteLn(TlkJSON.GenerateText(vDespJSONRespuestaLogin));
          Log('->'+vDespUsuario+' '+TlkJSON.GenerateText(vDespJSONRespuestaLogin),1);
        finally
          FreeAndNil(vDespJSONRespuestaLogin);
        end;
     end;
  2: begin //POSICION
        //Guardamos posicion segun Config
        if vDespConfig_GuardarPosicion then
        begin
          if not PosicionInt(vDespDatoRec) then
          begin
            logInt('Error en Guardar Posicion ',0);
          end;
        end;

        vDespAuxS := '';

        //Enviamos Viajes segun Config
        if vDespConfig_EnviarViajes then
        begin
          vDespAuxS := ControlInt(vDespMovil); //VERIFICA SI TIENE VIAJE ASIGNADO
          if Length(vDespAuxS) = 0 then
          begin
            vDespAuxS := ControlQTAInt(vDespMovil); //VERIFICA SI TIENE VIAJE QTA
          end;
        end;

        if Length(vDespAuxS) = 0 then
        begin
          vDespAuxS := '{}';
        end;

        //Enviamos el JSOn con la respuesta
        AContext.Connection.IOHandler.WriteLn(vDespAuxS);

        if vDespAuxS.Length > 2 then
          Log('Viaje -> '+IntToStr(vDespMovil)+' -> '+vDespAuxS,2);
     end;
  3: begin //VIAJE ACEPTADO - QTH FINAL
       //Armamos el JSON para enviar EL QTH FINAL como respuesta
       vDespJSONRespuestaFinal  := TlkJSONobject.Create;
       try
         //vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajeaceptado'].Field['idviaje'].Value));
         vDespIdViajeEnUso := idviajeenusoInt(vDespIdViaje);
         if vDespIdViajeEnUso > 0 then
         begin
           //vDomicilio := Trim(PendienteCalle(vIdViajeEnUso))+' '+IntToStr(PendienteAltura(vIdViajeEnUso))+' '+PendientePisoDpto(vIdViajeEnUso);
           vDespDomicilio := ArmarDomicilioInt(vDespIdViajeEnUso);
           vDespObservaciones := Trim(PendienteInfoTmpInt(vDespIdViajeEnUso))+' '+trim(PendienteObservacionesInt(vDespIdViajeEnUso));
           vDespViajeLat := Trim(PendienteLatInt(vDespIdViajeEnUso));
           vDespViajeLng := Trim(PendienteLngInt(vDespIdViajeEnUso));
         end
         else
         begin
           vDespDomicilio := 'VIAJE CANCELADO';
           vDespObservaciones := '';
           vDespViajeLat := '';
           vDespViajeLng := '';
         end;

         //DATOS DEL VIAJE
         vDespJSONRespuestaFinal.Add('domicilio'    , vDespDomicilio);
         vDespJSONRespuestaFinal.Add('observaciones', vDespObservaciones);
         vDespJSONRespuestaFinal.Add('lat', vDespViajeLat);
         vDespJSONRespuestaFinal.Add('lng', vDespViajeLng);
         vDespJSONRespuestaFinal.Add('idviaje', IntToStr(vDespIdViaje));

         //Enviamos el JSOn con la respuesta
         AContext.Connection.IOHandler.WriteLn(TlkJSON.GenerateText(vDespJSONRespuestaFinal));
         logInt('Viaje Aceptado -> '+IntToStr(vDespMovil)+' -> '+TlkJSON.GenerateText(vDespJSONRespuestaFinal),2);

         //Marcamos el viaje como aceptado
         DatoViajesInt(True,1, vDespIdViaje);   //MARCAMOS EL VIAJE COMO ACEPTADO
       finally
         FreeAndnil(vDespJSONRespuestaFinal);
       end;
     end;
  4: begin //VIAJE RECHAZADO
       //vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajerechazado'].Field['idviaje'].Value));
       vDespIdViajeEnUso := idviajeenusoInt(vDespIdViaje);

       //Marcamos el viaje como rechazado
       DatoViajesInt(True,2, vDespIdViaje);   //MARCAMOS EL VIAJE COMO RECHAZADO

       logInt('Viaje Rechazado -> '+IntToStr(vDespMovil) ,2);
     end;
  5: begin //VIAJE TIME OUT
       //vDespIdViaje := StrToInt(vartostr(vDespJSONDato.Field['viajetimeout'].Field['idviaje'].Value));
       vDespIdViajeEnUso := idviajeenusoInt(vDespIdViaje);

       //Marcamos el viaje como timeout
       DatoViajesInt(True,3, vDespIdViaje);   //MARCAMOS EL VIAJE COMO TIME OUT

       logInt('Viaje TimeOut -> '+IntToStr(vDespMovil) ,2);
     end;
  6: begin //HISTORIAL DE VIAJES
       vDespRespS := ViajesInt(vDespMovil);
       //Log('--> '+vRespS);
       AContext.Connection.IOHandler.WriteLn(vDespRespS);
     end;
  7: begin //ESTADO QAP / QRX DELMOVIL
       vDespRespS := ValidarMovilQRXInt(vDespMovil);
       AContext.Connection.IOHandler.WriteLn(vDespRespS)
     end;
  else
    begin
      LogInt('No trajo dato alguno... ',0)
    end;
  end;


  //---------------------------------------------------------------------------

end;
__________________
\_--> NoShY <--_/
Responder Con Cita
  #2  
Antiguo 07-02-2017
Avatar de noshy
noshy noshy is offline
Miembro
 
Registrado: jul 2003
Posts: 139
Poder: 21
noshy Va por buen camino
El codigo de arriba es el codigo ya limpio de todas las pruebas con try / except, por si alguien lo quiere revisar.
__________________
\_--> NoShY <--_/
Responder Con Cita
  #3  
Antiguo 07-02-2017
Reasen Reasen is offline
Miembro
NULL
 
Registrado: dic 2015
Ubicación: Barcelona
Posts: 140
Poder: 9
Reasen Va por buen camino
Prueba con MadExcept lo puedes usar gratis mientras no sea para fines comerciales.
Responder Con Cita
  #4  
Antiguo 08-02-2017
Avatar de noshy
noshy noshy is offline
Miembro
 
Registrado: jul 2003
Posts: 139
Poder: 21
noshy Va por buen camino
Cita:
Empezado por Reasen Ver Mensaje
Prueba con MadExcept lo puedes usar gratis mientras no sea para fines comerciales.

gracias, lo probare!!!
__________________
\_--> NoShY <--_/
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
no me detecta teclado numero Rofocale Varios 4 20-06-2011 23:00:14
BDS 2006 no detecta el IIS 7 en Win Vista ozrics Windows 0 17-06-2007 04:19:45
Software k detecta hardware Mrcl Debates 2 03-01-2007 22:07:58
la función SetSchemaInfo no detecta los índices amezeta32 Conexión con bases de datos 1 29-08-2006 22:51:53
¿Cua es el error que me detecta???? gandalf_27 C++ Builder 1 27-04-2006 19:57:44


La franja horaria es GMT +2. Ahora son las 02:23:09.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi