Sub ObtieneUpdTablas
Dim j As HttpJob
Dim estado As String
j.Initialize("", Me) 'name is empty as it is no longer needed
j.download2(ModConn.Url_php_mysql("UPDTABLAS"), Array As String ("REQUEST_METHOD", "GET_UPDTABLA", "USER_ID", ModConn.IMEI.GetDeviceId))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
'The result is a json string. We parse it and log the fields.
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim quotes As List = jp.NextArray
For Each quot As Map In quotes
estado = quot.Get("estado")
If estado <> 2 Then
If estado == "null" Then
'Log("Nombre Tabla: "".Get("TABLE_NAME"))
'Log("Fecha Tabla: "".Get("UPDATE_TIME"))
ComparaFecha(quot.Get("TABLE_NAME"), quot.Get("UPDATE_TIME"))
End If
Else
ToastMessageShow(quot.Get("mensaje"), False)
Log(quot.Get("mensaje"))
End If
Next
End If
j.Release
End Sub
Sub ComparaFecha(Tabla As String, Fecha As String)
Dim TablaName As String
ModConn.c = ModConn.s.ExecQuery("SELECT TABLE_NAME FROM upd_tablas WHERE TABLE_NAME = '"& Tabla &"' AND UPDATE_TIME <> '"& Fecha &"';")
If ModConn.c.RowCount <> 0 Then
For i = 0 To ModConn.c.RowCount-1
ModConn.c.Position = i
TablaName = ModConn.c.GetString("TABLE_NAME")
Next
End If
ModConn.c.Close
Select TablaName
Case "materiales"
Log("Actualizar materiales")
ObtieneMateriales(Fecha)
Case "mecanico"
Log("Actualizar mecanicos")
ObtieneMecanicos(Fecha)
Case "tipo_falla"
Log("Actualizar tipos de fallas")
ObtieneTpfalla(Fecha)
Case "tipos_eventos"
Log("Actualizar tipos de eventos")
ObtieneTiposEventos(Fecha)
Case "ubicacion_falla"
Log("Actualizar ubicacion falla")
ObtieneUbFalla(Fecha)
Case Else
Log("No hay tablas para actualizar.")
End Select
End Sub
Sub ObtieneTiposEventos (FechaServer As String)
Dim j As HttpJob
Dim estado As String
j.Initialize("", Me) 'name is empty as it is no longer needed
j.download2(ModConn.Url_php_mysql("TPEVENTOS"), Array As String ("REQUEST_METHOD", "GET_TPEVENTOS", "USER_ID", ModConn.IMEI.GetDeviceId))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
'The result is a json string. We parse it and log the fields.
Dim jp As JSONParser
jp.Initialize(j.GetString)
Dim quotes As List = jp.NextArray
ModConn.s.ExecNonQuery("DELETE FROM tipos_eventos;")
For Each quot As Map In quotes
estado = quot.Get("estado")
If estado <> 2 Then
If estado == "null" Then
ModConn.s.ExecNonQuery2("INSERT INTO tipos_eventos VALUES(?,?)", _
Array As String(quot.Get("id_tipoevento"),quot.Get("evento")))
End If
Else
ToastMessageShow(quot.Get("mensaje"), False)
Log(quot.Get("mensaje"))
End If
Next
ModConn.s.ExecNonQuery2("UPDATE upd_tablas SET UPDATE_TIME = ? WHERE TABLE_NAME = 'tipos_eventos';", _
Array As Object(FechaServer))
Log("tipos de eventos actualizados.")
End If
j.Release
End Sub