mirror of
https://github.com/KeymonSoft/Kelloggs_v4.git
synced 2026-04-17 18:26:11 +00:00
9/11/23 - Código para Respaldo Diario en Android 10.
- En Android 10, el código para ManageExternalStorage no funciona, asi que si se detecta que el directorio (skmt) no se creo, se manda la BD al directorio seguro en la sdcard (sdcard/Android/data/kelloggs ...)
This commit is contained in:
@@ -330,15 +330,21 @@ End Sub
|
||||
|
||||
Sub B4XPage_Appear
|
||||
MES1.Initialize(Me, "MES1")
|
||||
Log("SDK: " & device.SdkVersion)
|
||||
' Get the device SDK version
|
||||
Dim SdkVersion As Int = device.SdkVersion
|
||||
' Choose which permission to request in order to access external storgage
|
||||
If SdkVersion < 30 Then
|
||||
' Log("SDK = " & SdkVersion & " : Requesting WRITE_EXTERNAL_STORAGE permission")
|
||||
Log("SDK = " & SdkVersion & " : Requesting WRITE_EXTERNAL_STORAGE permission")
|
||||
Dim rp As RuntimePermissions
|
||||
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) ' Implicit read capability if granted
|
||||
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
||||
' Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${Result}"$)
|
||||
Wait For B4XPage_PermissionResult (Permission As String, ResultY As Boolean)
|
||||
Log($"PERMISSION_WRITE_EXTERNAL_STORAGE = ${ResultY}"$)
|
||||
Log("SDK = " & SdkVersion & " : Requesting READ_EXTERNAL_STORAGE permission")
|
||||
Dim rp As RuntimePermissions
|
||||
rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE) ' Implicit read capability if granted
|
||||
Wait For B4XPage_PermissionResult (Permission As String, ResultX As Boolean)
|
||||
Log($"PERMISSION_READ_EXTERNAL_STORAGE = ${ResultX}"$)
|
||||
Else
|
||||
' Log("SDK = " & SdkVersion & " : Requesting MANAGE_EXTERNAL_STORAGE permission")
|
||||
' Log("On Entry MANAGE_EXTERNAL_STORAGE = " & MES1.HasPermission)
|
||||
@@ -453,10 +459,11 @@ End Sub
|
||||
|
||||
Sub JobDone(Job As HttpJob)
|
||||
Log("JOBDONE MAINPAGE")
|
||||
If Job.Tag.As(String).StartsWith("_KMS_") Then Job.tag = Job.Tag.As(String).SubString(16)
|
||||
If Job.Success = False Then
|
||||
ToastMessageShow("Error: " & Job.ErrorMessage, True)
|
||||
Else
|
||||
If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
' If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim result As DBResult = reqManager.HandleJob(Job)
|
||||
If result.Tag = "version" Then 'query tag
|
||||
|
||||
@@ -15,7 +15,7 @@ Sub Class_Globals
|
||||
Dim t1 As Timer
|
||||
Dim t2 As Timer
|
||||
Private t3 As Timer
|
||||
Dim inicioContador As String
|
||||
Dim inicioContador As Double
|
||||
|
||||
'//Globals
|
||||
Dim trabajar As Button
|
||||
@@ -626,6 +626,7 @@ Sub cargar_Click
|
||||
|
||||
DateTime.TimeFormat = "HHmmss"
|
||||
inicioContador = DateTime.Now
|
||||
reqManager.trackInit
|
||||
|
||||
cmd.Initialize
|
||||
cmd.Name = "SELECT_HIST_ENCUESTA_KELL"
|
||||
@@ -635,7 +636,6 @@ Sub cargar_Click
|
||||
cmd.Initialize
|
||||
cmd.Name = "SELECT_EXHIBIDOR_RUTA_KELL"
|
||||
cmd.Parameters = Array As Object( e_ruta.text )
|
||||
If logger Then Log(e_ruta.TEXT)
|
||||
reqManager.ExecuteQuery(cmd , 0, "exhibidores")
|
||||
|
||||
cmd.Initialize 'Para traer la contraseña del candado de "FIN DIA"
|
||||
@@ -856,13 +856,7 @@ End Sub
|
||||
|
||||
Sub JobDone(Job As HttpJob)
|
||||
Log("JOBDONE PRINCIPAL")
|
||||
If reqManager.reqsList.IsInitialized Then 'Si tenemos lista de requests, la procesamos.
|
||||
If reqManager.reqsList.IndexOf(Job.tag) <> -1 Then
|
||||
reqManager.reqsList.RemoveAt(reqManager.reqsList.IndexOf(Job.tag))
|
||||
' LogColor($">>>>>> Quitamos ${Job.tag}"$, Colors.Blue)
|
||||
End If
|
||||
LogColor(">>>>>> " & reqManager.reqsList.Size & " - " & reqManager.reqsList, Colors.Blue)
|
||||
End If
|
||||
reqManager.trackNext(Job)
|
||||
If Not(Job.Success) Then
|
||||
LogColor("Error: " & Job.tag & " : " & Job.ErrorMessage, Colors.red)
|
||||
If Job.ErrorMessage = "STREAM" Then
|
||||
@@ -879,7 +873,7 @@ Sub JobDone(Job As HttpJob)
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
' If logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim RESULT As DBResult = reqManager.HandleJob(Job)
|
||||
If RESULT.Tag = "kmt_datos" Then 'query tag
|
||||
@@ -1564,7 +1558,7 @@ Sub JobDone(Job As HttpJob)
|
||||
If RESULT.Rows.Size = 0 Then ToastMessageShow("No hay ruta para ese usuario", True)
|
||||
For Each records() As Object In RESULT.Rows
|
||||
Dim VALIDO As String = records(RESULT.Columns.Get("VALIDO"))
|
||||
if starter.Logger then Log("|"&VALIDO&"|")
|
||||
If Starter.Logger Then Log("|"&VALIDO&"|")
|
||||
' If Logger Then Log(records(RESULT.Columns.Get("CAT_RU_CATEGORIA")))
|
||||
Starter.rutaTipo = records(RESULT.Columns.Get("CAT_RU_CATEGORIA")) 'Traemos el tipo de ruta para que cuando sean foraneas no carguen la carta porte todos los dias.
|
||||
If Starter.Logger Then Log($"========= TIPO RUTA = ${Starter.rutaTipo}"$)
|
||||
@@ -1761,7 +1755,7 @@ Sub JobDone(Job As HttpJob)
|
||||
' ToastMessageShow("LISTA DE PRECIOS OK LISTA DE PRECIOS OK", True)
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
'Candado Fin Dia
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim RESULT As DBResult = reqManager.HandleJob(Job)
|
||||
@@ -1915,6 +1909,14 @@ Sub JobDone(Job As HttpJob)
|
||||
|
||||
If PB2.Progress = 100 Then S_CP.Text = "LISTO"
|
||||
Job.Release
|
||||
Log($"tiempo Request "${Job.Tag}": ${((reqManager.inicioJobDone - reqManager.inicioRequest)/1000)}"$)
|
||||
Log($"tiempo JobDone "${Job.Tag}": ${((DateTime.Now - reqManager.inicioJobDone)/1000)}"$)
|
||||
Log($"tiempo Total "${Job.Tag}": ${((DateTime.Now - inicioContador)/1000)}"$)
|
||||
|
||||
Log(reqManager.requestTimes(Job.Tag))
|
||||
|
||||
' Log($"tiempo Total "${Job.Tag}": ${((DateTime.Now - inicioContador)/1000)}"$)
|
||||
' reqManager.PrintTable(RESULT)
|
||||
End Sub
|
||||
|
||||
Private Sub B4XPage_CloseRequest As ResumableSub
|
||||
@@ -1964,7 +1966,7 @@ Sub connecta_Click
|
||||
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then Log("Tenemos permisos de bluetooth.")
|
||||
Log($"Resultado del CheckAndRequest: ${Result}"$)
|
||||
Log("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
' Log("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
|
||||
' c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("RUTA"))
|
||||
' c.Position =0
|
||||
@@ -1978,7 +1980,7 @@ Sub connecta_Click
|
||||
Dim m As Matcher = Regex.Matcher("\d+", e_ruta.Text) 'Buscamos numeros en el campo de la ruta
|
||||
If m.Find Then e_ruta.Text = m.Match ' Si tiene numeros, solo nos quedamos con ellos.
|
||||
If e_ruta.Text.Length > 6 Then e_ruta.Text = e_ruta.Text.SubString2(0,6) ' Si tiene mas de 6 numeros solo tomamos los primeros 6
|
||||
If logger Then Log(e_ruta.Text)
|
||||
' If logger Then Log(e_ruta.Text)
|
||||
c=Starter.skmt.ExecQuery("select usuario from usuarioa")
|
||||
c.Position = 0
|
||||
usuario = c.GetString("USUARIO")
|
||||
@@ -1993,6 +1995,9 @@ Sub connecta_Click
|
||||
' End If
|
||||
' Log("Terminamos permisos")
|
||||
conn = "1"
|
||||
|
||||
reqManager.trackInit
|
||||
|
||||
Dim cmd As DBCommand
|
||||
cmd.Initialize
|
||||
cmd.Name = "select_version_KELL"
|
||||
|
||||
148
B4A/C_Subs.bas
148
B4A/C_Subs.bas
@@ -277,6 +277,21 @@ Sub panelVisible(panel As Panel, top As Int, left As Int) 'ignore
|
||||
panel.Left = left
|
||||
End Sub
|
||||
|
||||
'Oculta el panel especificado y lo manda al fondo
|
||||
Sub panelOculto(panel As Panel) 'ignore
|
||||
panel.SendToBack
|
||||
panel.Visible = False
|
||||
End Sub
|
||||
|
||||
'Modifica el ancho y alto de un panel dado con el ancho y alto proporcionados y los pone en top 0 y left 0.
|
||||
Sub panelAnchoAlto(p As Panel, w As Int, h As Int) 'ignore
|
||||
' If Starter.logger Then Log($"panel:${p}, alncho=${w}, alto=${h}"$)
|
||||
p.Top = 0
|
||||
p.Left = 0
|
||||
p.Width = w
|
||||
p.Height = h
|
||||
End Sub
|
||||
|
||||
'Centra una etiqueta dentro de un elemento superior.
|
||||
Sub centraEtiqueta(elemento As Label, anchoElementoSuperior As Int) 'ignore
|
||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||
@@ -297,6 +312,11 @@ Sub centraProgressBar(elemento As ProgressBar, anchoElementoSuperior As Int) 'ig
|
||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||
End Sub
|
||||
|
||||
'Centra un editText dentro de un elemento superior.
|
||||
Sub centraEditText(elemento As EditText, anchoElementoSuperior As Int) 'ignore
|
||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||
End Sub
|
||||
|
||||
'Regresa el usuario de la tabla USUARIOA si es que existe, si no existe, regresa "SinUsuario".
|
||||
Sub buscaDBUsuario As String 'ignore
|
||||
Private c As Cursor
|
||||
@@ -333,7 +353,7 @@ Sub logJobDoneResultados(resultado As DBResult) 'ignore
|
||||
End Sub
|
||||
|
||||
'Regresa la base de datos especificada ya inicializada.
|
||||
Sub inicializaBD(ruta As String, BDName As String) As SQL
|
||||
Sub inicializaBD(ruta As String, BDName As String) As SQL 'ignore
|
||||
Dim skmt As SQL
|
||||
If File.Exists(ruta, BDName) = False Then
|
||||
File.Copy(File.DirAssets, BDName, ruta, BDName)
|
||||
@@ -398,7 +418,7 @@ Sub traeTimeoutDeBD As String 'ignore
|
||||
End Sub
|
||||
|
||||
'Crea una notificación con el "body" dado y regresa el objeto.
|
||||
Sub CreateNotification (Body As String) As Notification
|
||||
Sub CreateNotification (Body As String) As Notification 'ignore
|
||||
Dim notification As Notification
|
||||
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||
notification.Icon = "icon"
|
||||
@@ -433,4 +453,128 @@ Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'i
|
||||
notification.Notify(id)
|
||||
' Log("notiLowReturn SetInfo")
|
||||
Return notification
|
||||
End Sub
|
||||
|
||||
'Guarda el nombre de la pagina en base de datos la muestra.
|
||||
Sub iniciaActividad(ia As String) 'ignore
|
||||
If ia <> "" And ia <> Null Then
|
||||
' If Starter.logger Then LogColor($"Guardamos en BD '${ia}'"$, Colors.Yellow)
|
||||
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("ULTIMOMODULO"))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("ULTIMOMODULO", ia))
|
||||
B4XPages.ShowPage(ia)
|
||||
' If Starter.logger Then LogColor("Iniciamos --> " & ia, Colors.Blue)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Guarda el nombre de la actividad en base de datos e inicia la actividad.
|
||||
Sub iniciaActividad2(ia As String) 'ignore
|
||||
' if starter.logger then LogColor($"Guardamos en BD '${ia}'"$, Colors.Yellow)
|
||||
Starter.skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("ULTIMOMODULO"))
|
||||
Starter.skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("ULTIMOMODULO", ia))
|
||||
StartActivity(ia)
|
||||
' B4XPages.ShowPage(ia)
|
||||
' if starter.logger then LogColor("Iniciamos --> " & ia, Colors.Blue)
|
||||
End Sub
|
||||
|
||||
'Cierra todas las actividades y sale de la aplicacion (Android 4.1+ - API 16+)
|
||||
Sub cierraActividades 'ignore
|
||||
If Starter.logger Then Log("closing activities")
|
||||
Dim jo As JavaObject
|
||||
jo.InitializeContext
|
||||
jo.RunMethod("finishAffinity", Null)
|
||||
End Sub
|
||||
|
||||
'Revisa que exista la BD y si es necesario crea algunas tablas dentro de ella
|
||||
Sub revisaBD 'ignore
|
||||
' if starter.logger then Log("subs.revisaBD")
|
||||
Starter.ruta = File.DirInternal
|
||||
If Not(File.Exists(Starter.ruta, "kmt.db")) Then File.Copy(File.DirAssets, "kmt.db", Starter.ruta, "kmt.db")
|
||||
If Not(Starter.skmt.IsInitialized) Then Starter.skmt.Initialize(Starter.ruta, "kmt.db", True)
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(fecha INTEGER, lat TEXT, lon TEXT)")
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS HIST_ENCUESTA2(HE_CLIENTE TEXT)")
|
||||
' Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS UUC(fecha INTEGER, lat TEXT, lon TEXT)") 'LastKnownLocation
|
||||
Starter.skmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS bitacora(fecha INTEGER, texto TEXT)") 'Bitacora
|
||||
Try 'Si no existe la columna CAT_CL_CATEGORIA la agregamos.
|
||||
Starter.skmt.ExecQuery("select count(CAT_CL_CATEGORIA) from kmt_info")
|
||||
Catch
|
||||
Try
|
||||
Starter.skmt.ExecNonQuery("ALTER TABLE kmt_info ADD COLUMN CAT_CL_CATEGORIA TEXT")
|
||||
Catch
|
||||
If Starter.logger Then LogColor("No pudimos agregar la columna CAT_CL_CATEGORIA.", Colors.Red)
|
||||
If Starter.logger Then LogColor(LastException, Colors.Red)
|
||||
End Try
|
||||
End Try
|
||||
Try 'Si no existe la columna CAT_CL_SEGMENTO la agregamos.
|
||||
Starter.skmt.ExecQuery("select count(CAT_CL_SEGMENTO) from kmt_info")
|
||||
Catch
|
||||
Try
|
||||
Starter.skmt.ExecNonQuery("ALTER TABLE kmt_info ADD COLUMN CAT_CL_SEGMENTO TEXT")
|
||||
Catch
|
||||
If Starter.logger Then LogColor("No pudimos agregar la columna CAT_CL_SEGMENTO.", Colors.Red)
|
||||
If Starter.logger Then LogColor(LastException, Colors.Red)
|
||||
End Try
|
||||
End Try
|
||||
'Tabla para la bitacora de errores
|
||||
If Not(Starter.errorLog.IsInitialized) Then Starter.errorLog.Initialize(File.DirInternal, "errorLog.db", True)
|
||||
Starter.errorLog.ExecNonQuery("CREATE TABLE IF NOT EXISTS errores(fecha TEXT, error TEXT)")
|
||||
End Sub
|
||||
|
||||
'Regresa el dia de HOY como string, en español y mayusculas.
|
||||
Sub dameDiaSemana As String 'ignore
|
||||
Private ds As String = DateTime.GetDayOfWeek(DateTime.Now)
|
||||
If ds = "1" Then
|
||||
ds = "DOMINGO"
|
||||
else if ds = "2" Then
|
||||
ds = "LUNES"
|
||||
else if ds = "3" Then
|
||||
ds = "MARTES"
|
||||
else if ds = "4" Then
|
||||
ds = "MIERCOLES"
|
||||
else if ds = "5" Then
|
||||
ds = "JUEVES"
|
||||
else if ds = "6" Then
|
||||
ds = "VIERNES"
|
||||
Else
|
||||
ds = "SABADO"
|
||||
End If
|
||||
Return ds
|
||||
End Sub
|
||||
|
||||
'Regresa cuentos clientes fuera de frecuencia hay con venta.
|
||||
Sub dameClientesFueraDeFrecuencia As String 'ignore
|
||||
Private dia_visita As String = dameDiaSemana
|
||||
Private f As Cursor = Starter.skmt.ExecQuery("SELECT CAT_VA_VALOR as dia_visita FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = 'DIA_VISITA'")
|
||||
If f.RowCount > 0 Then
|
||||
f.Position=0
|
||||
dia_visita = f.GetString("dia_visita")
|
||||
End If
|
||||
' Log("-> "&dia_visita)
|
||||
f = Starter.skmt.ExecQuery("Select count(distinct PE_CLIENTE) as cff FROM kmt_info INNER JOIN PEDIDO ON kmt_info.CAT_CL_CODIGO = PEDIDO.PE_CLIENTE WHERE kmt_info.CAT_CL_DIAS_VISITA <> '"&dia_visita&"'")
|
||||
f.Position=0
|
||||
' Log(f.GetString("cff"))
|
||||
Private cff As String = f.GetString("cff")
|
||||
f.Close
|
||||
Return cff
|
||||
End Sub
|
||||
|
||||
'Regresa la ultima actividad guardada en base de datos.
|
||||
Sub traeUltimaActividadBD As String 'ignore
|
||||
' If Starter.logger Then LogColor("Buscamos ultima actividad en BD", Colors.Magenta)
|
||||
Private c As Cursor
|
||||
Private x As String
|
||||
c = Starter.skmt.ExecQuery("select CAT_VA_VALOR from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'ULTIMOMODULO'")
|
||||
If c.RowCount > 0 Then
|
||||
c.Position = 0
|
||||
x = c.GetString("CAT_VA_VALOR")
|
||||
' If Starter.logger Then Log("Encontramos: " & x)
|
||||
End If
|
||||
c.Close
|
||||
Return x
|
||||
End Sub
|
||||
|
||||
'En geocerca si mete la contraseña poner 0 en precision gps y si esta dentro de los 50 mts poner 1 y 2 para eventos que no lo ocupen
|
||||
'Mandar fecha de sync(sysdate)
|
||||
Sub bitacora(fechab As String, usuariob As String, almacenb As String, rutab As String, eventob As String, clienteb As String, iniciob As String, finb As String, latitudb As String, longitudb As String, precision As String, motivonoventa As String, motivonovisita As String) 'ignore
|
||||
Log("bitacora")
|
||||
Starter.skmt.ExecNonQuery($"INSERT INTO BITACORAGPS (fechab, usuariob , almacenb , rutab , eventob , clienteb , iniciob , finb , latitudb , longitudb , precision , motivonoventa , motivonovisita) VALUES ('${fechab}' ,'${usuariob}' , '${almacenb}' , '${rutab}' , '${eventob}' , '${clienteb}' , '${iniciob}' , '${finb}' , '${latitudb}' , '${longitudb}' , '${precision}' , '${motivonoventa}' , '${motivonovisita}')"$)
|
||||
End Sub
|
||||
@@ -16,7 +16,10 @@ Sub Class_Globals
|
||||
Private VERSION As Float = 0.9
|
||||
Private tempArray(1) As Object
|
||||
Dim jobTagAnterior As String = "" 'Mod por CHV - 211109
|
||||
Dim reqsList As List
|
||||
Dim reqsList, timesList As List
|
||||
Dim inicioRequest As Long 'ignore
|
||||
Dim inicioJobDone As Long 'ignore
|
||||
Dim inicioRequestMap, inicioJobDoneMap As Map
|
||||
End Sub
|
||||
|
||||
'Target - The module that handles JobDone (usually Me).
|
||||
@@ -24,7 +27,6 @@ End Sub
|
||||
Public Sub Initialize (Target As Object, ConnectorLink As String)
|
||||
mTarget = Target
|
||||
link = ConnectorLink
|
||||
reqsList.Initialize
|
||||
End Sub
|
||||
|
||||
'Sends a query request.
|
||||
@@ -34,8 +36,9 @@ End Sub
|
||||
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object)
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
If reqsList.IsInitialized Then reqsList.Add(Tag)
|
||||
Dim out2 As OutputStream = StartJob(j, ms, Tag)
|
||||
' If reqsList.IsInitialized Then reqsList.Add(Tag)
|
||||
' If timesList.IsInitialized Then timesList.Add(DateTime.now)
|
||||
|
||||
WriteObject(Command.Name, out2)
|
||||
WriteInt(Limit, out2)
|
||||
@@ -50,7 +53,7 @@ End Sub
|
||||
Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object)
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
Dim out2 As OutputStream = StartJob(j, ms, Tag)
|
||||
WriteInt(ListOfCommands.Size, out2)
|
||||
For Each Command As DBCommand In ListOfCommands
|
||||
WriteObject(Command.Name, out2)
|
||||
@@ -62,11 +65,15 @@ End Sub
|
||||
|
||||
'Similar to ExecuteBatch. Sends a single command.
|
||||
Public Sub ExecuteCommand(Command As DBCommand, Tag As Object)
|
||||
If reqsList.IsInitialized Then reqsList.Add(Tag)
|
||||
' If reqsList.IsInitialized Then reqsList.Add(Tag)
|
||||
' If timesList.IsInitialized Then timesList.Add(DateTime.now)
|
||||
ExecuteBatch(Array As DBCommand(Command), Tag)
|
||||
End Sub
|
||||
|
||||
Private Sub StartJob(j As HttpJob, MemoryStream As OutputStream, Tag As Object) As OutputStream
|
||||
' inicioRequest = DateTime.now
|
||||
If reqsList.IsInitialized Then reqsList.Add(Tag)
|
||||
If timesList.IsInitialized Then timesList.Add(DateTime.now)
|
||||
j.Initialize("DBRequest", mTarget)
|
||||
j.Tag = Tag
|
||||
MemoryStream.InitializeToBytesArray(0)
|
||||
@@ -190,7 +197,13 @@ End Sub
|
||||
|
||||
'Handles the Job result and returns a DBResult.
|
||||
Public Sub HandleJob(Job As HttpJob) As DBResult
|
||||
Dim start As Long = DateTime.Now 'ignore
|
||||
If jobTagAnterior <> Job.Tag Then
|
||||
' inicioJobDone = DateTime.Now 'ignore
|
||||
If inicioJobDoneMap.IsInitialized Then inicioJobDoneMap.Put(Job.Tag, DateTime.Now)
|
||||
' tiempos.Put(Job.taskId, CreateMap("inicioJobDone":inicioJobDone))
|
||||
' Log(tiempos)
|
||||
' Log("############# " & Job.taskId)
|
||||
End If
|
||||
Dim In As InputStream = Job.GetInputStream
|
||||
Dim cs As CompressedStreams
|
||||
In = cs.WrapInputStream(In, "gzip")
|
||||
@@ -201,8 +214,6 @@ Public Sub HandleJob(Job As HttpJob) As DBResult
|
||||
table.Columns.Initialize
|
||||
table.rows.Initialize
|
||||
table.Tag = Job.Tag
|
||||
If jobTagAnterior <> Job.Tag Then LogColor("HandleJob: '"&Job.Tag&"'", Colors.Blue) 'Mod por CHV - 211109
|
||||
jobTagAnterior = Job.Tag 'Mod por CHV - 211109
|
||||
If method = "query" Then
|
||||
Dim numberOfColumns As Int = ReadInt(In)
|
||||
For i = 0 To numberOfColumns - 1
|
||||
@@ -225,8 +236,13 @@ Public Sub HandleJob(Job As HttpJob) As DBResult
|
||||
End If
|
||||
In.Close
|
||||
' Log("HandleJob: " & (DateTime.Now - start))'Comentado por CHV - 211112
|
||||
If jobTagAnterior <> table.Tag Then
|
||||
LogColor("HandleJob: '"&table.Tag&"'" & " - Registros: " & table.Rows.Size, Colors.RGB(115, 0, 140)) 'Mod por CHV - 211109
|
||||
End If
|
||||
jobTagAnterior = table.Tag 'Mod por CHV - 211109
|
||||
Return table
|
||||
End Sub
|
||||
|
||||
'Reads a file and returns the file as a bytes array.
|
||||
Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
|
||||
Dim out As OutputStream
|
||||
@@ -236,6 +252,7 @@ Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
|
||||
out.Close
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
|
||||
'Converts an image to a bytes array (for BLOB fields).
|
||||
Public Sub ImageToBytes(Image As Bitmap) As Byte()
|
||||
Dim out As OutputStream
|
||||
@@ -244,6 +261,7 @@ Public Sub ImageToBytes(Image As Bitmap) As Byte()
|
||||
out.Close
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
|
||||
'Converts a bytes array to an image (for BLOB fields).
|
||||
Public Sub BytesToImage(bytes() As Byte) As Bitmap
|
||||
Dim In As InputStream
|
||||
@@ -252,6 +270,7 @@ Public Sub BytesToImage(bytes() As Byte) As Bitmap
|
||||
bmp.Initialize2(In)
|
||||
Return bmp
|
||||
End Sub
|
||||
|
||||
'Prints the table to the logs.
|
||||
Public Sub PrintTable(Table As DBResult)
|
||||
Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
|
||||
@@ -267,8 +286,58 @@ Public Sub PrintTable(Table As DBResult)
|
||||
For Each record As Object In row
|
||||
sb.Append(record).Append(TAB)
|
||||
Next
|
||||
ToastMessageShow(sb.ToString, True)
|
||||
Log(sb.ToString)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Sub requestTimes(tag As String) As Map 'ignore
|
||||
Private times As Map
|
||||
times.Initialize
|
||||
' Log("###### " & tag)
|
||||
' Log(reqsList.IsInitialized)
|
||||
If reqsList.IsInitialized Then
|
||||
' Log(reqsList)
|
||||
' Private pos As Int = reqsList.IndexOf(tag)
|
||||
If inicioRequestMap.ContainsKey(tag) Then
|
||||
inicioRequest = inicioRequestMap.Get(tag)
|
||||
' Log(">>>>>>> From inicioRequestMap")
|
||||
End If
|
||||
If inicioJobDoneMap.ContainsKey(tag) Then
|
||||
inicioJobDone = inicioJobDoneMap.Get(tag)
|
||||
' Log(">>>>>>> From inicioJobDoneMap")
|
||||
End If
|
||||
End If
|
||||
' Log($"${inicioJobDone} - ${inicioRequest}"$)
|
||||
Private requestTime As String = NumberFormat2(((inicioJobDone - inicioRequest) / 1000),1,5,0,False)
|
||||
Private JobDoneTime As String = NumberFormat2(((DateTime.Now - inicioJobDone) / 1000),1,5,0,False)
|
||||
times.Put("requestTime", requestTime)
|
||||
times.Put("jobDoneTime", JobDoneTime)
|
||||
times.Put("totalTime", NumberFormat2((JobDoneTime + requestTime),1,5,0,False))
|
||||
Return times
|
||||
End Sub
|
||||
|
||||
'Initializes request tracking
|
||||
Sub trackInit 'ignore
|
||||
Log(">>>>>>>>> TRACKINIT ")
|
||||
reqsList.Initialize
|
||||
timesList.Initialize
|
||||
inicioRequestMap.Initialize
|
||||
inicioJobDoneMap.Initialize
|
||||
End Sub
|
||||
|
||||
Sub trackNext(job As HttpJob)
|
||||
If reqsList.IsInitialized Then 'Si tenemos lista de requests, la procesamos.
|
||||
Private quitamos As String = ""
|
||||
If reqsList.IndexOf(job.tag) <> -1 Then
|
||||
Private pos As Int = reqsList.IndexOf(job.tag)
|
||||
If pos <> -1 Then
|
||||
inicioRequestMap.Put(job.Tag, timesList.Get(pos))
|
||||
reqsList.RemoveAt(pos)
|
||||
timesList.RemoveAt(pos)
|
||||
End If
|
||||
quitamos = $"Quitamos ${job.tag} - "$
|
||||
End If
|
||||
LogColor(">>>>>> Requests: " & reqsList.Size & " - " & quitamos & reqsList, Colors.Blue)
|
||||
LogColor(">>>>>> inicioRequestMap:" & inicioRequestMap.Size & " - " & inicioRequestMap, Colors.Magenta)
|
||||
End If
|
||||
End Sub
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -24,7 +24,6 @@ ModuleBookmarks29=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks30=
|
||||
ModuleBookmarks31=
|
||||
ModuleBookmarks32=
|
||||
ModuleBookmarks4=
|
||||
ModuleBookmarks5=
|
||||
ModuleBookmarks6=
|
||||
@@ -57,7 +56,6 @@ ModuleBreakpoints29=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints30=
|
||||
ModuleBreakpoints31=
|
||||
ModuleBreakpoints32=
|
||||
ModuleBreakpoints4=
|
||||
ModuleBreakpoints5=
|
||||
ModuleBreakpoints6=
|
||||
@@ -65,38 +63,37 @@ ModuleBreakpoints7=
|
||||
ModuleBreakpoints8=
|
||||
ModuleBreakpoints9=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=4
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes10=
|
||||
ModuleClosedNodes11=
|
||||
ModuleClosedNodes12=
|
||||
ModuleClosedNodes11=50,51,52
|
||||
ModuleClosedNodes12=1,3
|
||||
ModuleClosedNodes13=
|
||||
ModuleClosedNodes14=
|
||||
ModuleClosedNodes14=39,40,41,42,43,44
|
||||
ModuleClosedNodes15=
|
||||
ModuleClosedNodes16=
|
||||
ModuleClosedNodes17=
|
||||
ModuleClosedNodes18=9,10,11,12,13,15,16,17,18
|
||||
ModuleClosedNodes18=3,4,5,7,8,9,10,11,12,13,15,16,18
|
||||
ModuleClosedNodes19=
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes20=
|
||||
ModuleClosedNodes21=20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
|
||||
ModuleClosedNodes22=
|
||||
ModuleClosedNodes23=
|
||||
ModuleClosedNodes24=10,12,14
|
||||
ModuleClosedNodes24=
|
||||
ModuleClosedNodes25=
|
||||
ModuleClosedNodes26=2
|
||||
ModuleClosedNodes27=
|
||||
ModuleClosedNodes28=
|
||||
ModuleClosedNodes29=
|
||||
ModuleClosedNodes29=9,10,11
|
||||
ModuleClosedNodes3=3
|
||||
ModuleClosedNodes30=9,10,11
|
||||
ModuleClosedNodes30=
|
||||
ModuleClosedNodes31=
|
||||
ModuleClosedNodes32=
|
||||
ModuleClosedNodes4=
|
||||
ModuleClosedNodes5=
|
||||
ModuleClosedNodes6=
|
||||
ModuleClosedNodes7=
|
||||
ModuleClosedNodes8=
|
||||
ModuleClosedNodes9=
|
||||
NavigationStack=C_Principal,cargar_Click,506,6,B4XMainPage,Class_Globals,100,0,B4XMainPage,B4XPage_CloseRequest,531,0,B4XMainPage,b_extras_Click,788,0,B4XMainPage,b_aceptarExtras_Click,796,0,B4XMainPage,p_extras_Click,791,0,C_Principal,JobDone,967,0,C_Principal,B4XPage_Created,200,0,Visual Designer,login.bal,-100,6,B4XMainPage,et_geocerca_TextChanged,768,0
|
||||
NavigationStack=Subs,panelAnchoAlto,724,0,C_Subs,panelVisible,266,0,C_Subs,panelOculto,274,0,Subs,traeCoordsDeBD,709,0,Subs,centraEditText,586,0,Subs,centraPanel,585,0,C_Subs,panelAnchoAlto,280,0,C_Subs,centraEditText,311,0,C_Subs,centraPanelV,303,0,C_Subs,centraProgressBar,308,0,C_Productos,B4XPage_Appear,143,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=1,30,11,24,3,31,28
|
||||
VisibleModules=1,29,11,24,3,30,14,12
|
||||
|
||||
@@ -202,7 +202,7 @@ Sub JobDone(Job As HttpJob)
|
||||
If Job.Success = False Then
|
||||
' ToastMessageShow("Error: " & Job.ErrorMessage, True)
|
||||
Else
|
||||
If Logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
' If Logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211110
|
||||
If Job.JobName = "DBRequest" Then
|
||||
Dim result As DBResult = reqManager.HandleJob(Job)
|
||||
If result.Tag = "updateKell_UTR" Then 'query tag
|
||||
|
||||
@@ -1546,8 +1546,8 @@ Sub fechanormal(fecha As String) As String 'ignore
|
||||
Return nuevaFecha
|
||||
End Sub
|
||||
|
||||
'En geocerca si mete la contraseña poner 0 en precision gps y si esta dentro de los 50 mts poner 1 y 2 para eventos que no lo ocupen
|
||||
'Mandar fecha de sync(sysdate)
|
||||
'En geocerca si mete la contraseña poner 0 en precision gps y si esta dentro de los 50 mts poner 1 y 2 para eventos que no lo ocupen
|
||||
'Mandar fecha de sync(sysdate)
|
||||
Sub bitacora(fechab As String, usuariob As String, almacenb As String, rutab As String, eventob As String, clienteb As String, iniciob As String, finb As String, latitudb As String, longitudb As String, precision As String, motivonoventa As String, motivonovisita As String )
|
||||
Log("bitacora")
|
||||
Starter.skmt.ExecNonQuery($"INSERT INTO BITACORAGPS (fechab, usuariob , almacenb , rutab , eventob , clienteb , iniciob , finb , latitudb , longitudb , precision , motivonoventa , motivonovisita) VALUES ('${fechab}' ,'${usuariob}' , '${almacenb}' , '${rutab}' , '${eventob}' , '${clienteb}' , '${iniciob}' , '${finb}' , '${latitudb}' , '${longitudb}' , '${precision}' , '${motivonoventa}' , '${motivonovisita}')"$)
|
||||
|
||||
@@ -13,7 +13,7 @@ Sub Class_Globals
|
||||
Dim rp As RuntimePermissions
|
||||
Dim safePath As String
|
||||
Dim fechaHoy As String
|
||||
Dim fechaAnt As String
|
||||
' Dim fechaAnt As String
|
||||
Dim skmtAttached As Boolean = False
|
||||
Dim rkmtAttached As Boolean = False
|
||||
'####### MES Vars ######
|
||||
@@ -46,18 +46,23 @@ Sub RD_Init
|
||||
Dim Dirp As String = File.DirRootExternal
|
||||
Dim Dir As String
|
||||
' Dim Dir2 As String
|
||||
' File.MakeDir(File.DirRootExternal,"/kmts")
|
||||
' File.MakeDir(rp.GetSafeDirDefaultExternal("/"), "kmts")
|
||||
Try
|
||||
File.MakeDir(Dirp,"/kmts")
|
||||
Dir = "/kmts"
|
||||
' Log("creado en kmts " & Dirp & Dir)
|
||||
Log("Creado kmts " & Dirp & Dir)
|
||||
Log(File.IsDirectory(Dirp, Dir))
|
||||
Catch
|
||||
Dir = ""
|
||||
' Log("creado en raiz")
|
||||
Log("Creado en raiz")
|
||||
End Try
|
||||
safePath = Dirp & Dir
|
||||
'Si no existe el directorio "kmts" en el raiz de la tarjeta de memoria, nos cambiamos al directorio seguro (sdcard/Android/data/kelloggs...)
|
||||
If Not(File.IsDirectory(Dirp, Dir)) Then safePath = rp.GetSafeDirDefaultExternal("kmts")
|
||||
If Starter.Logger Then Log($"Safepath:${safePath}"$)
|
||||
Private name() As String = Regex.split(" ", Application.LabelName)
|
||||
rkmt.Initialize(safePath,$"${name(0)}.rkmt.km"$, True)
|
||||
Private name() As String = Regex.split(" ", Application.LabelName) 'Obtenemos el nombre de la app para ponerselo a la BD.
|
||||
rkmt.Initialize(safePath, $"${name(0)}.rkmt.km"$, True)
|
||||
skmt.Initialize(File.DirInternal,"kmt.db", False)
|
||||
If chkIfTableExists(skmt, "PEDIDO") Then rkmt.ExecNonQuery($"create table if not exists PEDIDO (${getTableColumnList(skmt, "PEDIDO")}, FECHA TEXT)"$)
|
||||
If chkIfTableExists(skmt, "CAT_DETALLES_PAQ") Then rkmt.ExecNonQuery($"create table if not exists CAT_DETALLES_PAQ (${getTableColumnList(skmt, "CAT_DETALLES_PAQ")}, FECHA TEXT)"$)
|
||||
@@ -129,7 +134,7 @@ Sub RD_respalda_pedido
|
||||
rkmt.EndTransaction
|
||||
End If
|
||||
x.Close
|
||||
Log("P: " & ((DateTime.Now - inicio)/1000) & " segs")
|
||||
LogColor("P: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
|
||||
End Sub
|
||||
|
||||
'RD - Copia la tabla CAT_GUNAPRODS a rkmt.db en la tarjeta del celular.
|
||||
@@ -147,7 +152,7 @@ Sub RD_respalda_cat_gunaprod
|
||||
rkmt.EndTransaction
|
||||
End If
|
||||
x.Close
|
||||
Log("GP: " & ((DateTime.Now - inicio)/1000) & " segs")
|
||||
LogColor("GP: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
|
||||
End Sub
|
||||
|
||||
'RD - Copia la tabla CAT_GUNAPROD de rkmt.db al celular.
|
||||
@@ -188,7 +193,7 @@ Sub RD_respalda_cat_gunaprod2
|
||||
rkmt.EndTransaction
|
||||
End If
|
||||
x.Close
|
||||
Log("GP2: " & ((DateTime.Now - inicio)/1000) & " segs")
|
||||
LogColor("GP2: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
|
||||
End Sub
|
||||
|
||||
'RD - Copia la tabla CAT_GUNAPROD2 de rkmt.db al celular.
|
||||
@@ -224,7 +229,7 @@ Sub RD_respalda_cat_detalle_paq
|
||||
rkmt.ExecNonQuery($"insert into CAT_DETALLES_PAQ (${lasCols}, FECHA) select ${lasCols}, '${fechaHoy}' as FECHA from skmt1.CAT_DETALLES_PAQ"$)
|
||||
rkmt.TransactionSuccessful 'Si no se pone TransactionSuccessful no se escribe NADA!!
|
||||
rkmt.EndTransaction
|
||||
Log("DP: " & ((DateTime.Now - inicio)/1000) & " segs")
|
||||
LogColor("DP: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
|
||||
End If
|
||||
x.Close
|
||||
End Sub
|
||||
@@ -264,7 +269,7 @@ Sub RD_respalda_kmt_info
|
||||
rkmt.EndTransaction
|
||||
End If
|
||||
x.Close
|
||||
Log("KMT: " & ((DateTime.Now - inicio)/1000) & " segs")
|
||||
LogColor("KMT: " & ((DateTime.Now - inicio)/1000) & " segs", Colors.RGB(166,37,0))
|
||||
End Sub
|
||||
|
||||
'RD - Copia la tabla kmt_info de rkmt.db al celular.
|
||||
@@ -529,7 +534,7 @@ Sub hayPedido(db As SQL) As Boolean 'ignore
|
||||
Return hay
|
||||
End Sub
|
||||
|
||||
Sub string2date(fecha As String)
|
||||
Sub string2date(fecha As String) 'ignore
|
||||
Log(fecha)
|
||||
DateTime.DateFormat = "MM/dd/yyyy"
|
||||
Dim t As Long = DateTime.DateTimeParse(fecha, "00:00:00")
|
||||
|
||||
Reference in New Issue
Block a user