Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private btnfile As Button
Private TextField1 As TextField
Private fc As FileChooser
Private btnsave As Button
Private reqManager As DBRequestManager
'Define the result from a query. The columns and Rows to be used further, like listing in a tableview
Type DBResult (Tag As Object, Columns As Map, Rows As List)
'The database commands are defined in the RDC config.properties file
Type DBCommand (Name As String, Parameters() As Object)
Private btnOpen As Button
Private ImageView1 As ImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
fc.Initialize
reqManager.Initialize(Me, "http://localhost:17178/rdc")
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
End Sub
Sub btnfile_MouseClicked (EventData As MouseEvent)
'------------------------------------------------------------------------------
Dim fc As FileChooser
fc.Initialize
fc.Title="Select Photo"
fc.InitialDirectory = "C:\Users\MicroboxMac\Pictures\Saved Pictures"
fc.SetExtensionFilter("Image",Array As String("*.jpg","*.png","*.bmp"))
Dim f As String = fc.ShowOpen(MainForm)
If f <> "" Then
Dim BlobedImage As String = ImageToBlob(f)
'------------------------------------------------------------------------
Dim cmd As DBCommand
cmd.Initialize
'Defined as sql.insert in the RDC file config.properties located in the files folder
cmd.Name = "insert"
'Set the parameter defined as sql.insert=INSERT INTO notes (description, content) VALUES(?, ?)
cmd.Parameters = Array As Object("Test1", BlobedImage)
'Trigger the command. The result is handled by JobDone.
reqManager.ExecuteCommand(cmd, "insert")
Log("Insert table Triggered")
End If
'-------------------------------------------------------------------------------------------
End Sub
private Sub ImageToBlob(FileChooserResult As String) As String
Dim InputStream1 As InputStream
Dim directory As String =FileChooserResult.SubString2(0,FileChooserResult.LastIndexOf("\"))
Dim FileName As String = FileChooserResult.SubString(FileChooserResult.LastIndexOf("\") + 1)
InputStream1 = File.OpenInput(directory,FileName)
Dim su As StringUtils
Dim OutputStream1 As OutputStream
OutputStream1.InitializeToBytesArray(1000)
File.Copy2(InputStream1, OutputStream1)
Dim Buffer() As Byte 'declares an empty array
Buffer = OutputStream1.ToBytesArray
Return su.EncodeBase64(Buffer)
End Sub
Public Sub ImageToBytes(Image As Image) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(0)
Image.WriteToStream(out)
out.Close
Log("Done!")
Return out.ToBytesArray
End Sub
'
public Sub blobToIO(bySt As String) As InputStream
Dim su As StringUtils
Dim by() As Byte = su.DecodeBase64(bySt)
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(by, 0, by.Length)
InputStream1.Close
Return InputStream1
End Sub
Sub btnsave_MouseClicked (EventData As MouseEvent)
Dim cmd As DBCommand
cmd.Initialize
'Defined as sql.select2 in the RDC file config.properties located in the files folder
cmd.Name = "select"
'Trigger the query. The result is handled by JobDone.
reqManager.ExecuteQuery(cmd, 0, "select")
'Dlg.ToastMessage(DlgMsgWait, DlgMsgWaitDuration)
Log("Select Table Query triggered")
End Sub
Sub JobDone(Job As HttpJob)
If Job.Success = False Then
Log("Error: " & Job.ErrorMessage)
Else
If Job.JobName = "DBRequest" Then
reqManager.HandleJobAsync(Job, "ReqManager")
End If
End If
Job.Release
End Sub
Sub ReqManager_Result(result As DBResult)
'reqManager.PrintTable(result)
reqManager.PrintTable(result)
Log("Done here")
'reqManager.PrintTable(result)
End Sub
Sub btnOpen_MouseClicked (EventData As MouseEvent)
Dim byStr As String
Dim cmd As DBCommand
cmd.Initialize
'Defined as sql.select2 in the RDC file config.properties located in the files folder
cmd.Name = "select1"
'Trigger the query. The result is handled by JobDone.
reqManager.ExecuteQuery(cmd, 0, "select1")
Wait For(j) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For (req) req_Result(res As DBResult)
Dim r() As row = res.rows.get(0)
Dim im As Image
im.Initialize2(blobToIO(r(1)) 'The column index of your query.
ImageView1.SetImage(im)
End If
End Sub
public Sub BlobToIO(bySt As String) As InputStream
Dim su As StringUtils
Dim by() As Byte = su.DecodeBase64(bySt)
Dim InputStream1 As InputStream
InputStream1.InitializeFromBytesArray(by, 0, by.Length)
' InputStream1.Close
Return InputStream1
End Sub