Files
2024-06-04 19:09:40 -06:00

228 lines
8.0 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=StaticCode
Version=11
@EndOfDesignText@
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
' Public GZip As GZipStrings
Private su As StringUtils
Dim phn As Phone
Dim devModel As String
Dim kmt As SQL 'Requiere la libreria "SQL"
' Dim wifi As MLwifi
Dim ssid As String 'ignore
Dim rutaMaxPoints As Int = 3000
Dim rutaHrsAtras As Int = 48
' Dim rutaInicioHoy As String = ""
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
'Trae un string con hora, minutos y segundos - HHmmss
Sub hmsKMT As String 'ignore
' Log(fecha)
Dim OrigFormat As String = DateTime.DateFormat 'save orig date format
DateTime.DateFormat="HHmmss"
Private nuevaHora As String=DateTime.Date(DateTime.Now)
DateTime.DateFormat=OrigFormat 'return to orig date format
' Log(nuevaFecha)
Return nuevaHora
End Sub
'Genera una notificacion con importancia alta
Sub notiHigh(title As String, body As String, activity As Object) 'ignore
Private notif As Notification
notif.Initialize2(notif.IMPORTANCE_HIGH)
notif.Icon = "icon"
notif.Vibrate = False
notif.Sound = False
notif.AutoCancel = True
Log("notiHigh: "&title)
notif.SetInfo(title, body, activity)
' Log("notiHigh SetInfo")
notif.Notify(777)
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
'Revisa que exista la BD y si es necesario crea algunas tablas dentro de ella
Sub revisaBD 'ignore
If Not(File.Exists(Starter.ruta, "kmt.db")) Then File.Copy(File.DirAssets, "kmt.db", Starter.ruta, "kmt.db")
If Not(kmt.IsInitialized) Then kmt.Initialize(Starter.ruta, "kmt.db", True)
' kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS RUTA_GPS(FECHA INTEGER, LAT TEXT, LON TEXT)")
' kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS UUC(fecha INTEGER, lat TEXT, lon TEXT)") 'LastKnownLocation
' kmt.ExecNonQuery("CREATE TABLE IF NOT EXISTS bitacora(fecha INTEGER, texto TEXT)") 'Bitacora
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
'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
'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)
' Log(" +++ +++ pFecha:"&parteFecha&" | pHora:"&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
'Hace visible 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
'Saca el usuario de la tabla USUARIOA
Sub dameUsuarioDeDB As String 'ignore
Private c As Cursor
Private u As String = "SinUsuario"
If Not(kmt.IsInitialized) Then revisaBD
c=kmt.ExecQuery("select USUARIO from usuarioa")
c.Position=0
If c.RowCount > 0 Then u = c.GetString("USUARIO")
c.Close
Return u
End Sub
Sub SetDivider(lv As ListView, Color As Int, Height As Int) 'ignore
Dim r As Reflector
r.Target = lv
Dim CD As ColorDrawable
CD.Initialize(Color, 0)
r.RunMethod4("setDivider", Array As Object(CD), Array As String("android.graphics.drawable.Drawable"))
r.RunMethod2("setDividerHeight", Height, "java.lang.int")
End Sub
'Centra un listview dentro de un elemento superior
Sub centraListView(elemento As ListView, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Centra un panel 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 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 boton dentro de un elemento superior
Sub centraBoton(elemento As Button, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
'Trae el cliente desde la BD.
Sub traeCliente As String 'ignore
Private cli As Cursor = Starter.skmt.ExecQuery("Select CUENTA from cuentaa")
cli.Position = 0
Private cl As String = cli.GetString("CUENTA")
cli.Close
Return cl
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)
Try 'Intentamos usar "pragma_table_info" para revisar si existe la columna en la tabla
Private c As Cursor = Starter.skmt.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
Starter.skmt.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
Starter.skmt.ExecNonQuery($"ALTER TABLE ${tabla} ADD COLUMN ${columna} ${tipo}"$)
Log($"Columna "${columna} ${tipo}", agregada a "${tabla}".."$)
Catch
Log(LastException)
End Try
End Try
End Sub