Hello, good morning everyone
Estous making an application that will download via webservice the data of a remote bank to a local database in the mobile.
I am launching Job to do this inclusion but I would wait for the first Job to finish and then start the next Job. It is possible? In other words, I would like the App to be stopped by finishing the first job and then continuing to the next ones. Or a way to stop until all the jobs are completed.
In other words, I would like the user to be stopped until the two or more tables are updated when necessary.
Estous making an application that will download via webservice the data of a remote bank to a local database in the mobile.
I am launching Job to do this inclusion but I would wait for the first Job to finish and then start the next Job. It is possible? In other words, I would like the App to be stopped by finishing the first job and then continuing to the next ones. Or a way to stop until all the jobs are completed.
B4X:
Sub atualizarTabelasApoio(bForce As Boolean)
Dim rec As List
rec.Initialize
DBUtils.SQL.BeginTransaction
Try
ProgressDialogShow2("Sincronizando tabelas com a nuvem...", False )
If bForce Then
DBUtils.SQL.ExecNonQuery( "DELETE FROM Deposito" )
DBUtils.SQL.ExecNonQuery( "DELETE FROM Empresa" )
End If
' verifica se a tabela de deposito tem registro
rec = DBUtils.ExecuteMemoryTable(DBUtils.SQL, "SELECT ID FROM Deposito", Null, 0)
Log("Rec Deposito local: " & rec.Size )
If rec.Size = 0 Then
sincronizeTabela( SINCRONIZE_DEPOSITO )
End If
' verifica se a tabela de empresas tem registro
rec = DBUtils.ExecuteMemoryTable(DBUtils.SQL, "SELECT ID FROM Empresa", Null, 0)
Log("Rec Empresa local: " & rec.Size )
If rec.Size = 0 Then
sincronizeTabela( SINCRONIZE_EMPRESA )
End If
DBUtils.SQL.TransactionSuccessful
Catch
ProgressDialogHide
ToastMessageShow( "ERRO: " & LastException.Message, True)
End Try
DBUtils.SQL.EndTransaction
ProgressDialogHide
End Sub
Sub sincronizeTabela(JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
Select Case JobName
Case SINCRONIZE_DEPOSITO
job.PostString( "https://www./xxx.php", _
"SELECT id, descricao FROM estoque_deposito ORDER BY id" )
job.co
Case SINCRONIZE_EMPRESA
job.PostString( "https://www./xxx.php", _
"SELECT id, razaosocial, fantasia, apelido, depositoid FROM empresa WHERE (Excluido=False) ORDER BY id" )
End Select
End Sub
Sub JobDone(Job As HttpJob)
Dim parser As JSONParser
Dim res As String
Dim l As List
ProgressDialogHide
Try
If Job.Success Then
res = Job.GetString
parser.Initialize(res)
Log("Resposta do servidor: " & res)
' transforma em uma lista
l = parser.NextArray
Log("Num Rec:" & l.Size )
If l.Size > 0 Then
Select Job.JobName
Case SINCRONIZE_DEPOSITO
DBUtils.InsertMaps( DBUtils.SQL, "Deposito", l)
ToastMessageShow("Tabela de Depósito concluída...", False)
Case SINCRONIZE_EMPRESA
DBUtils.InsertMaps( DBUtils.SQL, "Empresa", l)
ToastMessageShow("Tabela de Depósito concluída...", False)
End Select
End If
Else
Log(Job.ErrorMessage)
ToastMessageShow("Erro: " & Job.ErrorMessage, True)
End If
Job.Release
Catch
Log(LastException)
ToastMessageShow("Erro: " & LastException, True)
End Try
End Sub
In other words, I would like the user to be stopped until the two or more tables are updated when necessary.