Private Sub B4XPage_MenuClick (Tag As String)
Log(Tag)
If Tag="indietro" Then
livelloscelto=livelloscelto-1
If livelloscelto>=0 Then
scegliquery(livelloscelto,"",sottogrupposcelto)
Else
B4XPages.ClosePage(Me)
End If
End If
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("SearchResults")
B4XPages.SetTitle(Me, "SCEGLI")
B4XFltTxtSearch.HintText = "Search"
B4XFltTxtSearch.Update
CLVSearchResults.sv.Color = XUI.Color_White
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
Sub SQLQuery(Query As String,tipo As String,livello As Int)
Dim item As String
CLVSearchResults.Clear
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
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