B4J Tutorial [BANanoWebix] Creating Multi-Page Apps - Part 5

Ola

Download BANanoWebix Things

Copy the 1.Libraries contents to your external b4j libraries folder. The project source code for this lesson is in BANanoWebixMultiPage

Part 5 here closes this tutorial. This encompasses everything we have learned from Part 1 to Part 4 and some more.

1. We create the backend for the clients table
2. We create the front end for the clients table
3. We add badges to indicate the number of clients we have everytime that changes
4. We add print functionality so that we can print the grid.
5. We load the combo boxes based on data stored in other tables.


1. We create the backend BANanoSQL table for the clients we want to create...

B4X:
Dim newTable As Map = CreateMap()
    newTable.put("id","INT")
    newTable.put("fname","STRING")
    newTable.put("lname","STRING")
    newTable.put("position","STRING")
    newTable.put("email","STRING")
    newTable.put("city","STRING")
    newTable.put("address","STRING")
    newTable.put("birthday","STRING")
    newTable.put("firstrequest","STRING")
    newTable.put("phone","STRING")
    newTable.put("notifications","STRING")
    newTable.put("photo","STRING")
    newTable.put("notes","STRING")

    'initialize the helper class
    Dim alaSQL As BANanoAlaSQL
    alaSQL.Initialize
    'generate the create table sql
    Dim rs As AlaSQLResultSet = alaSQL.CreateTable("clients", newTable, "id")
    'execute the create table command
    rs.Result = ourclients.ExecuteWait(rs.query, rs.args)

2. In modClients, we define code to add the clients page to the multi-view and we add this page to the master project.

B4X:
Sub AddToMultiView(pg As WixPage, mv As WixMultiView)
    Page = pg
    Dim dt1 As WixDataTable = CreateClientsDT
    Dim frm1 As WixForm = CreateClientForm
    
    Dim a As WixElement
    a.Initialize("mv_clients").SetTemplate("Clients").SetTypeLine("")
    Dim r1 As WixElement
    r1.Initialize("r1")
    r1.AddRows(CreateClientsToolBar.item)
    a.AddRows(r1.item)
    '
    Dim r2 As WixElement
    r2.initialize("r2")
    r2.AddColumns(dt1.item)
    r2.AddColumnsResizer("")
    r2.AddColumns(frm1.item)
    a.AddRows(r2.Item)
    '
    mv.AddItem(a.Item)
    SetPage(Page)
End Sub

3. In the toolbar we have added, we have added a print button, this activates the printer and we are able to print the data-table.

B4X:
Sub printclients_click
    Dim wp As WixPrint
    wp.Initialize
    wp.SetHeader(True)
    wp.SetFooter(True)
    wp.SetDocHeader("Clients")
    wp.SetModeLandScape(True)
    wp.SetDataAll(True)
    wp.SetDocFooter("BANanoWebix Multi-Page App")
    wp.SetPaperA4(True)       
    Page.Print("dtclients",wp)
End Sub

This toolbar also shows an icon that has an updating badge. To update the badge, we get the total number of client records in the table and then update the badge..

B4X:
Dim tc As Int = rs.result.size
    Page.SetBadge("totalclients", tc)

4. In edit mode and when a new client is being added, we refresh the positions and the cities combo boxes with records from the respective tables.

B4X:
Sub RefreshOptions
    Dim alasql As BANanoAlaSQL
    alasql.Initialize
    Dim rs As AlaSQLResultSet = alasql.SelectAll("positions", Array("id","value"), Array("value"))
    rs.Result = ourclients.ExecuteWait(rs.query, rs.args)
    Page.AddNotSelected(rs.result)
    Page.SetOptions("position", rs.result)
    '
    alasql.Initialize
    Dim rs As AlaSQLResultSet = alasql.SelectAll("cities", Array("id","value"), Array("value"))
    rs.Result = ourclients.ExecuteWait(rs.query, rs.args)
    Page.AddNotSelected(rs.result)
    Page.SetOptions("city", rs.result)
        
End Sub

The rest of the crud functionality has been greatly discussed in Part 4.

Ta!
 
Top