Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim latitude, longitude, nome, dt, str, cod As String
Dim i As Int
Dim SQL1 As SQL
End Sub
Sub Service_Create
SQL1.Initialize(File.DirDefaultExternal, "bd.db", True)
End Sub
Sub Service_Start (StartingIntent As Intent)
Main.tem_lastcall = False //
Dim rs As Cursor
rs = SQL1.ExecQuery("SELECT * FROM last_call")
If rs.RowCount <= 0 Then
Main.tem_lastcall = False // FOR THE PROGRAM TO KNOW THAT THERE IS NO REGISTERS LEFT IN THE DATABASE
StopService("")
Else
grava_lastcall_remoto // CALL THE SUBROUTINE
End If
rs.Close
End Sub
Sub grava_lastcall_remoto
i = i + 1
Dim rs As Cursor
rs = SQL1.ExecQuery ("SELECT * FROM last_call")
If rs.RowCount > 0 Then
rs.Position = 0
latitude = rs.GetString("latitude")
longitude = rs.GetString("longitude")
nome = rs.GetString("operador")
cod = rs.GetString("cod")
DateTime.DateFormat = "dd/MM/yyyy"
dt = DateTime.date ( rs.GetString("data") )
dt = dt & "%20"
dt = dt & DateTime.Time ( rs.GetString("data") )
str = "latitude=" & latitude & "&longitude=" & longitude & "&operador=" & nome & "&data=" & dt & "&cod=" & cod & "&tag_comboio=CB1"
Dim job As HttpJob
job.Initialize("job_lastcall"&i, Me)
job.PostString(Main.IP & "cb_remoto_lastcall.asp?",str)
Else
StopService("")
End If
rs.Close
End Sub
Sub JobDone (job As HttpJob)
If job.JobName = "job_lastcall"&i Then
If job.Success = True Then
Log ("index " & i)
Log("getstring " & job.GetString)
Dim codx = job.GetString
job.Release
SQL1.ExecNonQuery("DELETE FROM last_call WHERE cod = '" & codx & "'")
grava_lastcall_remoto // CALL THE SUBROUTINE AGAIN THAT CALLS THE JOB WITH A NEW REGISTER
Else
Main.server_ok = False
job.Release
Main.tem_lastcall = True
i = 0
StopService("")
End If
End If
End Sub
Sub Service_Destroy
CancelScheduledService ("")
StopService("")
End Sub