Xbrowse Tree using Array instead of DBF

Post Reply
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Xbrowse Tree using Array instead of DBF

Post by fraxzi »

Hi!

It's been a while since I posted but almost everyday I read topics here..

I usually do xbrowse tree using DBF data..

I couldn't find an example using Array data for an xbrowse tree.. anyone? .. Mr. RAO?


Kind Regards,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Xbrowse Tree using Array instead of DBF

Post by anserkk »

Try this.
Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array" 
    @0,0 XBROWSE oBrw OF oWnd 
    
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL 

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;   
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;   
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }   
                    
    TREE oTree  
    nLevel:=aItems[1][3] 
    nTreeCount:=0             
    For i:=1 to Len(aItems)
        if aItems[i][3] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][3] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][3] 
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][2] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][3]
    Next               
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser
User avatar
RAMESHBABU
Posts: 591
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: Xbrowse Tree using Array instead of DBF

Post by RAMESHBABU »

Hello Anser,

Very Good Example :D

Regards,

- Ramesh
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by fraxzi »

Hi Anser!

That's a good one!


Kind regards,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
ACC69
Posts: 619
Joined: Tue Dec 12, 2006 7:34 pm
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by ACC69 »

anserkk wrote:Try this.
Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array" 
    @0,0 XBROWSE oBrw OF oWnd 
    
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL 

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;   
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;   
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }   
                    
    TREE oTree  
    nLevel:=aItems[1][3] 
    nTreeCount:=0             
    For i:=1 to Len(aItems)
        if aItems[i][3] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][3] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][3] 
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][2] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][3]
    Next               
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Hola buenas tardes Anserk,como esta, estoy tratando de compilar tu ejemplo, pero me marca error,que es lo que hace falta,uso version 8.12

//---------------------//
Function BUSCAR1()

Local oBrw,oWnd

DEFINE WINDOW oWnd TITLE "Tree using Array"
@0,0 XBROWSE oBrw OF oWnd

WITH OBJECT oBrw
:SetTree(BuildTree())
:oTree:OpenAll()
:CreateFromCode()
END

oWnd:oClient:=oBrw
ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
Local i,j,nLevel
Local aItems:={ {"01","Computers" ,0},;
{"02","Core i3" ,1},;
{"03","Core i5" ,1},;
{"04","Furnitures" ,0},;
{"05","Tables" ,1},;
{"06","Computer Table" ,2},;
{"07","Regular Table" ,2},;
{"08","Desk" ,1},;
{"09","Computer Desk" ,2},;
{"10","Regular Desk" ,2},;
{"11","Chairs" ,1} }

TREE oTree
nLevel:=aItems[1][3]
nTreeCount:=0
For i:=1 to Len(aItems)
if aItems[3] > nLevel
TREE
nTreeCount++
Elseif aItems[3] < nLevel
nPrevLevel:=nLevel
nCurLevel:=aItems[3]
nLevelDiff:=nPrevLevel-nCurLevel
For j:=1 to nLevelDiff
ENDTREE
nTreeCount--
Next
Endif
TREEITEM aItems[2] CARGO { aItems[1] } // Item Code
nLevel:=aItems[3]
Next
if nTreeCount > 0
For i:=nTreeCount To 1 Step -1
ENDTREE
Next
Endif
ENDTREE
Return oTree

Este es el error :

C:\Pro_FWH\ProveIVA\Prg\buscar1.prg(70) Error E0030 Syntax error: "syntax
error at 'AITEMS'"

Estoy tratando de adaptar a mi catalago de cuentas de 1 a 4 niveles de cuentas con caracter y longitud 16 ,y estaba tomando tu ejemplo, pero no me sale desde mi dbfs.

Saludos y buen dia.

Atte: Adrian C. C.
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Xbrowse Tree using Array instead of DBF

Post by anserkk »

Sorry,
I cannot find line 70 in your code. As per your message, the error occurs at line 70. The max no of lines in the code posted by you is only 61.

Did you try the sample code posted by me on your PC using your FHW ver 8.12 ?. Did it work ?

Regards
Anser
ACC69
Posts: 619
Joined: Tue Dec 12, 2006 7:34 pm
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by ACC69 »

anserkk wrote:Sorry,
I cannot find line 70 in your code. As per your message, the error occurs at line 70. The max no of lines in the code posted by you is only 61.

Did you try the sample code posted by me on your PC using your FHW ver 8.12 ?. Did it work ?

Regards
Anser
Hola buenos dias de nuevo, el error se produce aqui en esta linea ....

For i:=1 to Len(aItems)
if aItems[3] > nLevel
TREE
nTreeCount++
Elseif aItems[3] < nLevel
nPrevLevel:=nLevel
nCurLevel:=aItems[3]
nLevelDiff:=nPrevLevel-nCurLevel
For j:=1 to nLevelDiff
ENDTREE
nTreeCount--
Next
Endif
TREEITEM aItems[2] CARGO { aItems[1] } // Item Code /// Anserk aqui se me produce este error, y es con tu codigo que estoy probando....
nLevel:=aItems[3]
Next

Quiero implementar mi catalogo de cuentas en forma de tree,mi estructura en la base de datos es asi : Cuentas caracter longitud 16 y nivel longitud 1 numerico

CUENTAS NIVEL DESCRIPCION

1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Pero como hacerle con tu ejemplo, que intento compilar, pero ese error me sigue dando, y es el mismo ejemplo con tu codigo, solo le agregue la variable nLevel, que no estaba declarado,uso VERCE 5.0 y FWH 8.12

Saludos y buen dia Anserk

Atte: Adrian C. C.
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by Otto »

I use normal xBrowse with

oBrw:bIndent := { ||20 + ( ::cAlias )->TREELEVEL * 20 }

instead of treeView.

Best regards,
Otto

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Xbrowse Tree using Array instead of DBF

Post by anserkk »

To do a test with your FWH ver, I don't have FWH 8.12 here with me right now.

Many changes has been implemented to Tree after Ver 8.12

Anyway Tree with your data is working fine here with the latest FWH version.

CUENTAS NIVEL DESCRIPCION
1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array"
    @0,0 XBROWSE oBrw OF oWnd
   
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
/*    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;  
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;  
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }  
*/                    
Local aItems:={ {"1020-0000-0000-0000", 1,"Cuenta mayor"},;
                {"1020-0001-0000-0000", 2,"Subcta"},;
                {"1020-0001-0001-0000", 3,"Subsubcta"},;
                {"1020-0001-0001-0001", 4,"subsubctanddetalles"} }                    
                   
    TREE oTree  
    nLevel:=aItems[1][2]
    nTreeCount:=0            
    For i:=1 to Len(aItems)
        if aItems[i][2] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][2] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][2]
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][3] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][2]
    Next              
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser
ACC69
Posts: 619
Joined: Tue Dec 12, 2006 7:34 pm
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by ACC69 »

anserkk wrote:To do a test with your FWH ver, I don't have FWH 8.12 here with me right now.

Many changes has been implemented to Tree after Ver 8.12

Anyway Tree with your data is working fine here with the latest FWH version.

CUENTAS NIVEL DESCRIPCION
1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array"
    @0,0 XBROWSE oBrw OF oWnd
   
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
/*    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;  
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;  
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }  
*/                    
Local aItems:={ {"1020-0000-0000-0000", 1,"Cuenta mayor"},;
                {"1020-0001-0000-0000", 2,"Subcta"},;
                {"1020-0001-0001-0000", 3,"Subsubcta"},;
                {"1020-0001-0001-0001", 4,"subsubctanddetalles"} }                    
                   
    TREE oTree  
    nLevel:=aItems[1][2]
    nTreeCount:=0            
    For i:=1 to Len(aItems)
        if aItems[i][2] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][2] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][2]
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][3] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][2]
    Next              
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Gracias Anserk, yo creo que si tienes razon, ha de ser mi version, porque hasta la variable nLevel, la tuve que definir ,porque no me la reconocia,le preguntare a Antonio LInares, con cual podria sustituir la variable aItems, para mi version 8.12., o hay otra manera de crear para ese modulo que me esta dando vueltas la cabeza, con mi arbol de catalogo de cuentas.

Gracias de todos modos y un saludos

Atte: Adrian C. C.
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Xbrowse Tree using Array instead of DBF

Post by Eoeo »

and if I wish insert a check for each item how I can make ?

for a sample I have a menu items and I wish show any items instead of others
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Xbrowse Tree using Array instead of DBF

Post by Otto »

Silvio,
try to use oBrw:bIndent.

Best regards,
Otto
Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Eoeo
Posts: 222
Joined: Mon Jun 04, 2012 12:00 pm

Re: Xbrowse Tree using Array instead of DBF

Post by Eoeo »

where ? can you modify the test made from Anserkk please ?
or made another

I use an array to create ribbon

aMenuRibbon := { "Gestione Ufficio Tecnico","Hardware","Software","Manuali","Prestiti","Magazzino","Utilità","Aiuto" }
::obar:=TRibbonBar():New(::oWndMain, aMenuRibbon,,,,140,25,,,,,,,,,,.F.,1 )

we can create a configuration to set wich menu we not want to show....
Post Reply