mirror of
https://github.com/KeymonSoft/Mariana.git
synced 2026-04-20 06:09:16 +00:00
15/9/23 - Codigo de prueba en C_Subs
Código de prueba para hacer un DBRequest desde una clase y "tratar" de simplificar algunas funciones.
This commit is contained in:
@@ -18,7 +18,6 @@ Version=9.85
|
|||||||
#End Region
|
#End Region
|
||||||
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\
|
||||||
|
|
||||||
|
|
||||||
Sub Class_Globals
|
Sub Class_Globals
|
||||||
Private Root As B4XView
|
Private Root As B4XView
|
||||||
Private xui As XUI
|
Private xui As XUI
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ Version=11.5
|
|||||||
@EndOfDesignText@
|
@EndOfDesignText@
|
||||||
Sub Class_Globals
|
Sub Class_Globals
|
||||||
Public rp As RuntimePermissions
|
Public rp As RuntimePermissions
|
||||||
|
dim s as C_Subs
|
||||||
Private Root As B4XView 'ignore
|
Private Root As B4XView 'ignore
|
||||||
Private xui As XUI 'ignore
|
Private xui As XUI 'ignore
|
||||||
Dim conectado As String
|
Dim conectado As String
|
||||||
@@ -233,6 +234,7 @@ Private Sub B4XPage_Created (Root1 As B4XView)
|
|||||||
Root = Root1
|
Root = Root1
|
||||||
'load the layout to Root
|
'load the layout to Root
|
||||||
Root.LoadLayout("principal")
|
Root.LoadLayout("principal")
|
||||||
|
s.Initialize(Me, "Subs")
|
||||||
EJECUTANDO=1
|
EJECUTANDO=1
|
||||||
Dim ruta As String
|
Dim ruta As String
|
||||||
img2.Visible =False
|
img2.Visible =False
|
||||||
@@ -955,6 +957,7 @@ Sub cargar_Click
|
|||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub JobDone(Job As HttpJob)
|
Sub JobDone(Job As HttpJob)
|
||||||
|
Log("JOBDONE PRINCIPAL")
|
||||||
' If Job.JobName = "DBRequest" Then
|
' If Job.JobName = "DBRequest" Then
|
||||||
' Dim RESULT As DBResult = B4XPages.MainPage.reqManager.HandleJob(Job)
|
' Dim RESULT As DBResult = B4XPages.MainPage.reqManager.HandleJob(Job)
|
||||||
' Log($"Tag: ${RESULT.tag}, success=${Job.Success}"$)
|
' Log($"Tag: ${RESULT.tag}, success=${Job.Success}"$)
|
||||||
@@ -1731,6 +1734,20 @@ Private Sub B4XPage_CloseRequest As ResumableSub
|
|||||||
Return False
|
Return False
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
'############################################################################################
|
||||||
|
'################### Codigo de prueba JAGU, no poner atencion ############################
|
||||||
|
Sub connecta_LongClick
|
||||||
|
ProgressDialogShow("Enviamos")
|
||||||
|
s.reqManagerReInit 'Reiniciamos el DBReqManager por si hay modificacion en el servidor.
|
||||||
|
s.envioTest 'Llamamos envioTest de C_Subs.
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub Subs_envioOk(succes As Boolean)
|
||||||
|
Log("###################### " & succes)
|
||||||
|
ProgressDialogHide
|
||||||
|
End Sub
|
||||||
|
'################################ Termina codigo de prueba #############################
|
||||||
|
|
||||||
Sub connecta_Click
|
Sub connecta_Click
|
||||||
B4XPages.MainPage.reqManager.Initialize(Me, Starter.server)
|
B4XPages.MainPage.reqManager.Initialize(Me, Starter.server)
|
||||||
Log(Starter.server)
|
Log(Starter.server)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ ModulesStructureVersion=1
|
|||||||
Type=Class
|
Type=Class
|
||||||
Version=11.5
|
Version=11.5
|
||||||
@EndOfDesignText@
|
@EndOfDesignText@
|
||||||
Sub Mods
|
Sub Mods 'ignore
|
||||||
'20230526 - Se cambió en b_terminar_click y b_continuar_click la funcion "guardaProducto" por "guardaProductoSinGestion", para que no ponga que ya esta guardada la orden y no deje borrar productos.
|
'20230526 - Se cambió en b_terminar_click y b_continuar_click la funcion "guardaProducto" por "guardaProductoSinGestion", para que no ponga que ya esta guardada la orden y no deje borrar productos.
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ Sub Class_Globals
|
|||||||
Private b_continuar As Button
|
Private b_continuar As Button
|
||||||
Private p_prodsVariables As Panel
|
Private p_prodsVariables As Panel
|
||||||
Dim laPromo = "", elCliente = "" As String
|
Dim laPromo = "", elCliente = "" As String
|
||||||
Dim prodsPedidoActual As String
|
Dim prodsPedidoActual As String 'ignore
|
||||||
Dim montoPedidoActual As String
|
Dim montoPedidoActual As String 'ignore
|
||||||
Dim promosMap As Map
|
Dim promosMap As Map
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
@@ -155,8 +155,8 @@ Sub muestraPromo(promo As String, cliente As String)
|
|||||||
' jpeg = c2.GetBlob("CAT_GP_IMG")
|
' jpeg = c2.GetBlob("CAT_GP_IMG")
|
||||||
' ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
|
' ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
|
||||||
' bmp.Initialize2(ins)
|
' bmp.Initialize2(ins)
|
||||||
Private indicePV = pv.IndexOf(p)
|
Private indicePV As String = pv.IndexOf(p)
|
||||||
Private estePrecio = listaPreciosPV.Get(indicePV)
|
Private estePrecio as string = listaPreciosPV.Get(indicePV)
|
||||||
Private thisProd As Map = prodsPromo.Get(p)
|
Private thisProd As Map = prodsPromo.Get(p)
|
||||||
If thisLog Then Log(thisProd)
|
If thisLog Then Log(thisProd)
|
||||||
clv_prodsVariabes.Add(CreateListItem(Subs.traeProdNombre(p)&CRLF&"Hay " & invDispPromo.Get(p) & " $" & estePrecio, estePrecio, invDispPromo.Get(p), clv_prodsVariabes.AsView.Width, 50dip, Null, p), p)
|
clv_prodsVariabes.Add(CreateListItem(Subs.traeProdNombre(p)&CRLF&"Hay " & invDispPromo.Get(p) & " $" & estePrecio, estePrecio, invDispPromo.Get(p), clv_prodsVariabes.AsView.Width, 50dip, Null, p), p)
|
||||||
@@ -426,7 +426,7 @@ Private Sub b_continuar_Click
|
|||||||
lv_prodsFijos.Clear
|
lv_prodsFijos.Clear
|
||||||
' Activity_KeyPress(KeyCodes.KEYCODE_BACK)
|
' Activity_KeyPress(KeyCodes.KEYCODE_BACK)
|
||||||
' CallSubDelayed2(productos, "Activity_KeyPress", KeyCodes.KEYCODE_BACK)
|
' CallSubDelayed2(productos, "Activity_KeyPress", KeyCodes.KEYCODE_BACK)
|
||||||
Private prodspage As C_Productos
|
Private prodspage As C_Productos 'ignore
|
||||||
If prodspage.IsInitialized Then
|
If prodspage.IsInitialized Then
|
||||||
prodspage.lv_catalogos.Visible = True
|
prodspage.lv_catalogos.Visible = True
|
||||||
prodspage.lv_promos.Visible = False
|
prodspage.lv_promos.Visible = False
|
||||||
|
|||||||
497
B4A/C_Subs.bas
Normal file
497
B4A/C_Subs.bas
Normal file
@@ -0,0 +1,497 @@
|
|||||||
|
B4A=true
|
||||||
|
Group=Default Group
|
||||||
|
ModulesStructureVersion=1
|
||||||
|
Type=Class
|
||||||
|
Version=12.2
|
||||||
|
@EndOfDesignText@
|
||||||
|
Sub Class_Globals
|
||||||
|
'These global variables will be declared once when the application starts.
|
||||||
|
'These variables can be accessed from all modules.
|
||||||
|
' Public GZip As GZipStrings 'Usa la libreria CompressStrings
|
||||||
|
' Private su As StringUtils 'Usa la libreria StringUtils
|
||||||
|
Dim reqManager As DBRequestManager
|
||||||
|
Private EventName As String 'ignore
|
||||||
|
Private CallBack As Object 'ignore
|
||||||
|
Dim phn As Phone
|
||||||
|
Dim devModel As String
|
||||||
|
Dim db, kmt, errorLog As SQL 'Requiere la libreria "SQL" 'ignore
|
||||||
|
Dim ssid As String 'ignore
|
||||||
|
Dim reqsList As List
|
||||||
|
Private subsLogs As Boolean = False
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'You can add more parameters here.
|
||||||
|
Public Sub Initialize (vCallback As Object, vEventName As String) As Object
|
||||||
|
reqsList.Initialize
|
||||||
|
EventName = vEventName
|
||||||
|
CallBack = vCallback
|
||||||
|
db = dbInit
|
||||||
|
reqManager = reqManagerInit
|
||||||
|
Return Me
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Inicializa la BD con "kmt.db" en File.DirInternal, si el archivo no existe, lo copia desde File.DirAssets.
|
||||||
|
'Dispara el evento "dbOk" cuando termina.
|
||||||
|
Sub dbInit As SQL
|
||||||
|
If File.Exists(File.DirInternal, "kmt.db") = False Then File.Copy(File.DirAssets, "kmt.db", File.DirInternal, "kmt.db")
|
||||||
|
db.Initialize(File.DirInternal,"kmt.db", True)
|
||||||
|
dbOk(True)
|
||||||
|
Log(db.IsInitialized)
|
||||||
|
Return db
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub dbOk(Success As Boolean)
|
||||||
|
If SubExists(CallBack, EventName & "_dbOk") Then
|
||||||
|
CallSub2(CallBack, EventName & "_dbOk", Success)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub reqManagerInit As DBRequestManager
|
||||||
|
Private rm As DBRequestManager
|
||||||
|
rm.Initialize(Me, traeDBReqServerDeBD(db))
|
||||||
|
Log($"Inicializamos reqManager con ${traeDBReqServerDeBD(db)}"$)
|
||||||
|
Return rm
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub reqManagerReInit
|
||||||
|
Log("reqManager ReInit")
|
||||||
|
reqManager = reqManagerInit
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub envioTest
|
||||||
|
reqsList.Initialize ' Ponemos la lista de DBRequests en cero.
|
||||||
|
Private cmd As DBCommand
|
||||||
|
cmd.Initialize
|
||||||
|
cmd.Name = "select_fecha"
|
||||||
|
For i = 0 To 20
|
||||||
|
reqManager.ExecuteQuery(cmd, 0, $"select_fecha_${i}"$)
|
||||||
|
reqsList.Add($"select_fecha_${i}"$)
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Dispara el evento "_envioOk" del caller.
|
||||||
|
Sub envioOk(Success As Boolean)
|
||||||
|
' Log($"_ENVIOOK_"$)
|
||||||
|
If SubExists(CallBack, EventName & "_envioOk") Then
|
||||||
|
CallSub2(CallBack, EventName & "_envioOk", Success)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub JobDone(Job As HttpJob)
|
||||||
|
LogColor("C_SUBS JOBDONE - " & Job.Success, Colors.Red)
|
||||||
|
If Job.Success = False Then
|
||||||
|
LogColor("** " & Job.Tag & " Error: " & Job.ErrorMessage, Colors.Red)
|
||||||
|
Else
|
||||||
|
If Job.JobName = "DBRequest" Then
|
||||||
|
Dim resultado As DBResult = reqManager.HandleJob(Job)
|
||||||
|
If reqsList.IndexOf(resultado.Tag) > -1 Then reqsList.RemoveAt(reqsList.IndexOf(resultado.Tag))
|
||||||
|
If resultado.Tag = "select_fecha" Then
|
||||||
|
For Each records() As Object In resultado.Rows
|
||||||
|
For Each k As String In resultado.Columns.Keys
|
||||||
|
Log(resultado.Tag & ": " & k & ": " & records(resultado.Columns.Get(k)))
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
Log(reqsList.Size)
|
||||||
|
If reqsList.Size = 0 Then 'Ya no hay DBReqs pendientes.
|
||||||
|
envioOk(True)
|
||||||
|
Log("-= FIN =-")
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
Job.Release
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Pone el valor de phn.Model en la variable global "devModel"
|
||||||
|
Sub getPhnId As String 'ignore
|
||||||
|
'Requiere la libreria "Phone"
|
||||||
|
devModel = phn.Model
|
||||||
|
If devModel.Length <= 3 Then 'Si phn.Model esta en blanco ...
|
||||||
|
Dim t As String = phn.GetSettings("android_id") 'Intentamos con "android_id"
|
||||||
|
devModel = t
|
||||||
|
End If
|
||||||
|
If devModel.Length >= 3 Then 'Si tenemos valor para phn.Model
|
||||||
|
File.WriteString(File.DirInternal, "phnId.txt", devModel) 'Sobreescribimos archivo phnId.txt with deviceId
|
||||||
|
' Log("Tenemos phnId: "&devModel&" "&File.DirInternal&"/phn.txt sobreescrito")
|
||||||
|
Else If devModel.Length < 3 Then ' Si no tenemos valor, lo leemos de phnId.txt
|
||||||
|
Dim s As String = File.ReadString(File.DirInternal, "phnId.txt")
|
||||||
|
devModel = s
|
||||||
|
' Log("Leemos id de "&File.DirInternal&"/phnId.txt")
|
||||||
|
' Log(devModel)
|
||||||
|
End If
|
||||||
|
Return devModel
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Convierte una fecha al formato yyMMddHHmmss
|
||||||
|
Sub fechaKMT(fecha As String) As String 'ignore
|
||||||
|
' Log(fecha)
|
||||||
|
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||||
|
DateTime.DateFormat="yyMMddHHmmss"
|
||||||
|
Dim nuevaFecha As String=DateTime.Date(fecha)
|
||||||
|
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||||
|
' Log(nuevaFecha)
|
||||||
|
Return nuevaFecha
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Escribimos las coordenadas y fecha a un archivo de texto
|
||||||
|
Sub guardaInfoEnArchivo(coords As String) 'ignore
|
||||||
|
' Cambiamos el formato de la hora
|
||||||
|
Dim OrigFormat As String=DateTime.DateFormat 'save orig date format
|
||||||
|
DateTime.DateFormat="MMM-dd HH:mm:ss"
|
||||||
|
Dim lastUpdate As String=DateTime.Date(DateTime.Now)
|
||||||
|
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||||
|
|
||||||
|
Dim ubic As String = coords&","&lastUpdate
|
||||||
|
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal, "gps.txt", True)
|
||||||
|
Dim s As String = ubic & CRLF
|
||||||
|
Dim t() As Byte = s.GetBytes("UTF-8")
|
||||||
|
out.WriteBytes(t, 0, t.Length)
|
||||||
|
out.Close
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Escribimos las coordenadas (latitud, longitud, fecha) y fecha a una BD
|
||||||
|
Sub guardaInfoEnBD(coords As String) 'ignore
|
||||||
|
Log("Guardamos ubicacion en BD - "&coords)
|
||||||
|
Try
|
||||||
|
Dim latlon() As String = Regex.Split("\|", coords)
|
||||||
|
If latlon.Length < 2 Then latlon = Regex.Split(",", coords) 'Si son menos de 2, entonces estan separadas por comas y no por "|"
|
||||||
|
If subsLogs Then Log("LatLon="&latlon)
|
||||||
|
kmt.ExecNonQuery2("INSERT INTO RUTA_GPS(FECHA, LAT, LON) VALUES (?,?,?)", Array As Object (latlon(2),latlon(0),latlon(1)))
|
||||||
|
Catch
|
||||||
|
LogColor(LastException, Colors.red)
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Limpiamos la tabla RUTA_GPS de la BD
|
||||||
|
Sub deleteGPS_DB 'ignore
|
||||||
|
kmt.ExecNonQuery("delete from RUTA_GPS")
|
||||||
|
kmt.ExecNonQuery("vacuum;")
|
||||||
|
ToastMessageShow("Borramos BD Coords GPS", False)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Limpiamos la tabla errorLog de la BD
|
||||||
|
Sub deleteErrorLog_DB 'ignore
|
||||||
|
errorLog.ExecNonQuery("delete from errores")
|
||||||
|
errorLog.ExecNonQuery("vacuum;")
|
||||||
|
ToastMessageShow("BD Errores Borrada", False)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Mandamos "coords" en un mensaje a "Sprvsr"
|
||||||
|
'Sub mandamosLoc(coords As String) 'ignore
|
||||||
|
'' Log("Iniciamos mandamosLoc "&coords)
|
||||||
|
'' Log("locRequest="&Tracker.locRequest)
|
||||||
|
' guardaInfoEnBD(coords)'Escribimos coordenadas y fecha a una bd
|
||||||
|
' Dim t As String
|
||||||
|
' If Tracker.locRequest="Activa" Then
|
||||||
|
' If PushService.au = 1 Then
|
||||||
|
' t = "au" ' es una actualizacion
|
||||||
|
' Else
|
||||||
|
' t = "u" ' es una peticion
|
||||||
|
' End If
|
||||||
|
' Dim params As Map = CreateMap("topic":"Sprvsr", "coords":coords, "t":t, "b":PushService.battery, "mt":Main.montoActual)
|
||||||
|
' CallSub2(PushService, "mandaMensaje",params)
|
||||||
|
' Tracker.locRequest="Enviada"
|
||||||
|
' CallSubDelayed(Tracker,"CreateLocationRequest")
|
||||||
|
' End If
|
||||||
|
'End Sub
|
||||||
|
|
||||||
|
'Regresa la fecha y hora de hoy a las 00:00 en el formato "yyMMddHHMMSS"
|
||||||
|
Sub fechaInicioHoy As String 'ignore
|
||||||
|
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
|
||||||
|
DateTime.DateFormat="yyMMdd"
|
||||||
|
Private h As String = DateTime.Date(DateTime.Now)&"000000"
|
||||||
|
DateTime.DateFormat=OrigFormat 'return to orig date format
|
||||||
|
Log("Hoy="&h)
|
||||||
|
Return h
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Guardamos "texto" a la bitacora
|
||||||
|
Sub log2DB(texto As String) 'ignore
|
||||||
|
LogColor(fechaKMT(DateTime.Now)&" - log2BD: '"&texto&"'", Colors.LightGray)
|
||||||
|
kmt.ExecNonQuery2("INSERT INTO bitacora(fecha, texto) VALUES (?,?)", Array As Object (fechaKMT(DateTime.now), texto))
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa verdadero si ya pasaron XX minutos de la fecha dada
|
||||||
|
Sub masDeXXMins(hora As Int, mins As Int) As Boolean 'ignore
|
||||||
|
If (hora + mins * DateTime.TicksPerMinute) < DateTime.Now Then
|
||||||
|
Return True
|
||||||
|
Else
|
||||||
|
Return False
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa verdadero si ya pasaron XX minutos de la fechaKMT dada
|
||||||
|
Sub masDeXXMinsKMT(hora As String, mins As Int) As Boolean 'ignore
|
||||||
|
Try
|
||||||
|
' LogColor($"Hora=${fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute)}, Mins=${mins}, Actual=${fechaKMT(DateTime.Now)}"$,Colors.red)
|
||||||
|
If fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute < DateTime.Now Then
|
||||||
|
' Log("+++ +++ "&fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute) & " < " & fechaKMT(DateTime.Now))
|
||||||
|
Return True
|
||||||
|
Else
|
||||||
|
' Log("+++ +++ "&fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute) & " > " & fechaKMT(DateTime.Now))
|
||||||
|
Return False
|
||||||
|
End If
|
||||||
|
Catch
|
||||||
|
Log(LastException)
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Limpiamos la tabla "bitacora" de la BD
|
||||||
|
Sub borraLogDB 'ignore
|
||||||
|
LogColor("Borramos BD de log", Colors.Magenta)
|
||||||
|
kmt.ExecNonQuery("delete from bitacora")
|
||||||
|
kmt.ExecNonQuery("vacuum;")
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Monitoreamos los servicios para ver si estan activos (No pausados), y si no, los reniciamos
|
||||||
|
'Sub Monitor 'ignore
|
||||||
|
' Private monitorStatus As Boolean = True
|
||||||
|
' LogColor("Corriendo Subs.Monitor", Colors.RGB(161,150,0))
|
||||||
|
' If IsPaused(Tracker) Then
|
||||||
|
' log2DB("Reiniciando 'Tracker Pausado' desde Subs.Monitor")
|
||||||
|
' StartService(Tracker)
|
||||||
|
' monitorStatus = False
|
||||||
|
' Else
|
||||||
|
' CallSubDelayed(Tracker, "revisaFLP")
|
||||||
|
' End If
|
||||||
|
' If IsPaused(PushService) Then
|
||||||
|
' log2DB("Reiniciando 'PushService Pausado' desde Subs.Monitor")
|
||||||
|
' StartService(PushService)
|
||||||
|
' monitorStatus = False
|
||||||
|
' Else
|
||||||
|
' revisaPushService
|
||||||
|
' End If
|
||||||
|
' If monitorStatus Then LogColor(" +++ +++ Servicios Activos", Colors.Green)
|
||||||
|
'End Sub
|
||||||
|
|
||||||
|
'Convierte una fecha en formato YYMMDDHHMMSS a Ticks
|
||||||
|
Sub fechaKMT2Ticks(fKMT As String) As Long 'ignore
|
||||||
|
Try
|
||||||
|
If fKMT.Length = 12 Then
|
||||||
|
Private parteFecha As String = fKMT.SubString2(0,6)
|
||||||
|
Private parteHora As String = fKMT.SubString(6)
|
||||||
|
Private OrigFormat As String = DateTime.DateFormat 'save original date format
|
||||||
|
DateTime.DateFormat="yymmdd"
|
||||||
|
DateTime.TimeFormat="HHmmss"
|
||||||
|
Private ticks As Long = DateTime.DateTimeParse(parteFecha,parteHora)
|
||||||
|
DateTime.DateFormat=OrigFormat 'return to original date format
|
||||||
|
Return ticks
|
||||||
|
Else
|
||||||
|
Log("Formato de fecha incorrecto, debe de ser 'YYMMDDHHMMSS', no '"&fKMT&"' largo="&fKMT.Length)
|
||||||
|
Return 0
|
||||||
|
End If
|
||||||
|
Catch
|
||||||
|
Log(LastException)
|
||||||
|
LogColor($"Fecha dada: ${fKMT}, Parte Fecha: ${parteFecha}, Parte Hora: ${parteHora}"$, Colors.Red)
|
||||||
|
Return 0
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Sub InstallAPK(dir As String, apk As String) 'ignore
|
||||||
|
If File.Exists(dir, apk) Then
|
||||||
|
Dim i As Intent
|
||||||
|
i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(dir, apk))
|
||||||
|
i.SetType("application/vnd.android.package-archive")
|
||||||
|
StartActivity(i)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Copia la base de datos del almacenamiento interno al externo en el directorio kmts.
|
||||||
|
Sub copiaDB(result As Boolean) 'ignore
|
||||||
|
ToastMessageShow("copiaDB", False)
|
||||||
|
If result Then
|
||||||
|
Dim p As String
|
||||||
|
If File.ExternalWritable Then
|
||||||
|
p = File.DirRootExternal
|
||||||
|
' Log("Externo")
|
||||||
|
Else
|
||||||
|
p = File.DirInternal
|
||||||
|
' Log("Interno")
|
||||||
|
End If
|
||||||
|
Dim theDir As String
|
||||||
|
Try
|
||||||
|
File.MakeDir(File.DirRootExternal,"kmts")
|
||||||
|
theDir = "/kmts"
|
||||||
|
Catch
|
||||||
|
theDir = ""
|
||||||
|
End Try
|
||||||
|
Try
|
||||||
|
File.Copy(File.DirInternal,"kmt.db",File.DirRootExternal&theDir,"cedex_kmt.db")
|
||||||
|
File.Copy(File.DirInternal,"errorLog.db",File.DirRootExternal&theDir,"cedex_errorLog.db")
|
||||||
|
ToastMessageShow("BD copiada!", False)
|
||||||
|
Catch
|
||||||
|
ToastMessageShow("No se pudo hacer la copia: "&LastException, True)
|
||||||
|
End Try
|
||||||
|
Log("rootExternal="&p)
|
||||||
|
Log("File.DirInternal="&File.DirInternal)
|
||||||
|
Log("File.DirRootExternal="&File.DirRootExternal)
|
||||||
|
Else
|
||||||
|
ToastMessageShow("Sin permisos", False)
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Hace visible y trae al frente el panel con los parametros "Top" y "Left" dados.
|
||||||
|
Sub panelVisible(panel As Panel, top As Int, left As Int) 'ignore
|
||||||
|
panel.BringToFront
|
||||||
|
panel.Visible = True
|
||||||
|
panel.Top = top
|
||||||
|
panel.Left = left
|
||||||
|
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)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Centra un panel horizontalmente dentro de un elemento superior.
|
||||||
|
Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore
|
||||||
|
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Centra un panel verticalmente dentro de un elemento superior.
|
||||||
|
Sub centraPanelV(elemento As Panel, altoElementoSuperior As Int) 'ignore
|
||||||
|
elemento.Top = Round(altoElementoSuperior/2)-(elemento.Height/2)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Centra una barra de progreso dentro de un elemento superior.
|
||||||
|
Sub centraProgressBar(elemento As ProgressBar, 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
|
||||||
|
Private usuario As String = "SinUsuario"
|
||||||
|
c=kmt.ExecQuery("select USUARIO from usuarioa")
|
||||||
|
c.Position=0
|
||||||
|
If c.RowCount > 0 Then usuario = c.GetString("USUARIO")
|
||||||
|
Return usuario
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa la fecha en el formato "MM/dd/yyyy"
|
||||||
|
Sub traeFecha As String 'ignore
|
||||||
|
DateTime.DateFormat = "MM/dd/yyyy"
|
||||||
|
Private sDate As String = DateTime.Date(DateTime.Now)
|
||||||
|
Private sTime As String = DateTime.Time(DateTime.Now)
|
||||||
|
Return sDate & sTime
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Guarda el nombre y version de la app en CAT_VARIABLES.
|
||||||
|
Sub guardaAppInfo(skmt As SQL) 'ignore
|
||||||
|
skmt.ExecNonQuery("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = 'EMPRESA' or CAT_VA_DESCRIPCION = 'APP_NAME' or CAT_VA_DESCRIPCION = 'APP_VERSION'")
|
||||||
|
skmt.ExecNonQuery($"insert into CAT_VARIABLES (CAT_VA_DESCRIPCION, CAT_VA_VALOR) values ('APP_NAME', '${Application.LabelName}')"$)
|
||||||
|
skmt.ExecNonQuery($"insert into CAT_VARIABLES (CAT_VA_DESCRIPCION, CAT_VA_VALOR) values ('APP_VERSION', '${Application.VersionName}')"$)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Muestra en el Log los campos y valores que regresan en el JobDone.
|
||||||
|
Sub logJobDoneResultados(resultado As DBResult) 'ignore
|
||||||
|
For Each records() As Object In resultado.Rows
|
||||||
|
LogColor($"====== ${resultado.Tag} - REGISTROS = ${resultado.Rows.Size}"$, Colors.RGB(215,37,0))
|
||||||
|
For Each k As String In resultado.Columns.Keys
|
||||||
|
LogColor(k & " = " & records(resultado.Columns.Get(k)), Colors.RGB(215,37,0))
|
||||||
|
Next
|
||||||
|
Next
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa la base de datos especificada ya inicializada.
|
||||||
|
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)
|
||||||
|
LogColor($"Copiamos ${BDName} de ${File.DirAssets} a ${ruta}"$,Colors.Green)
|
||||||
|
End If
|
||||||
|
skmt.Initialize(ruta, BDName, True)
|
||||||
|
Return skmt
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Agrega una columna a la tabla especificada.
|
||||||
|
'Hay que indicar el "tipo" de la columna (TEXT, INTEGER, ETC)
|
||||||
|
'Ej. agregaColumna("TABLA", "COLUMNA", "TIPO")
|
||||||
|
Sub agregaColumna(tabla As String, columna As String, tipo As String) 'ignore
|
||||||
|
Try 'Intentamos usar "pragma_table_info" para revisar si existe la columna en la tabla
|
||||||
|
Private c As Cursor = db.ExecQuery($"SELECT COUNT(*) AS fCol FROM pragma_table_info('${tabla}') WHERE name='${columna}'"$)
|
||||||
|
c.Position = 0
|
||||||
|
If c.GetString("fCol") = 0 Then 'Si no esta la columna la agregamos
|
||||||
|
db.ExecNonQuery($"ALTER TABLE ${tabla} ADD COLUMN ${columna} ${tipo}"$)
|
||||||
|
Log($"Columna "${columna} ${tipo}", agregada a "${tabla}"."$)
|
||||||
|
End If
|
||||||
|
Catch 'Si no funciona "pragma_table_info" lo hacemos con try/catch
|
||||||
|
Try
|
||||||
|
db.ExecNonQuery($"ALTER TABLE ${tabla} ADD COLUMN ${columna} ${tipo}"$)
|
||||||
|
Log($"Columna "${columna} ${tipo}", agregada a "${tabla}".."$)
|
||||||
|
Catch
|
||||||
|
Log(LastException)
|
||||||
|
End Try
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa el DBReqServer desde CAT_VARIABLES o "N/A" si no existe.
|
||||||
|
Sub traeDBReqServerDeBD(dbx As SQL) As String 'ignore
|
||||||
|
Dim srvr As String = "N/A"
|
||||||
|
Dim rs As ResultSet = dbx.ExecQuery("select CAT_VA_VALOR from cat_variables where CAT_VA_DESCRIPCION = 'SERVER'")
|
||||||
|
If rs.RowCount > 0 Then
|
||||||
|
rs.NextRow
|
||||||
|
srvr = rs.GetString("CAT_VA_VALOR")
|
||||||
|
End If
|
||||||
|
Return srvr
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa el valor de intervalo desde CAT_VARIABLES o "30" si no existe.
|
||||||
|
Sub traeIntervaloDeBD As String 'ignore
|
||||||
|
Dim intrvl As String = "30"
|
||||||
|
Dim rs As ResultSet = db.ExecQuery("select valor from cat_variables where nombre = 'intervalo'")
|
||||||
|
If rs.RowCount > 0 Then
|
||||||
|
rs.NextRow
|
||||||
|
intrvl = rs.GetString("valor")
|
||||||
|
End If
|
||||||
|
Return intrvl
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa el valor timeout desde CAT_VARIABLES o "9000" si no existe.
|
||||||
|
Sub traeTimeoutDeBD As String 'ignore
|
||||||
|
Dim tmout As String = "9000"
|
||||||
|
Dim rs As ResultSet = db.ExecQuery("select valor from cat_variables where nombre = 'timeout'")
|
||||||
|
If rs.RowCount > 0 Then
|
||||||
|
rs.NextRow
|
||||||
|
tmout = rs.GetString("valor")
|
||||||
|
End If
|
||||||
|
Return tmout
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Crea una notificación con el "body" dado y regresa el objeto.
|
||||||
|
Sub CreateNotification (Body As String) As Notification 'ignore
|
||||||
|
Dim notification As Notification
|
||||||
|
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||||
|
notification.Icon = "icon"
|
||||||
|
notification.SetInfo("Tester", Body, Main)
|
||||||
|
Return notification
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Genera una notificacion con importancia alta
|
||||||
|
Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
|
||||||
|
activity = Main
|
||||||
|
Private notif As Notification
|
||||||
|
notif.Initialize2(notif.IMPORTANCE_HIGH)
|
||||||
|
notif.Icon = "icon"
|
||||||
|
notif.Vibrate = False
|
||||||
|
notif.Sound = False
|
||||||
|
notif.AutoCancel = True
|
||||||
|
' If logger Then Log("notiHigh: "&title)
|
||||||
|
notif.SetInfo(title, body, activity)
|
||||||
|
' Log("notiHigh SetInfo")
|
||||||
|
notif.Notify(id)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Regresa el objeto de una notificacion con importancia baja
|
||||||
|
Sub notiLowReturn(title As String, Body As String, id As Int) As Notification 'ignore
|
||||||
|
Private notification As Notification
|
||||||
|
notification.Initialize2(notification.IMPORTANCE_LOW)
|
||||||
|
' Log("notiLowReturn: "&title)
|
||||||
|
notification.Icon = "icon"
|
||||||
|
notification.Sound = False
|
||||||
|
notification.Vibrate = False
|
||||||
|
notification.SetInfo(title, Body, Main)
|
||||||
|
notification.Notify(id)
|
||||||
|
' Log("notiLowReturn SetInfo")
|
||||||
|
Return notification
|
||||||
|
End Sub
|
||||||
@@ -51,7 +51,7 @@ Private Sub FindCamera (frontCamera As Boolean) As CameraInfoAndId
|
|||||||
Array As String("java.lang.int", "android.hardware.Camera$CameraInfo"))
|
Array As String("java.lang.int", "android.hardware.Camera$CameraInfo"))
|
||||||
r.target = cameraInfo
|
r.target = cameraInfo
|
||||||
Log("facing: " & r.GetField("facing") & ", " & cameraValue)
|
Log("facing: " & r.GetField("facing") & ", " & cameraValue)
|
||||||
If r.GetField("facing") = cameraValue Then
|
If r.GetField("facing") = cameraValue Then 'ignore
|
||||||
ci.cameraInfo = r.target
|
ci.cameraInfo = r.target
|
||||||
ci.Id = i
|
ci.Id = i
|
||||||
Return ci
|
Return ci
|
||||||
|
|||||||
@@ -730,15 +730,16 @@ Module11=C_Pedidos
|
|||||||
Module12=C_Principal
|
Module12=C_Principal
|
||||||
Module13=C_Productos
|
Module13=C_Productos
|
||||||
Module14=C_Promos
|
Module14=C_Promos
|
||||||
Module15=C_TicketsDia
|
Module15=C_Subs
|
||||||
Module16=C_UpdateAvailable
|
Module16=C_TicketsDia
|
||||||
Module17=CameraExClass2
|
Module17=C_UpdateAvailable
|
||||||
Module18=DBRequestManager
|
Module18=CameraExClass2
|
||||||
Module19=MAPA_RUTAS
|
Module19=DBRequestManager
|
||||||
Module2=B4XMainPage
|
Module2=B4XMainPage
|
||||||
Module20=Starter
|
Module20=MAPA_RUTAS
|
||||||
Module21=Subs
|
Module21=Starter
|
||||||
Module22=Tracker
|
Module22=Subs
|
||||||
|
Module23=Tracker
|
||||||
Module3=BatteryUtilities
|
Module3=BatteryUtilities
|
||||||
Module4=C_Cliente
|
Module4=C_Cliente
|
||||||
Module5=C_Clientes
|
Module5=C_Clientes
|
||||||
@@ -748,8 +749,8 @@ Module8=C_Nota
|
|||||||
Module9=C_NoVenta
|
Module9=C_NoVenta
|
||||||
NumberOfFiles=347
|
NumberOfFiles=347
|
||||||
NumberOfLibraries=29
|
NumberOfLibraries=29
|
||||||
NumberOfModules=22
|
NumberOfModules=23
|
||||||
Version=12.2
|
Version=12.5
|
||||||
@EndOfDesignText@
|
@EndOfDesignText@
|
||||||
#Region Project Attributes
|
#Region Project Attributes
|
||||||
#ApplicationLabel: Mariana
|
#ApplicationLabel: Mariana
|
||||||
|
|||||||
@@ -15,11 +15,12 @@ Sub Process_Globals
|
|||||||
Public gps As GPS
|
Public gps As GPS
|
||||||
Dim ph As Phone
|
Dim ph As Phone
|
||||||
Public rp As RuntimePermissions
|
Public rp As RuntimePermissions
|
||||||
|
Dim s As C_Subs
|
||||||
Public FLP As FusedLocationProvider
|
Public FLP As FusedLocationProvider
|
||||||
' Private flpStarted As Boolean
|
' Private flpStarted As Boolean
|
||||||
Dim reqManager As DBRequestManager
|
Dim reqManager As DBRequestManager
|
||||||
' Dim server As String = "http://11.0.0.253:1782"
|
' Dim server As String = "http://11.0.0.253:1782"
|
||||||
Dim server As String = "http://187.189.244.154:1783"
|
Dim server As String = "http://187.189.244.154:1782"
|
||||||
' Dim server As String = "http://10.0.0.205:1782"
|
' Dim server As String = "http://10.0.0.205:1782"
|
||||||
' Dim server As String = "http://11.0.0.231:1782"
|
' Dim server As String = "http://11.0.0.231:1782"
|
||||||
Dim Timer1 As Timer
|
Dim Timer1 As Timer
|
||||||
@@ -32,19 +33,19 @@ Sub Process_Globals
|
|||||||
Dim logger As Boolean = True
|
Dim logger As Boolean = True
|
||||||
Dim marcaCel As String = ph.manufacturer
|
Dim marcaCel As String = ph.manufacturer
|
||||||
Public rp As RuntimePermissions
|
Public rp As RuntimePermissions
|
||||||
Dim muestraProgreso = 0
|
Dim muestraProgreso As String = 0
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Service_Create
|
Sub Service_Create
|
||||||
'This is the program entry point.
|
'This is the program entry point.
|
||||||
'This is a good place to load resources that are not specific to a single activity.
|
'This is a good place to load resources that are not specific to a single activity.
|
||||||
|
s.Initialize(Me, "Subs") 'Inicializamos la clase Subs
|
||||||
gps.Initialize("GPS")
|
gps.Initialize("GPS")
|
||||||
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para Push FirebaseMessaging
|
|
||||||
Timer1.Initialize("Timer1", Interval * 1000)
|
Timer1.Initialize("Timer1", Interval * 1000)
|
||||||
Timer1.Enabled = True
|
Timer1.Enabled = True
|
||||||
' 'Para los Logs
|
' 'Para los Logs
|
||||||
#if RELEASE
|
#if RELEASE
|
||||||
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
|
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
|
||||||
#end if
|
#end if
|
||||||
logs.Initialize
|
logs.Initialize
|
||||||
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para Push FirebaseMessaging
|
' CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'Para Push FirebaseMessaging
|
||||||
@@ -53,7 +54,6 @@ End Sub
|
|||||||
Sub Service_Start (StartingIntent As Intent)
|
Sub Service_Start (StartingIntent As Intent)
|
||||||
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
|
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
|
||||||
Subs.revisaBD
|
Subs.revisaBD
|
||||||
' Log(marcaCel)
|
|
||||||
reqManager.Initialize(Me, server)
|
reqManager.Initialize(Me, server)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user