mirror of
https://github.com/KeymonSoft/Kelloggs_v4.git
synced 2026-04-19 19:19:14 +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:
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
|
||||
Reference in New Issue
Block a user