private Sub Loadreport(fromPage As Int)
' Here is where we populate the ABMtable with records from our MySQL table
' Since we don't want all the records initially (could be hundreds), we will use pagination to limit what is fetched from the server
' Use the query to order your table if you desire
' Get the ABMTable component...
Dim tblUsers As ABMTable = page.Component("tblUsers") ' get the table defined in ConnetPage...
' create a SQL cursor
Dim SQL As SQL = DBM.GetSQL
' get number of users (select count query) - used in table footer and for pagination....
Dim numusers As Int = DBM.SQLSelectSingleResult(SQL, "SELECT Count(pk) as IDS FROM reports ")
'**********************************************************************************************************
'**********************************************************************************************************
' Get a list of records - LIMIT these by pagination (page number) and number of records to show - iRecs (global var set to 4 currently)
' NOTE: We are selecting "certain" fields from the table - and in a certain order - the same order as title headers
' tblUsers.SetHeaders( Array As String ("ID" , "Access Type" , "Person's Name" , "Login (username)" , "Password" ,"Photo", "Active" ,"Open/Edit", "Delete" ))
'**********************************************************************************************************
'**********************************************************************************************************
Dim qry As String = "SELECT pk, repname, repfile,p1,p2,p3,p4,p5,rtype FROM reports " & " LIMIT " & ((fromPage - 1) * iRecs) & ", "&iRecs
Dim users As List = DBM.SQLSelect(SQL, qry)
If users.Size = 0 And fromPage > 1 Then
' we are on a page without any lines (maybe removed by other user?)
DBM.CloseSQL(SQL)
fromPage = fromPage - 1
Loadreport(fromPage)
Return
End If
tblUsers.SetFooter("Total number of reports: " & numusers, 12,"bgc")
' clear any old stuff in the table so we may add new...
tblUsers.Clear
For i = 0 To users.Size - 1
' our list is a map of field names and values
' we create a new map for each list item
Dim tblFields As Map = users.Get(i)
'
Dim rCellValues As List
Dim rCellThemes As List
rCellValues.Initialize
rCellThemes.Initialize
'**********************************************************************************************************
'**********************************************************************************************************
' In this example, we shall add ABMTable fields by users.field name...
' It does not matter in what order we add items now since our query defined the order based on our ABMTable headers...
'**********************************************************************************************************
'**********************************************************************************************************
For j = 0 To tblFields.Size - 1 ' set the var - Value of map...
' This "var" is used for each "GetKeyAt" that follows....
Dim var As String
var = tblFields.GetValueAt(j)
If var = "null" Then ' init as string to avoid null_pointer error
var = ""
End If
' NEVER format the primary key (as a label)!!!! It is generally hidden and needed to get which row was selected.
' A label format will not return the value of this cell...
If tblFields.GetKeyAt(j) = "pk" Then
rCellValues.Add(var)
rCellThemes.Add("nocolor")
Continue
End If
' NEVER format the primary key (as a label)!!!! It is generally hidden and needed to get which row was selected.
If tblFields.GetKeyAt(j) = "repname" Then
Dim pd As ABMLabel
pd.Initialize(page,"usrn"&j, var ,ABM.SIZE_H5,False,"")
rCellValues.Add(pd)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "repfile" Then
Dim pd As ABMLabel
pd.Initialize(page,"usrl"&j,var,ABM.SIZE_PARAGRAPH,False,"")
rCellValues.Add(pd)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "p1" Then
Dim cb As ABMCheckbox
Dim nvar As Int ' convert var to int
nvar = var
cb.Initialize(page, "ucb"&j, "", (nvar > 0) ,"") ' set checkbox state (True / False) with nvar logic
cb.Enabled = False
rCellValues.Add(cb)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "p2" Then
Dim cb As ABMCheckbox
Dim nvar As Int
nvar = var
cb.Initialize(page, "ucb"&j, "", (nvar > 0) ,"")
cb.Enabled = False
rCellValues.Add(cb)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "p3" Then
Dim cb As ABMCheckbox
Dim nvar As Int
nvar = var
cb.Initialize(page, "ucb"&j, "", (nvar > 0) ,"")
cb.Enabled = False
rCellValues.Add(cb)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "p4" Then
Dim cb As ABMCheckbox
Dim nvar As Int
nvar = var
cb.Initialize(page, "ucb"&j, "", (nvar > 0) ,"")
cb.Enabled = False
rCellValues.Add(cb)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "p5" Then
Dim cb As ABMCheckbox
Dim nvar As Int
nvar = var
cb.Initialize(page, "ucb"&j, "", (nvar > 0) ,"")
cb.Enabled = False
rCellValues.Add(cb)
rCellThemes.Add("nocolor")
Continue
End If
If tblFields.GetKeyAt(j) = "rtype" Then
Dim reptype As String = "Config"
If var > 0 Then
reptype = "Application"
End If
Dim pd As ABMLabel
pd.Initialize(page,"usrl"&j,reptype,ABM.SIZE_PARAGRAPH,False,"")
rCellValues.Add(pd)
rCellThemes.Add("nocolor")
Continue
End If
Next
' add our edit and delete buttons to each row of the table
' the edit button is blue (by default - no theme)
Dim btnEdit As ABMButton
btnEdit.InitializeFloating(page, "btnEdit" ,"mdi-action-visibility", "")
' TIP: uncomment the line below and watch the height of each row shrink. Use small buttons for more rows per page when required
' btnEdit.Size = ABM.BUTTONSIZE_SMALL
rCellValues.Add(btnEdit)
rCellThemes.Add("nocolor")
' Now add a ABMTable row with the list items. This list must match the number of headers you defined for this abmtable!
tblUsers.AddRow("uid_"&i, rCellValues)
' make sure you have as many items in rCellThemes as in rCellValues! Must follow IMMEDIATELY AFTER AddRow!
tblUsers.SetRowThemes( rCellThemes)
Next
' refresh the table!!!
tblUsers.Refresh
DBM.CloseSQL(SQL)
' Here we are setting the pagination component.
' It determines how many pages we have - and which page is currently in view.
Dim pagination As ABMPagination = page.Component("pagination")
If (numusers Mod iRecs > 0) Or (numusers = 0) Then
numusers = numusers/iRecs + 1
Else
numusers = numusers/iRecs
End If
pagination.SetTotalNumberOfPages(numusers)
pagination.SetActivePage(fromPage)
pagination.Refresh
Log(" Finished loading reports... ")
End Sub