Spanish [ SOLUCIONADO ] jRDC2 - B4A Cliente Sqlite

elsanto

Member
Licensed User
Longtime User
Estoy desarrollando una app en b4a como cliente para leer BD sqlite, esta BD
es creada con un programa echo en Fujitsu PowerCobol , que va insertando datos
en dos tablas , el problema lo tengo en el cliente B4A , cuando realizo las consultas
de la segunda tabla no me muestra siempre los datos ordenados. Como puedo hacer
para mostrar los datos en forma ordenada de acuerdo a mis solicitudes al servidor(jRDC2)

ordenar sqlite.png

B4X:
Sub GetCabeceras
     Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_all_cabeceras" , Null)

    clvPedidos.Clear
    
    Wait For(req.ExecuteQuery(cmd,0,Null)) jobdone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j,"req")
        Wait For (req) req_result(res As DBResult)
'        Log(res.Columns)
        
        spnCabecera.Clear
        
        For Each row() As Object In res.Rows
            spnCabecera.Add(row(0))

        Next

    Else
           Log("----------------------------------")
           Log("Comando Enviado : get_all_cabeceras")
           Log("Error : " &    j.ErrorMessage)   
           Log("----------------------------------")

    End If
    
    j.Release
    
    'Muestra el detalle de los pedidos o comandas
    ' A veces ordenados por el nro de comanda o pedido
    For i = 0 To spnCabecera.Size - 1
        Log(spnCabecera.GetItem(i))
        GetDetalle(spnCabecera.GetItem(i))
    
    Next
'    GetDetalle(212)
'   
'    GetDetalle(213)
'   
'    GetDetalle(214)
'   
Log("---------------------")
Log("Salio")

End Sub

Sub GetDetalle( value As Object)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_detalle" , Array(value))
    
    Dim Cantidad    As String
    Dim Cantidadant As Double
    Dim Barras      As String
    Dim Barrasant   As String
    Dim Descri      As String
    Dim Descriant   As String
    Dim CantLineas  As Int = 0
    Dim mapData     As Map
    
    
    Wait For(req.ExecuteQuery(cmd,0,Null)) jobdone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j,"req")
        
        Wait For (req) req_result(res As DBResult)
        
        
'       Log(res.Columns)
        Log(req.PrintTable(res))

        For Each row() As Object In res.Rows
            mapData.Initialize
'        Log ( "fila " & row(0) & " comanda nro " & row(1) & " date " & row(2) & " cantidad " & row(3) & " barras " & row(4))

            
'            Log(res.Columns.GetKeyAt(0))
'            Log(res.Columns.GetKeyAt(1))
'            Log(res.Columns.GetKeyAt(2))
'            Log(res.Columns.GetKeyAt(3))
'            Log(res.Columns.GetKeyAt(4))
'            Log(res.Columns.GetKeyAt(5))
            Barrasant = row(4)'RsDetalle.GetString("combarras")
            Descriant = row(5)'RsDetalle.GetString("comdescri")
            Cantidadant = row(3)'RsDetalle.GetString("comcant")
        
            Cantidad = Cantidad & CRLF & Cantidadant

            Barras = Barras & CRLF & Barrasant
            Descri = Descri & CRLF & Descriant
            CantLineas = CantLineas + 1
        Next
        mapData.Put("Datnro" , row(1))
        mapData.Put("Cantidad" , Cantidad )
        mapData.Put("Barras" , Barras )
        mapData.Put("Descri" , Descri.trim )
        mapData.Put("Lineas" , CantLineas )
        Dim p As B4XView = CreateCard(mapData)
        clvPedidos.Add(p, mapData)
        
    Else

        Log("----------------------------------")
        Log("Comando Enviado : get_detalle")
        Log("Error : " &    j.ErrorMessage)
        Log("----------------------------------")
          
    
        
    End If
    
    j.Release
    
    
    
End Sub

Gracias por su tiempo
Saludos..
 

Attachments

  • CliSql.zip
    14 KB · Views: 29

OliverA

Expert
Licensed User
Longtime User
Try:
B4X:
Sub GetCabeceras
     Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_all_cabeceras" , Null)

    clvPedidos.Clear
    
    Wait For(req.ExecuteQuery(cmd,0,Null)) jobdone(j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j,"req")
        Wait For (req) req_result(res As DBResult)
'        Log(res.Columns)
         
        spnCabecera.Clear
         
        For Each row() As Object In res.Rows
            spnCabecera.Add(row(0))

        Next

    Else
           Log("----------------------------------")
           Log("Command Sent: get_all_headers")
           Log("Error : " &    j.ErrorMessage)    
           Log("----------------------------------")

    End If
    
    j.Release
    
    'Shows the details of the orders or orders 
    'Sometimes ordered by order or order number
    For i = 0 To spnCabecera.Size - 1
        Log(spnCabecera.GetItem(i))
        wait for (GetDetalle(spnCabecera.GetItem(i))) Complete (success As Boolean)  ' Modified************
    Next
' GetDetails(212)
'    
' GetDetails(213)
'    
' GetDetails(214)
'    
Log("---------------------")
Log("Salio")

End Sub

Sub GetDetalle( value As Object) As ResumableSub 'Modified***************
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("get_detalle" , Array(value))
    
    Dim Quantity As String
    Dim Cantidadant As Double
    Dim Barras      As String
    Dim Barrasant   As String
    Dim Descri      As String
    Dim Descriant   As String
    Dim CantLineas  As Int = 0
    Dim mapData     As Map
    
    Dim success        As Boolean 'New**************
    
    Wait For(req.ExecuteQuery(cmd,0,Null)) jobdone(j As HttpJob)
    success = j.Success 'New**************
    If j.Success Then
        req.HandleJobAsync(j,"req")
        
        Wait For (req) req_result(res As DBResult)
        
        
'       Log(res.Columns)
        Log(req.PrintTable(res))

        For Each row() As Object In res.Rows
            mapData.Initialize
'        Log ( "fila " & row(0) & " comanda nro " & row(1) & " date " & row(2) & " cantidad " & row(3) & " barras " & row(4))

            
'            Log(res.Columns.GetKeyAt(0)) 
'            Log(res.Columns.GetKeyAt(1))
'            Log(res.Columns.GetKeyAt(2))
'            Log(res.Columns.GetKeyAt(3))
'            Log(res.Columns.GetKeyAt(4))
'            Log(res.Columns.GetKeyAt(5))
            Barrasant = row(4)'RsDetalle.GetString("combarras")
            Descriant = row(5)'RsDetalle.GetString("comdescri")
            Cantidadant = row(3)'RsDetalle.GetString("comcant")
        
            Quantity = Quantity & CRLF & Quantityant

            Barras = Barras & CRLF & Barrasant
            Descri = Descri & CRLF & Descriant
            CantLineas = CantLineas + 1
        Next
        mapData.Put("Datnro" , row(1))
        mapData.Put("Amount" , Amount )
        mapData.Put("Barras" , Barras )
        mapData.Put("Describe" , Descri.trim )
        mapData.Put("Lineas" , CantLineas )
        Dim p As B4XView = CreateCard(mapData)
        clvPedidos.Add(p, mapData)
        
    Else

        Log("----------------------------------")
        Log("Command sent: get_detalle")
        Log("Error : " &    j.ErrorMessage)
        Log("----------------------------------")
           
    
        
    End If
    
    j.Release
    
    Return success 'New*************************
    
End Sub
 
Top