Files
DBCheck/B4A/Subs.bas

289 lines
9.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.
Private su As StringUtils 'Usa la libreria StringUtils 'ignore
End Sub
'Linea de prueba X10
'Convierte una fecha al formato yyMMddHHmmss
Sub fechaKMT(fecha As String) As String 'ignore
' if starter.logger then 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
' if starter.logger then Log(nuevaFecha)
Return nuevaFecha
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
' If Starter.logger Then 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
' if starter.logger then 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
' if starter.logger then Log("+++ +++ "&fechaKMT(fechaKMT2Ticks(hora) + mins * DateTime.TicksPerMinute) & " < " & fechaKMT(DateTime.Now))
Return True
Else
' if starter.logger then 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)
' If Starter.logger Then LogColor($"Fecha dada: ${fKMT}, Parte Fecha: ${parteFecha}, Parte Hora: ${parteHora}"$, Colors.Red)
Return 0
End Try
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
'Oculta el panel especificado y lo manda al fondo
Sub panelOculto(panel As Panel) 'ignore
panel.SendToBack
panel.Visible = False
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 dentro de un elemento superior
Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
End Sub
Sub centraEditText(elemento As EditText, anchoElementoSuperior As Int) 'ignore
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/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
'Modifica el ancho y alto de un panel dado con el ancho y alto proporcionados.
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
'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 el usuario de la tabla USUARIOA
Sub traeUsuarioDeBD As String 'ignore
Private c As Cursor
Private u As String = "SinUsuario"
c = B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
c.Position = 0
If c.RowCount > 0 Then u = c.GetString("USUARIO")
c.Close
Return u
End Sub
'Regresa el usuario de la tabla USUARIOA
Sub traeUsuario As String 'ignore
Private c As Cursor
Private u As String = "SinUsuario"
c = B4XPages.MainPage.skmt.ExecQuery("select USUARIO from usuarioa")
c.Position = 0
If c.RowCount > 0 Then u = c.GetString("USUARIO")
c.Close
Return u
End Sub
'Regresa la ruta actual de la base de datos.
Sub traeRuta As String 'ignore
Private c As Cursor
Private r As String
c = B4XPages.MainPage.skmt.ExecQuery("select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
r = "0"
If c.RowCount > 0 Then
c.Position=0
r = c.GetString("CAT_CL_RUTA")
End If
c.Close
Return r
End Sub
'Regresa la ruta actual de la base de datos.
Sub traeRuta2 (cliente As String) As String 'ignore
Private c As Cursor
Private r As String
c=B4XPages.MainPage.skmt.ExecQuery($"select CAT_CL_RUTA from kmt_info where CAT_CL_CODIGO = '${cliente}' UNION ALL select CAT_CL_RUTA from kmt_info2 where CAT_CL_CODIGO = '${cliente}'"$)
r = "0"
If c.RowCount > 0 Then
c.Position=0
r = c.GetString("CAT_CL_RUTA")
End If
c.Close
Return r
End Sub
'Regresa la ruta del cliente dado de la tabla pedido.
Sub traeRutaPedidoCliente(idcliente As String) As String 'ignore
Private r As String
Private c As Cursor = B4XPages.MainPage.skmt.ExecQuery($"select PE_RUTA from pedido where PE_CLIENTE = '${idcliente}'"$)
r = "0"
If c.RowCount > 0 Then
c.Position = 0
r = c.GetString("PE_RUTA")
End If
c.Close
Return r
End Sub
'Regresa el cliente actual desde CUENTAA.
Sub traeCliente As String 'ignore
Private c As Cursor
Private cl As String
c = B4XPages.MainPage.skmt.ExecQuery("Select CUENTA from cuentaa")
c.Position = 0
cl = c.GetString("CUENTA")
c.Close
Return cl
End Sub
'Regresa el almacen actual de la base de datos.
Sub traeAlmacen As String 'ignore
Private c As Cursor
Private a As String
c = B4XPages.MainPage.skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
c.Position = 0
a = C.GetString("ID_ALMACEN")
c.Close
Return a
End Sub
'Muestra en el Log los campos y valores que regresan en el JobDone.
Sub logJobDoneResultados(resultado As DBResult)
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
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
Sub parseHTTPError(error As String) As String
Private nuevoError As String = error
Private inicio As Int = error.IndexOf("<title>")
Private final As Int = error.IndexOf("</title>")
Log("|" & inicio & "|" & final & "|")
If inicio > 0 And final > 0 Then
nuevoError = error.SubString2(inicio + 17, final)
' LogColor(error.SubString2(inicio + 17, final), Colors.Blue)
End If
Return nuevoError
End Sub
'Trae el precio del ID dado, desde CAT_GUNAPROD o HIST_VENTAS, dependiendo de si es promoción o no Y CAJAS.
Sub traeConversion(id As String) As String
Private pu As String = "0"
Private idc As Cursor = B4XPages.MainPage.skmt.ExecQuery($"select CONVERSION from CAT_GUNAPROD where CAT_GP_ID = '${id}'"$)
If idc.RowCount > 0 Then
idc.Position=0
If idc.RowCount > 0 And IsNumber(idc.GetString("CONVERSION")) Then pu = idc.GetString("CONVERSION")
' Log("id=" & id & "|p=" & x & "|" & idc.GetString("CAT_GP_PRECIO"))
End If
idc.Close
Return pu
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