B4J Library SD: BindingNavigator (Sqlite GUI Navigator)

Star-Dust

Expert
Licensed User
This is a first version of the BindingNavigator Library, which wants to somehow reproduce the corresponding BindingNavigator of VB.NET

What is needed? I want to get something similar to the tools available on VB.NET to link the views to the DB. As in the pictures.
I am now working on a B4J App that creates a Layout (.bal and baj) from a database that can be loaded into your B4X project, based on Erel's bal converter. (hoping to succeed)

upload_2018-3-25_11-55-47.png
upload_2018-3-25_11-55-51.png


A DataSet Class is available that allows to associate some views (EditText, Label, ImageView, ToggleButton, CheckBox) with specific fields of a Sqlite DataBase.

By scrolling the position of the DataSet the fields will be updated and if the fields in some way undergo a variation by the user, raising the UpdateChange event will in turn be modified in the DataBase.
This very Agevolent construction of GUI related to the DB.

In addition you have a Second ViewCalss NavigatorBar that adds a new Seek view to the design that is linked to the DataSet. Scrolling through the Seek will change all the views linked to the DataSet. And if the UpdateChange eventio is updated, the DB will be updated based on changes in the views linked to the fields.

VERY IMPORTANT:
  1. The sql database must always have a Primarykey field, of type int with auto-increment, in the example i call it ID, but it could be called as you want.
    The name of the field that will be the Primarykey must be communicated to the DataSet when call query method.
  2. It is always necessary to add in the code - #AdditionalJar: sqlite-jdbc-3.7.2

jSD_BindingNavigator

Author: Star-Dust
Version: 0.10
  • ControlView
    • Fields:
      • Field As String
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • V As Object
    • Functions:
      • Initialize
        Inizializza i campi al loro valore predefinito.
  • DataSet
    • Functions:
      • AddLinkView (View As Object, Field As String) As String
        View Label, TextField, TextArea, CheckBox, ImageView
      • AddRecord As String
      • Class_Globals As String
      • ClearLinkView As String
      • Close As String
        Close connection DB
      • DeleteRecord As String
      • getBlob (Field As String) As Byte()
      • getCurrentTable As String
      • getDouble (Field As String) As Double
      • getImage (Field As String) As Image
      • getInt (Field As String) As Int
      • getLong (Field As String) As Long
      • getPosition As Int
        Return -3 : Not Initialized
        Return -2 : Is empty
        Return -1 : Not positoned
      • getSize As Int
        Return -1 id Query non execute
      • getSQL As SQL
      • getString (Field As String) As String
      • Initialize (Path As String, FileName As String, CreateIfNecessary As Boolean) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • NextRecord As String
      • PreviousRecord As String
      • Query (StringQuery As String, PrimaryKeyName As String) As String
      • Query2 (StringQuery As String, StringArg As String(), PrimaryKeyName As String) As String
      • RefreshField As String
      • setPosition (Index As Int) As Boolean
        Return false if Query not execute, index out of range or other error
      • UpdateChange As String
    • Properties:
      • CurrentTable As String [read only]
      • Position As Int
        Return -3 : Not Initialized
        Return -2 : Is empty
        Return -1 : Not positoned
      • Size As Int [read only]
        Return -1 id Query non execute
      • SQL As SQL [read only]

Sample1.png
 

Attachments

Last edited:

Star-Dust

Expert
Licensed User
DataSet

B4X:
#AdditionalJar: sqlite-jdbc-3.7.2

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form

    Private Slider1 As Slider
    Private ImageView1 As ImageView
    Private LabelName As Label
    PrivateTextFieldDescription As TextField
    Private CheckBox1 As CheckBox
 
    Dim DS As DataSet
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("main") 'Load the layout file.
    MainForm.Show
 
    File.Copy(File.DirAssets,"test.sql",File.DirTemp,"test.sql")
    DS.Initialize(File.DirTemp,"test.sql",False)
 
    DS.AddLinkView(ImageView1,"bitmap")
    DS.AddLinkView(LabelName,"name")
    DS.AddLinkView(TextFieldDescription,"description")
    DS.AddLinkView(CheckBox1,"mycheck")
 
    DS.Query("SELECT * FROM mytable","ID")
    Slider1.MaxValue=DS.Size-1
    Slider1.Value=0

End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub ButtonM_Click
    Dim I As Int = Max(0,Slider1.Value-1)
    Slider1.Value=I
    'DS.PreviousRecord
End Sub

Sub ButtonP_Click
    Dim I As Int = Min(DS.Size-1,Slider1.Value+1)
    Slider1.Value=I
    'DS.NextRecord
End Sub

Sub Slider1_ValueChange (Value As Double)
    DS.Position=Value
End Sub

Sub ButtonUpdate_Click
    DS.UpdateChange
End Sub

upload_2018-3-25_0-27-7.png
 

Attachments

Last edited:
Top