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 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