Commit inicial de Java
24
B4J/C_Principal.bas
Normal file
@@ -0,0 +1,24 @@
|
||||
B4J=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=10
|
||||
@EndOfDesignText@
|
||||
Sub Class_Globals
|
||||
Private Root As B4XView 'ignore
|
||||
Private xui As XUI 'ignore
|
||||
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
|
||||
|
||||
End Sub
|
||||
|
||||
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
|
||||
272
B4J/DBRequestManager.bas
Normal file
@@ -0,0 +1,272 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=6.8
|
||||
@EndOfDesignText@
|
||||
'Class module
|
||||
' Requiere RandomAccessFile, CompressStrings, ByteConverter y OkhttpUtils2
|
||||
Sub Class_Globals
|
||||
Private mTarget As Object
|
||||
Type DBResult (Tag As Object, Columns As Map, Rows As List)
|
||||
Type DBCommand (Name As String, Parameters() As Object)
|
||||
Private link As String
|
||||
Private bc As ByteConverter
|
||||
Private T_NULL = 0, T_STRING = 1, T_SHORT = 2, T_INT = 3, T_LONG = 4, T_FLOAT = 5 _
|
||||
,T_DOUBLE = 6, T_BOOLEAN = 7, T_BLOB = 8 As Byte
|
||||
Private VERSION As Float = 0.9
|
||||
Private tempArray(1) As Object
|
||||
Dim jobTagAnterior As String = "" 'Mod por CHV - 211109
|
||||
End Sub
|
||||
|
||||
'Target - The module that handles JobDone (usually Me).
|
||||
'ConnectorLink - URL of the Java server.
|
||||
Public Sub Initialize (Target As Object, ConnectorLink As String)
|
||||
mTarget = Target
|
||||
link = ConnectorLink
|
||||
End Sub
|
||||
|
||||
'Sends a query request.
|
||||
'Command - Query name and parameters.
|
||||
'Limit - Maximum rows to return or 0 for no limit.
|
||||
'Tag - An object that will be returned in the result.
|
||||
'Timeout - The http request timeout in ms, or 0 if default (30 secs)
|
||||
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object, Timeout As Int) 'Mod por CHV, agregué el parametro Timeout - 211229
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
WriteObject(Command.Name, out2)
|
||||
WriteInt(Limit, out2)
|
||||
WriteList(Command.Parameters, out2)
|
||||
out2.Close
|
||||
j.PostBytes(link & "?method=query", ms.ToBytesArray)
|
||||
If Timeout <> 0 Then j.GetRequest.Timeout = Timeout
|
||||
End Sub
|
||||
|
||||
'Executes a batch of (non-select) commands.
|
||||
'ListOfCommands - List of the commands that will be executes.
|
||||
'Tag - An object that will be returned in the result.
|
||||
Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object)
|
||||
Dim j As HttpJob
|
||||
Dim ms As OutputStream
|
||||
Dim out2 As OutputStream = StartJob(j,ms, Tag)
|
||||
WriteInt(ListOfCommands.Size, out2)
|
||||
For Each Command As DBCommand In ListOfCommands
|
||||
WriteObject(Command.Name, out2)
|
||||
WriteList(Command.Parameters, out2)
|
||||
Next
|
||||
out2.Close
|
||||
j.PostBytes(link & "?method=batch", ms.ToBytesArray)
|
||||
End Sub
|
||||
|
||||
'Similar to ExecuteBatch. Sends a single command.
|
||||
Public Sub ExecuteCommand(Command As DBCommand, Tag As Object)
|
||||
ExecuteBatch(Array As DBCommand(Command), Tag)
|
||||
End Sub
|
||||
|
||||
Private Sub StartJob(j As HttpJob, MemoryStream As OutputStream, Tag As Object) As OutputStream
|
||||
j.Initialize("DBRequest", mTarget)
|
||||
j.Tag = Tag
|
||||
MemoryStream.InitializeToBytesArray(0)
|
||||
Dim compress As CompressedStreams
|
||||
Dim out As OutputStream = compress.WrapOutputStream(MemoryStream, "gzip")
|
||||
WriteObject(VERSION, out)
|
||||
Return out
|
||||
End Sub
|
||||
|
||||
Private Sub WriteList(Parameters As List, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
If Parameters = Null Or Parameters.IsInitialized = False Then
|
||||
Dim Parameters As List
|
||||
Parameters.Initialize
|
||||
End If
|
||||
data = bc.IntsToBytes(Array As Int(Parameters.Size))
|
||||
out.WriteBytes(data, 0, data.Length)
|
||||
For Each o As Object In Parameters
|
||||
WriteObject(o, out)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Private Sub WriteObject(o As Object, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
tempArray(0) = o
|
||||
If tempArray(0) = Null Then
|
||||
out.WriteBytes(Array As Byte(T_NULL), 0, 1)
|
||||
Else If tempArray(0) Is Short Then
|
||||
out.WriteBytes(Array As Byte(T_SHORT), 0, 1)
|
||||
data = bc.ShortsToBytes(Array As Short(o))
|
||||
Else If tempArray(0) Is Int Then
|
||||
out.WriteBytes(Array As Byte(T_INT), 0, 1)
|
||||
data = bc.IntsToBytes(Array As Int(o))
|
||||
Else If tempArray(0) Is Float Then
|
||||
out.WriteBytes(Array As Byte(T_FLOAT), 0, 1)
|
||||
data = bc.FloatsToBytes(Array As Float(o))
|
||||
Else If tempArray(0) Is Double Then
|
||||
out.WriteBytes(Array As Byte(T_DOUBLE), 0, 1)
|
||||
data = bc.DoublesToBytes(Array As Double(o))
|
||||
Else If tempArray(0) Is Long Then
|
||||
out.WriteBytes(Array As Byte(T_LONG), 0, 1)
|
||||
data = bc.LongsToBytes(Array As Long(o))
|
||||
Else If tempArray(0) Is Boolean Then
|
||||
out.WriteBytes(Array As Byte(T_BOOLEAN), 0, 1)
|
||||
Dim b As Boolean = 0
|
||||
Dim data(1) As Byte
|
||||
If b Then data(0) = 1 Else data(0) = 0
|
||||
Else If GetType(tempArray(0)) = "[B" Then
|
||||
data = o
|
||||
out.WriteBytes(Array As Byte(T_BLOB), 0, 1)
|
||||
WriteInt(data.Length, out)
|
||||
Else 'If o Is String Then (treat all other values as string)
|
||||
out.WriteBytes(Array As Byte(T_STRING), 0, 1)
|
||||
data = bc.StringToBytes(o, "UTF8")
|
||||
WriteInt(data.Length, out)
|
||||
End If
|
||||
If data.Length > 0 Then out.WriteBytes(data, 0, data.Length)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadObject(In As InputStream) As Object
|
||||
Dim data(1) As Byte
|
||||
In.ReadBytes(data, 0, 1)
|
||||
Select data(0)
|
||||
Case T_NULL
|
||||
Return Null
|
||||
Case T_SHORT
|
||||
Dim data(2) As Byte
|
||||
Return bc.ShortsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_INT
|
||||
Dim data(4) As Byte
|
||||
Return bc.IntsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_LONG
|
||||
Dim data(8) As Byte
|
||||
Return bc.LongsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_FLOAT
|
||||
Dim data(4) As Byte
|
||||
Return bc.FloatsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_DOUBLE
|
||||
Dim data(8) As Byte
|
||||
Return bc.DoublesFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
Case T_BOOLEAN
|
||||
Dim b As Byte = ReadByte(In)
|
||||
Return b = 1
|
||||
Case T_BLOB
|
||||
Dim len As Int = ReadInt(In)
|
||||
Dim data(len) As Byte
|
||||
Return ReadBytesFully(In, data, data.Length)
|
||||
Case Else
|
||||
Dim len As Int = ReadInt(In)
|
||||
Dim data(len) As Byte
|
||||
ReadBytesFully(In, data, data.Length)
|
||||
Return BytesToString(data, 0, data.Length, "UTF8")
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub ReadBytesFully(In As InputStream, Data() As Byte, Len As Int) As Byte()
|
||||
Dim count = 0, read As Int
|
||||
Do While count < Len And read > -1
|
||||
read = In.ReadBytes(Data, count, Len - count)
|
||||
count = count + read
|
||||
Loop
|
||||
Return Data
|
||||
End Sub
|
||||
|
||||
Private Sub WriteInt(i As Int, out As OutputStream)
|
||||
Dim data() As Byte
|
||||
data = bc.IntsToBytes(Array As Int(i))
|
||||
out.WriteBytes(data, 0, data.Length)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadInt(In As InputStream) As Int
|
||||
Dim data(4) As Byte
|
||||
Return bc.IntsFromBytes(ReadBytesFully(In, data, data.Length))(0)
|
||||
End Sub
|
||||
|
||||
Private Sub ReadByte(In As InputStream) As Byte
|
||||
Dim data(1) As Byte
|
||||
In.ReadBytes(data, 0, 1)
|
||||
Return data(0)
|
||||
End Sub
|
||||
|
||||
'Handles the Job result and returns a DBResult.
|
||||
Public Sub HandleJob(Job As HttpJob) As DBResult
|
||||
Dim start As Long = DateTime.Now 'ignore
|
||||
Dim In As InputStream = Job.GetInputStream
|
||||
Dim cs As CompressedStreams
|
||||
In = cs.WrapInputStream(In, "gzip")
|
||||
Dim serverVersion As Float = ReadObject(In) 'ignore
|
||||
Dim method As String = ReadObject(In)
|
||||
Dim table As DBResult
|
||||
table.Initialize
|
||||
table.Columns.Initialize
|
||||
table.rows.Initialize
|
||||
table.Tag = Job.Tag
|
||||
If jobTagAnterior <> Job.Tag Then Log("HandleJob: '"&Job.Tag&"'") 'Mod por CHV - 211109
|
||||
jobTagAnterior = Job.Tag 'Mod por CHV - 211109
|
||||
If method = "query" Then
|
||||
Dim numberOfColumns As Int = ReadInt(In)
|
||||
For i = 0 To numberOfColumns - 1
|
||||
table.Columns.Put(ReadObject(In), i)
|
||||
Next
|
||||
Do While ReadByte(In) = 1
|
||||
Dim rowObjects(numberOfColumns) As Object
|
||||
table.rows.Add(rowObjects)
|
||||
For col = 0 To numberOfColumns - 1
|
||||
Dim o As Object = ReadObject(In)
|
||||
rowObjects(col) = o
|
||||
Next
|
||||
Loop
|
||||
Else If method = "batch" Then
|
||||
table.Columns.Put("AffectedRows", 0)
|
||||
Dim rows As Int = ReadInt(In)
|
||||
For i = 0 To rows - 1
|
||||
table.rows.Add(Array As Object(ReadInt(In)))
|
||||
Next
|
||||
End If
|
||||
In.Close
|
||||
' Log("HandleJob: " & (DateTime.Now - start))'Comentado por CHV - 211112
|
||||
Return table
|
||||
End Sub
|
||||
'Reads a file and returns the file as a bytes array.
|
||||
Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
|
||||
Dim out As OutputStream
|
||||
out.InitializeToBytesArray(0)
|
||||
Dim In As InputStream = File.OpenInput(Dir, FileName)
|
||||
File.Copy2(In, out)
|
||||
out.Close
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
'Converts an image to a bytes array (for BLOB fields).
|
||||
'Public Sub ImageToBytes(Image As Bitmap) As Byte()
|
||||
' Dim out As OutputStream
|
||||
' out.InitializeToBytesArray(0)
|
||||
' Image.WriteToStream(out, 100, "JPEG")
|
||||
' out.Close
|
||||
' Return out.ToBytesArray
|
||||
'End Sub
|
||||
''Converts a bytes array to an image (for BLOB fields).
|
||||
'Public Sub BytesToImage(bytes() As Byte) As Bitmap
|
||||
' Dim In As InputStream
|
||||
' In.InitializeFromBytesArray(bytes, 0, bytes.Length)
|
||||
' Dim bmp As Bitmap
|
||||
' bmp.Initialize2(In)
|
||||
' Return bmp
|
||||
'End Sub
|
||||
'Prints the table to the logs.
|
||||
Public Sub PrintTable(Table As DBResult)
|
||||
Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
|
||||
Dim sb As StringBuilder
|
||||
sb.Initialize
|
||||
For Each col In Table.Columns.Keys
|
||||
sb.Append(col).Append(TAB)
|
||||
Next
|
||||
Log(sb.ToString)
|
||||
For Each row() As Object In Table.Rows
|
||||
Dim sb As StringBuilder
|
||||
sb.Initialize
|
||||
For Each record As Object In row
|
||||
sb.Append(record).Append(TAB)
|
||||
Next
|
||||
' ToastMessageShow(sb.ToString, True)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
BIN
B4J/Files/MainPage.bjl
Normal file
BIN
B4J/Files/candado.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
B4J/Files/engrane.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
B4J/Files/engrane_fondoblanco.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
B4J/Files/engranes.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
B4J/Files/errorLog.db
Normal file
BIN
B4J/Files/kmt.db
Normal file
BIN
B4J/Files/login.bjl
Normal file
BIN
B4J/Files/logolanter.bmp
Normal file
|
After Width: | Height: | Size: 147 KiB |
BIN
B4J/Files/logolanter.png
Normal file
|
After Width: | Height: | Size: 62 KiB |
BIN
B4J/Files/logolanter2.bmp
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
B4J/Files/logolanter_192x192.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
B4J/Files/logolanternegro.bmp
Normal file
|
After Width: | Height: | Size: 149 KiB |
BIN
B4J/Files/logolanternegro.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
B4J/Files/logolanternegro2.bmp
Normal file
|
After Width: | Height: | Size: 94 KiB |
BIN
B4J/Files/mesasItem.bjl
Normal file
BIN
B4J/Files/usuario.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
1566
B4J/Subs.bas
Normal file
100
B4J/lanterna.b4j
Normal file
@@ -0,0 +1,100 @@
|
||||
AppType=JavaFX
|
||||
Build1=Default,b4j.example
|
||||
File1=candado.png
|
||||
File10=logolanter_192x192.png
|
||||
File11=logolanter2.bmp
|
||||
File12=logolanternegro.bmp
|
||||
File13=logolanternegro.png
|
||||
File14=logolanternegro2.bmp
|
||||
File15=MainPage.bjl
|
||||
File16=mesasItem.bjl
|
||||
File17=usuario.png
|
||||
File2=engrane.png
|
||||
File3=engrane_fondoblanco.png
|
||||
File4=engranes.png
|
||||
File5=errorLog.db
|
||||
File6=kmt.db
|
||||
File7=login.bjl
|
||||
File8=logolanter.bmp
|
||||
File9=logolanter.png
|
||||
FileGroup1=Default Group
|
||||
FileGroup10=Default Group
|
||||
FileGroup11=Default Group
|
||||
FileGroup12=Default Group
|
||||
FileGroup13=Default Group
|
||||
FileGroup14=Default Group
|
||||
FileGroup15=New Group
|
||||
FileGroup16=Default Group
|
||||
FileGroup17=Default Group
|
||||
FileGroup2=Default Group
|
||||
FileGroup3=Default Group
|
||||
FileGroup4=Default Group
|
||||
FileGroup5=Default Group
|
||||
FileGroup6=Default Group
|
||||
FileGroup7=Default Group
|
||||
FileGroup8=Default Group
|
||||
FileGroup9=Default Group
|
||||
Group=Default Group
|
||||
Library1=b4xpages
|
||||
Library10=jstringutils
|
||||
Library11=wobblemenu
|
||||
Library12=xcustomlistview
|
||||
Library2=byteconverter
|
||||
Library3=compressstrings
|
||||
Library4=jcore
|
||||
Library5=jfx
|
||||
Library6=jokhttputils2
|
||||
Library7=jrandomaccessfile
|
||||
Library8=json
|
||||
Library9=jsql
|
||||
Module1=|relative|..\B4XMainPage
|
||||
Module2=C_Principal
|
||||
Module3=DBRequestManager
|
||||
Module4=Subs
|
||||
NumberOfFiles=17
|
||||
NumberOfLibraries=12
|
||||
NumberOfModules=4
|
||||
Version=10
|
||||
@EndOfDesignText@
|
||||
#Region Project Attributes
|
||||
#MainFormWidth: 600
|
||||
#MainFormHeight: 600
|
||||
#AdditionalJar: sqlite-jdbc-3.7.2.jar
|
||||
#End Region
|
||||
|
||||
Sub Process_Globals
|
||||
Private fx As JFX
|
||||
Private MainForm As Form
|
||||
End Sub
|
||||
|
||||
Sub AppStart (Form1 As Form, Args() As String)
|
||||
MainForm = Form1
|
||||
' Log(MainForm.Width)
|
||||
MainForm.Show
|
||||
Dim PagesManager As B4XPagesManager
|
||||
PagesManager.Initialize(MainForm)
|
||||
End Sub
|
||||
|
||||
'Template version: B4J-1.0
|
||||
#Region Delegates
|
||||
Sub MainForm_FocusChanged (HasFocus As Boolean)
|
||||
B4XPages.Delegate.MainForm_FocusChanged(HasFocus)
|
||||
End Sub
|
||||
|
||||
Sub MainForm_Resize (Width As Double, Height As Double)
|
||||
B4XPages.Delegate.MainForm_Resize(Width, Height)
|
||||
End Sub
|
||||
|
||||
Sub MainForm_Closed
|
||||
B4XPages.Delegate.MainForm_Closed
|
||||
End Sub
|
||||
|
||||
Sub MainForm_CloseRequest (EventData As Event)
|
||||
B4XPages.Delegate.MainForm_CloseRequest(EventData)
|
||||
End Sub
|
||||
|
||||
Public Sub MainForm_IconifiedChanged (Iconified As Boolean)
|
||||
B4XPages.Delegate.MainForm_IconifiedChanged(Iconified)
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
18
B4J/lanterna.b4j.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks2=
|
||||
ModuleBookmarks3=
|
||||
ModuleBookmarks4=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints2=
|
||||
ModuleBreakpoints3=
|
||||
ModuleBreakpoints4=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=40,41
|
||||
ModuleClosedNodes2=
|
||||
ModuleClosedNodes3=
|
||||
ModuleClosedNodes4=
|
||||
NavigationStack=Main,Process_Globals,8,0,B4XMainPage,b_cerrarApp_Click,620,0,B4XMainPage,Class_Globals,96,0,Subs,revisaMaxPromosProdsFijosPorInventario2,1008,0,Visual Designer,login.bjl,-100,6,B4XMainPage,b_cerrarCerrar_Click,651,0,B4XMainPage,b_abrirMesa_Click,586,0,B4XMainPage,lv_categorias_MouseClicked,607,0,B4XMainPage,lv_categorias_SelectedIndexChanged,605,6,B4XMainPage,llenaProdsLL,530,0,B4XMainPage,p_mesasItem_MouseClicked,524,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=1,4,2,3
|
||||
9
B4J/lanterna.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleClosedNodes0=1,4
|
||||
ModuleClosedNodes1=1
|
||||
NavigationStack=Main,MainForm_IconifiedChanged,37,0,Main,AppStart,14,6,B4XMainPage,Button1_Click,19,0,B4XMainPage,Initialize,9,0,B4XMainPage,B4XPage_Created,18,0,B4XMainPage,Class_Globals,7,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=1
|
||||