Private Sub B4XPage_MenuClick (Tag As String)
Log(Tag)
If Tag="indietro" Then 'BACK
livelloscelto=livelloscelto-1
If livelloscelto>=0 Then
scegliquery(livelloscelto,"",sottogrupposcelto)
Else
B4XPages.ClosePage(Me) 'try to close page
End If
End If
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("SearchResults")
'load the layout to Root
B4XPages.SetTitle(Me, "SCEGLI") 'Page title
B4XFltTxtSearch.HintText = "Search"
B4XFltTxtSearch.Update
CLVSearchResults.sv.Color = XUI.Color_White
'Query the SQLite database to populate the results
'SQLQuery("select distinct u.id,coalesce(u.citta,"&"""GENERALI"""&") As descr from anaute u order by u.citta","CITTA")
scegliquery(0,"","")
End Sub
Sub scegliquery(livello As Int ,tipo As String, param As Object)
Dim sql As String
livelloscelto=livello
If livello=0 And Main.parametri.sottogruppo>=0 Then
sql="select id,descrizione as descr from anaditte_sottogruppi where idditta="&Main.parametri.idditta&" and stato='A' order by descrizione"
sottogrupposcelto=-1
End If
If livello=1 Then
sottogrupposcelto=param.As(Int)
If Main.parametri.comuni Then
sql="select distinct coalesce(u.citta,"&"""GENERALI"""&") As descr from anaute u "
If Main.parametri.sottogruppo=0 Then
sql=sql&"where coalesce(idsottogruppo,0)="&sottogrupposcelto&" order by descr"
Else
sql=sql& " order by descr"
End If
End If
End If
If livello=2 Then
sql="select distinct u.id,upper(coalesce(u.nome,"&""""""&")||"""&" "&"""||coalesce(u.cognome,"&""""""&")) As descr, u.tipo_marcatura from anaute u where coalesce(upper(citta),"&""""""&")="""& param.as(String).ToUpperCase &""" "
If Main.parametri.sottogruppo>=0 Then
sql=sql&"and coalesce(idsottogruppo,-1)="&sottogrupposcelto&" order by descr"
Else
sql=sql& "order by descr"
End If
End If
SQLQuery(sql,tipo,livello)
End Sub
' fill the CLV
Sub SQLQuery(Query As String,tipo As String,livello As Int)
Dim item As String
' Dim parametri As List
' If parametro<>"" Then
' parametri.Initialize
' parametri.InsertAt(0,parametro)
' End If
CLVSearchResults.Clear 'Clear the CustomListView
Dim SenderFilter As Object = B4XPages.MainPage.SQL.ExecQueryAsync("SQL", Query, Null)
Wait For (SenderFilter) SQL_QueryComplete (Success As Boolean, rs As ResultSet)
If Success Then
Do While rs.NextRow 'Loop through the results
'Ceate your custom type (on a per line basis)
'PCLV.AddItem(260dip, XUI.Color_White, CreateRowSearchResultData(rs.GetString("Country"), rs.GetInt("Year"), rs.GetString("Male"), rs.GetString("Female"), rs.GetString("Total")))
'item=rs.GetString("descrizione")
'CLVSearchResults.add
Dim ResultValues As RowSearchResultData
ResultValues.Initialize
ResultValues.descr=rs.GetString("descr")
ResultValues.id=rs.GetInt("id")
ResultValues.livello=livello
CLVSearchResults.AddTextItem(ResultValues.descr,ResultValues)
Loop
rs.Close
Else
Log(LastException)
End If
End Sub