Files
Guna_CuentaKilometros_2/B4A/C_Principal.bas

522 lines
15 KiB
QBasic

B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=12.2
@EndOfDesignText@
Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Dim reqManager As DBRequestManager
Dim b_mapa As Button
Dim l_ruta As Label
Private inv As Button
Private p_principal As Panel
Dim ime As IME
Private et_placas As EditText
Private et_operador As EditText
Private et_rutaReparto As EditText
' et_rutaReparto.InputType=et_rutaReparto.INPUT_TYPE_NUMBERS
Private b_guardar As Button
Private ImageView1 As ImageView
Private ImageView1 As ImageView
Private p_datos As Panel
Private p_camara As Panel
Private b_cerrar As Button
Private pnlPreview As Panel
Private camEx As CameraExClass
Private toast As BCToast
Private Capturing As Boolean
Private rp As RuntimePermissions
Private detector As JavaObject
Private camEx As CameraExClass
Private LastPreview As Long
Private IntervalBetweenPreviewsMs As Int = 100
Dim codigoencontrado, codigoBuscado As String
Private b_escanRuta As Button
Private b_escanOperador As Button
Private b_escanPlacas As Button
Private et_kmsInicial As EditText
Private et_kmsFinal As EditText
Private B_Color As Button
Private P_Color As Panel
Dim OPERADOR_OK As String
Dim CHECK_LIST As String
Dim PLACA_OK As String
Dim CARTAPORTE_OK As String
Dim c As Cursor
Dim count As Int = 0
Dim count2 As Int = 0
Dim ime As IME
Private L_Color As Label
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
'load the layout to Root
Root.LoadLayout("principal")
reqManager.Initialize(Me, Starter.server)
B4XPages.MainPage.usuario=Subs.dameUsuarioDeDB
'Inicia camara
p_camara.Width = Root.Width
p_camara.Height= Root.Height
p_camara.Visible = False
toast.Initialize(Root)
StopCamera
B4XPages.SetTitle(Me, "Barcode Example")
CreateDetector (Array("AZTEC", "CODE_128", "CODE_39", "CODE_93", "CODABAR", "DATA_MATRIX", "EAN_13", "EAN_8", "ITF", "PDF417", "QR_CODE", "UPC_A", "UPC_E"))
'Termina camara
End Sub
Sub B4XPage_Appear
Subs.centraPanel(p_principal, Root.Width)
P_Color.Height = Root.Height
End Sub
Sub JobDone(Job As HttpJob)
' Private r As DBResult = reqManager.HandleJob(Job)
If Job.Success = False Then
LogColor("** " & Job.Tag & " Error: " & Job.ErrorMessage, Colors.Red) ' Mod by CHV - 211023
'ToastMessageShow("Error: " & Job.ErrorMessage, True)
Else
LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211023
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "ins_rechazos" Then 'query tag
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log(k & ": " & records(result.Columns.Get(k)))
Next
Next
End If
End If
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "PLACA_OK" Then 'query tag
count = count+1
PLACA_OK = 0
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log(k & ": " & records(result.Columns.Get(k)))
PLACA_OK= records(result.Columns.Get("INFO_OK"))
Next
Next
If PLACA_OK = "OK" Then
count2 = count2+1
End If
End If
End If
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "CheckList_OK" Then 'query tag
count = count+1
CHECK_LIST = 0
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log(k & ": " & records(result.Columns.Get(k)))
CHECK_LIST= records(result.Columns.Get("'OK'"))
Next
Next
If CHECK_LIST = "OK" Then
count2 = count2+1
End If
End If
End If
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "Operador_OK" Then 'query tag
count = count+1
OPERADOR_OK = 0
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log(k & ": " & records(result.Columns.Get(k)))
OPERADOR_OK = records(result.Columns.Get("INFO_OK"))
Next
Next
If OPERADOR_OK = "OK" Then
count2 = count2+1
End If
End If
End If
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "CartaPorte_OK" Then 'query tag
count = count+1
CARTAPORTE_OK = 0
For Each records() As Object In result.Rows
For Each k As String In result.Columns.Keys
Log(k & ": |" & records(result.Columns.Get(k))&"|")
CARTAPORTE_OK= records(result.Columns.Get("INFO_OK"))
Next
Next
If CARTAPORTE_OK = "OK" Then
count2 = count2+1
End If
End If
End If
' Log($"placa:${PLACA_OK}, operador:${OPERADOR_OK}, checklist:${CHECK_LIST}, cp:${CARTAPORTE_OK}"$)
If count = 4 Then
If count2 = 4 Then
P_Color.Visible = True
P_Color.Color = Colors.Green
L_Color.Visible = True
Else If PLACA_OK = "OK" And OPERADOR_OK = "OK" And CHECK_LIST <> "OK" And CARTAPORTE_OK = "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Yellow
L_Color.Visible = False
MsgboxAsync("Favor de revisar el CheckList", "AVISO")
Else If count2 < 4 Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
If PLACA_OK <> "OK" And OPERADOR_OK <> "OK" And CHECK_LIST <> "OK" And CARTAPORTE_OK = "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("Revisa La Placa", "AVISO")
Else If PLACA_OK = "OK" And OPERADOR_OK <> "OK" And CHECK_LIST = "OK" And CARTAPORTE_OK = "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("Revisa El Operador", "AVISO")
Else if PLACA_OK <> "OK" And OPERADOR_OK <> "OK" And CHECK_LIST = "OK" And CARTAPORTE_OK <> "OK" And count2 = 1 Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("No hay Carta Porte para esa Ruta", "AVISO")
Else If PLACA_OK <> "OK" And OPERADOR_OK <> "OK" And CHECK_LIST = "OK" And CARTAPORTE_OK = "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("La Placa o el Operador no coinsiden con CheckList y Carta Porte", "AVISO")
End If
End If
If PLACA_OK = "OK" And OPERADOR_OK = "OK" And CHECK_LIST = "OK" And CARTAPORTE_OK <> "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("No se encuentra Carta Porte", "AVISO")
End If
If PLACA_OK <> "OK" And OPERADOR_OK <> "OK" And CHECK_LIST <> "OK" And CARTAPORTE_OK <> "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("No se encuentran Placas, Operador, CheckList, CartaPorte", "AVISO")
End If
If PLACA_OK = "OK" And OPERADOR_OK = "OK" And CHECK_LIST <> "OK" And CARTAPORTE_OK <> "OK" Then
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("No se encuentran CheckList y CartaPorte", "AVISO")
End If
End If
Job.Release
End If
End Sub
Private Sub B4XPage_CloseRequest As ResumableSub
' BACK key pressed
If P_Color.Visible Then
P_Color.Visible = False
Else
B4XPages.ShowPage("Login")
End If
' Returning False signals the system to handle the key
Return False
End Sub
'Inicia camara
Private Sub B4XPage_Disappear
If p_camara.Visible = True Then
p_camara.Visible = False
StopCamera
End If
End Sub
Sub btnStartStop_Click
If Capturing = False Then
p_camara.Visible = True
StartCamera
Else
p_camara.Visible = False
StopCamera
End If
End Sub
Private Sub B_cerrar_Click
' If et_codigo.Text.Length = 0 Then
' p_camara.Visible = False
' Else
' p_camara.Visible = False
' et_codigo_EnterPressed
' End If
StopCamera
p_camara.Visible = False
End Sub
Private Sub StopCamera
' et_codigo.Text = ""
Capturing = False
pnlPreview.Visible = False
If camEx.IsInitialized Then
camEx.Release
End If
End Sub
Private Sub StartCameraShared
pnlPreview.Visible = True
Capturing = True
End Sub
Private Sub FoundBarcode (msg As String)
' et_codigo.Text = msg
toast.Show($"Found [Color=Red][b][plain]${msg}[/plain][/b][/Color]"$)
Log(msg)
codigoencontrado = msg
Log($"${codigoencontrado}, ${codigoBuscado}"$)
If codigoBuscado = "placas" Then
et_placas.text = codigoencontrado
Else If codigoBuscado = "operador" Then
Log("ponemos operador en HOLA")
et_operador.text = codigoencontrado
Else If codigoBuscado = "ruta" Then
et_rutaReparto.text = codigoencontrado
End If
' If et_codigo.Text.Length > 1 Then
B_cerrar_Click
' End If
End Sub
Private Sub StartCamera
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
toast.Show("No permission!")
Return
End If
StartCameraShared
camEx.Initialize(pnlPreview, False, Me, "Camera1")
Wait For Camera1_Ready (Success As Boolean)
If Success Then
camEx.SetContinuousAutoFocus
camEx.CommitParameters
camEx.StartPreview
Else
toast.Show("Error opening camera")
StopCamera
End If
End Sub
Private Sub CreateDetector (Codes As List)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim builder As JavaObject
builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
Dim barcodeStatic As JavaObject
barcodeStatic.InitializeStatic(barcodeClass)
Dim format As Int
For Each formatName As String In Codes
format = Bit.Or(format, barcodeStatic.GetField(formatName))
Next
builder.RunMethod("setBarcodeFormats", Array(format))
detector = builder.RunMethod("build", Null)
Dim operational As Boolean = detector.RunMethod("isOperational", Null)
If operational = False Then
toast.Show("Failed to create detector")
End If
b_escanOperador.Enabled = operational
b_escanPlacas.Enabled = operational
b_escanRuta.Enabled = operational
End Sub
Private Sub Camera1_Preview (data() As Byte)
If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
'Dim n As Long = DateTime.Now
Dim frameBuilder As JavaObject
Dim bb As JavaObject
bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
Dim cs As CameraSize = camEx.GetPreviewSize
frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height, 842094169))
Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
LastPreview = DateTime.Now
Dim Matches As Int = SparseArray.RunMethod("size", Null)
If Matches > 0 Then
Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(0))
Dim raw As String = barcode.GetField("rawValue")
FoundBarcode(raw)
End If
End If
End Sub
'fin camara
Private Sub b_guardar_Click
count = 0
count2 = 0
ime.HideKeyboard
Starter.skmt.ExecNonQuery($"insert into CONTROL_KMS (PLACAS, OPERADOR, RUTA, KMS_INICIAL, KMS_FINAL) values ('${et_placas.text}', '${et_operador.text}', '${et_rutaReparto.text}', '${et_kmsInicial.text}', '${et_kmsFinal.text}')"$)
Dim ValDato As List
ValDato.Initialize
If et_placas.Text = "" Then
ValDato.Add("Las placas")
End If
If et_operador.Text = "" Then
ValDato.Add("el operador")
End If
If et_rutaReparto.Text = "" Then
ValDato.Add("la ruta")
End If
If et_kmsInicial.Text = "" Then
ValDato.Add("el Kilometraje Inicial")
End If
If ValDato.Size > 0 Then
Dim MS As String
If ValDato.Size = 1 Then
MS = ValDato.Get(0) & " debe ser obligatorio"
Else
MS = JoinStrings(ValDato, ", ") & " deben ser obligatorios"
End If
MsgboxAsync(MS, "AVISO")
Else if IsNumber(et_rutaReparto.Text) Then
c = Starter.skmt.ExecQuery("select ID_ALMACEN from CAT_ALMACEN")
c.Position = 0
Dim ALM_ENV = c.GetString ("ID_ALMACEN")
c.Close
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "select_placa_GUNA"
cmd.Parameters = Array As Object(et_placas.Text, et_rutaReparto.Text, ALM_ENV)
Log(et_placas.Text & " ," & et_rutaReparto.Text & " ," & ALM_ENV)
reqManager.ExecuteQuery(cmd , 0, "PLACA_OK")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "select_Operador_GUNA"
cmd.Parameters = Array As Object(et_placas.Text, et_operador.Text, et_rutaReparto.Text, ALM_ENV)
Log(et_placas.Text & " ," & et_operador.Text & " ," & et_rutaReparto.Text & " ," & ALM_ENV)
reqManager.ExecuteQuery(cmd , 0, "Operador_OK")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "select_CheckList_GUNA"
cmd.Parameters = Array As Object(et_placas.Text)
Log(et_placas.Text)
reqManager.ExecuteQuery(cmd , 0, "CheckList_OK")
Dim cmd As DBCommand
cmd.Initialize
cmd.Name = "select_CartaPorte_GUNA"
cmd.Parameters = Array As Object(et_rutaReparto.Text, ALM_ENV)
Log(et_rutaReparto.Text & " ," & ALM_ENV)
reqManager.ExecuteQuery(cmd , 0, "CartaPorte_OK")
Else
P_Color.Visible = True
P_Color.Color = Colors.Red
L_Color.Visible = False
MsgboxAsync("Las Ruta debe ser numerica", "AVISO")
End If
End Sub
Sub JoinStrings(list As List, delimiter As String) As String
Dim result As String
For Each item As String In list
If result.Length > 0 Then
result = result & delimiter & " "
End If
result = result & item
Next
Return result
End Sub
Private Sub B_Color_Click
If P_Color.Visible = True Then
P_Color.Visible = False
' b_guardar.Visible = True
End If
End Sub
Private Sub pnlPreview_Click
End Sub
Private Sub p_camara_Click
End Sub
Private Sub b_escanPlacas_Click
ime.HideKeyboard
codigoBuscado = "placas"
Subs.panelVisible(p_camara, 0, 0)
If Capturing = False Then
p_camara.Visible = True
StartCamera
Else
p_camara.Visible = False
StopCamera
End If
End Sub
Private Sub b_escanOperador_Click
ime.HideKeyboard
codigoBuscado = "operador"
Subs.panelVisible(p_camara, 0, 0)
If Capturing = False Then
p_camara.Visible = True
StartCamera
Else
p_camara.Visible = False
StopCamera
End If
End Sub
Private Sub b_escanRuta_Click
ime.HideKeyboard
codigoBuscado = "ruta"
Subs.panelVisible(p_camara, 0, 0)
If Capturing = False Then
p_camara.Visible = True
StartCamera
Else
p_camara.Visible = False
StopCamera
End If
End Sub
Private Sub et_rutaReparto_TextChanged (Old As String, New As String)
If New.Length > 4 Then
et_rutaReparto.Text = Old
End If
End Sub
Private Sub et_kmsInicial_TextChanged (Old As String, New As String)
If New.Length > 6 Then
et_kmsInicial.Text = Old
End If
End Sub