Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Private lst_tragos = "lst_tragos", fot_marca = "fot_marca", fot_pro = "fot_pro", fotos = "fotos"
Dim lv As CustomListView
Type treslineas (First As String, Second As String, Tercero As String)
'Dim temp As Boolean
Private pg As Page
Private Label1 As Label
Private ncarrito As Label
Private carrito As ImageView
Private foto_marca As ImageView
Dim imgmarca,cod_foto As String
Dim list_ima, list_ima2 As List
Type list_ima_col(id As Int, tag As String, img As Bitmap)
Type list_ima2_col(id As Int, tag As String, img As Bitmap)
Dim list_imag As Map
Dim cont, contfot As Int
Private desc As Label
Private atras As ImageView
End Sub
Public Sub Show
If pg.IsInitialized = False Then
pg.Initialize("pg")
pg.RootPanel.LoadLayout("carta")
End If
Main.NavControl.ShowPage(pg)
list_ima.Initialize
list_ima2.Initialize
list_imag.Initialize
Dim Bm As Bitmap
Bm.Initialize(File.DirAssets,"ic_action_refresh.png")
foto_marca.Bitmap = Bm
desc.Initialize("")
lv.Clear
traer_fotos '<-----call the work that brings photos and stored in a list
End Sub
Sub cargar_img(fot As String)
des_img("http://www.xxxxxx.com/app/ejxxxes/ixxxges/marca/" & fot, fot_marca)
End Sub
Sub traer_fotos
ExecuteRemoteQuery("select * from inxxxxtario where categoria = '"&Main.categoria&"' and marca = '"&Main.marca&"'", fotos)
End Sub
Sub llenar_lista
ExecuteRemoteQuery("select * from xxxxxo where categoria = '"&Main.categoria&"' and marca = '"&Main.marca&"'", lst_tragos)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://www.dxxxxx.com/netdbxxxxores.php", Query)
End Sub
Sub des_img(url As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.Download(url)
End Sub
Sub JobDone(Job As HttpJob)
'ProgressDialogHide
If Job.Success Then
'Log("Response from server: " & res)
Select Job.JobName
'***************************************************************************************************************
Case fotos '<-----Case Photo
Dim res As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Dim l2 As List
l2 = parser.NextArray
cont = l2.Size
If l2.Size = 0 Then
Msgbox("No se encontraron registros", False)
Else
Log ("Tamaño del rs: "&l2.Size)
contfot = 0
cod_foto = ""
For i = 0 To l2.Size - 1'<-----For that runs the sql result to know the name of the photo and call the function that discharge
Dim tl As treslineas
Dim m As Map
m = l2.Get(i)
tl.First = m.Get("nombre")
tl.Second = m.Get("foto")
imgmarca = m.Get("foto_marca")
cod_foto = tl.First
Log("Desde el for: "&cod_foto)
des_img("http://www.dxxxxxxx.com/app/ejxxxxres/images/tragos/" & tl.Second, fot_pro)'<-----function callback download images
Next
cargar_img(imgmarca)'<-----Call the function that discharge prevention image of Cabora screen
End If
'***************************************************************************************************************
Case lst_tragos'<-----Case txt
If lv.IsInitialized = False Then
lv.Initialize(Me, "lv", 100%X)
pg.RootPanel.AddView(lv.AsView, 0, 0, 100%x, 150%y)
lv.SetSize(Label1.Width, 150%y)
lv.AsView.Left = 0%x
lv.AsView.Top = 0%y + foto_marca.Top + foto_marca.Height + 3dip
lv.AsView.Color = Colors.ARGB(25,0,0,0)
End If
Dim res As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Dim l2 As List
lv.Clear
l2 = parser.NextArray
If l2.Size = 0 Then
Msgbox("No se encontraron registros", False)
Else
For i = 0 To l2.Size - 1
Dim tl As treslineas
Dim m As Map
m = l2.Get(i)
tl.First = m.Get("nombre")
tl.Second = m.Get("foto")
tl.Tercero = m.Get("descripcion")& Chr(13) & Chr(10) & " Valor: $" & m.Get("valor")
lv.Add(CreateListItem(tl.First,tl.Second , i, 120%x, 70dip), 70dip, "Item")
Next
End If
'***************************************************************************************************************
Case fot_marca
foto_marca.Bitmap=Job.GetBitmap
'***************************************************************************************************************
Case fot_pro
Log("-> Fot_pro contfot: "&contfot & " Tag: " & Job.Tag & " BitMap: " & Job.GetBitmap)
Dim p As list_ima_col
p.id = contfot
p.tag = Job.Tag
p.img = Job.GetBitmap
list_ima.Add(p)
contfot = contfot + 1
If (contfot = cont) Then'<-----After you download all photos I call the function to download the data to match the photos
list_ima.SortType("id",True)'<-----ordered list of photos downloaded as recommended Erel
For i = 0 To list_ima.Size - 1
Dim q As list_ima_col
q = list_ima.Get(i)
list_ima2.InsertAt(i,q)'<-----ordered after I copy a new list
Log("Tag: " & q.tag & " Bitmap: " & q.img)
Next
llenar_lista
End If
End Select
Else
Msgbox("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub CreateListItem(Text As String,foto As String, indx As String, Width As Int, Height As Int) As Panel
Dim p As Panel
p.Initialize("")
p.Color = Colors.Black
Dim q As list_ima2_col
q = list_ima2.Get(indx)
Dim b As Bitmap = q.img
Dim im As ImageView
im.Initialize("")
im.Bitmap = b
Dim lbl As Label
lbl.Initialize("lbl")
lbl.TextAlignment = lbl.ALIGNMENT_LEFT
lbl.Text = Text
lbl.Font = Font.CreateNew(13)
lbl.TextColor = Colors.White
p.AddView(lbl, Height+5dip,0,Width*0.8,Height)
p.AddView(im, 0,0,Height,Height)
Return p
End Sub