FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour oTree for xBrowse sample...
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
oTree for xBrowse sample...
Posted: Wed Oct 15, 2008 08:46 AM

Thankyou Mr.Antonio

Posts: 811
Joined: Tue May 06, 2008 04:28 AM
oTree for xBrowse sample...
Posted: Thu Oct 16, 2008 12:56 AM

Senior Linales,

Thank you for the kind help.... Your expertise is utmost needed.

My best regards!

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
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: Tree
Posted: Fri Dec 24, 2010 09:33 AM
Dear Mr. Antonio,

How can I make a tree with more than 2 levels using xbrowse?

like:

AK
|
+--Tarzana
|
+-----another level under Tarzana
|
+---- another level under under Tarzana


Best regards,
Frances

Antonio Linares wrote:Frances, Detlef,

Here you have a working example:
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()   

   local oWnd, oBrw

   USE Customer
   INDEX ON Field->State TO State
   SET ORDER TO "State"
   GO TOP
   
   DEFINE WINDOW oWnd TITLE "DbfTree"

   @ 0, 0 XBROWSE oBrw OF oWnd LINES CELL

   oBrw:SetTree( BuildTree() )

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "State"

   oWnd:oClient = oBrw
   
   ACTIVATE WINDOW oWnd
   
return nil   

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( Customer->State ):Cargo := RecNo()
            TREE
            cState = Customer->State
         else
            if cState != Customer->State
               ENDTREE
               cState = Customer->State
               _TreeItem( Customer->State ):Cargo := RecNo()
               TREE
            endif   
         endif   
         if Customer->State == cState
            _TreeItem( Customer->City ):Cargo := RecNo()
         endif   
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

return oTree
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: oTree for xBrowse sample...
Posted: Fri Dec 24, 2010 04:39 PM
Code (fw): Select all Collapse
/*
*
*   XbTree2.Prg
*   24-12-2010 08:39 PM
*
*/

#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"

//----------------------------------------------------------------------------//

REQUEST DBFCDX

#xtranslate bmp( <c> ) => "c:\fwh\bitmaps\16x16\" + <c> + ".bmp"

//----------------------------------------------------------------------------//

function Main()

   CreateTestData()
   TreeBrowse()

return (0)

//----------------------------------------------------------------------------//

init procedure PrgInit

    SET DATE ITALIAN
    SET CENTURY ON
    SET TIME FORMAT TO "HH:MM:SS"
    SET EPOCH TO YEAR(DATE())-50

    SET DELETED ON
    SET EXCLUSIVE OFF

    RDDSETDEFAULT( "DBFCDX" )

    XbrNumFormat( 'I', .t. )
    SetKinetic( .f. )
    SetGetColorFocus()

return

//----------------------------------------------------------------------------//

exit procedure PrgExit

    SET RESOURCES TO

return

//----------------------------------------------------------------------------//

static function TreeBrowse

   local oDlg, oBrw, oFont
   local aTot  := { 0, 0 }
   local aColors  := {  { CLR_WHITE,   CLR_GREEN         }, ;
                        { CLR_BLACK,   RGB(255,255,180)  }, ;
                        { CLR_BLACK,   CLR_WHITE         }  }

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 600,500 PIXEL ;
      TITLE "Xbrowse Tree" FONT oFont

   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
      CELL LINES NOBORDER FOOTERS

   oBrw:SetTree( MakeTree( aTot ), { bmp( "open" ), bmp( "folder" ), bmp( "spurce" ) } )

   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] PICTURE "999,999,999" HEADER "Sales"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] PICTURE "999,999,999" HEADER "Margin"

   WITH OBJECT ( oBrw:Percent := { || oBrw:Value / oBrw:Value * 100 } )
      :cHeader          := "%"
      :cEditPicture     := "999.99 %"
      :bFooter          := { || aTot[ 2 ] / aTot[ 1 ] * 100 }
   END

   WITH OBJECT oBrw
      :bClrStd          := { || aColors[ oBrw:oTreeItem:nLevel ] }
      :cHeader     := "Area"
      :bFooter    := { || aTot[ 1 ] }
      :bFooter   := { || aTot[ 2 ] }
      :nStretchCol      := 1
   END

   oBrw:CreateFromCode()
   oBrw:OpenAll()

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

static function MakeTree( aTot )

   local oTree
   local cRegion, cCountry
   local oRegion, oCountry

   USE SALEDATA NEW ALIAS SD SHARED READONLY
   SET ORDER TO TAG AREA
   GO TOP

   TREE oTree

   do while !SD->( eof() )
      TREEITEM oRegion PROMPT SD->REGION CARGO { 0, 0 }
      cRegion     := SD->REGION

      TREE
      do while SD->REGION == cRegion
         TREEITEM oCountry PROMPT SD->COUNTRY CARGO { 0, 0 }
         cCountry := SD->COUNTRY

         TREE
         do while SD->COUNTRY == cCountry

            TREEITEM SD->CITY CARGO { SD->SALES, SD->MARGIN }
            oCountry:Cargo[ 1 ]  += SD->SALES
            oCountry:Cargo[ 2 ]  += SD->MARGIN

            SD->( DbSkip( 1 ) )
         enddo
         ENDTREE
         oRegion:Cargo[ 1 ]   += oCountry:Cargo[ 1 ]
         oRegion:Cargo[ 2 ]   += oCountry:Cargo[ 2 ]
      enddo
      ENDTREE
      aTot[ 1 ]   += oRegion:Cargo[ 1 ]
      aTot[ 2 ]   += oRegion:Cargo[ 2 ]

   enddo

   ENDTREE
   CLOSE SD

return oTree

//----------------------------------------------------------------------------//

static function createTestData()

   field REGION,COUNTRY,CITY

   local aCols := {  ;
      {  "REGION",   "C",  10,   0  }, ;
      {  "COUNTRY",  "C",  10,   0  }, ;
      {  "CITY",     "C",  10,   0  }, ;
      {  "SALES",    "N",  10,   0  }, ;
      {  "MARGIN",   "N",  10,   0  }  }

   local i,n,m

   DbCreate( "SALEDATA.DBF", aCols )

   USE SALEDATA EXCLUSIVE

   for i := 1 to 20

      APPEND BLANK
      n           := HB_RandomInt( 1, 4 )
      REGION      := { "AMERICAS","EUROPE","ASIA","OCEANA" }[ n ]
      m           := HB_RandomInt( 1, 2 )
      COUNTRY     := {{"USA","CANADA"},{"ITALY","SPAIN"},{"CHINA","INDIA"},{"AU","NZ"}}[ n, m ]
      CITY        := "City " + StrZero( i, 2 )
      n           := HB_Random( 10000,1000000 )
      m           := HB_Random( 1000, n * 0.1 )
      FIELD->SALES   := n
      FIELD->MARGIN  := m

   next i

   INDEX ON REGION+COUNTRY+CITY TAG AREA
   CLOSE DATA

return nil

//----------------------------------------------------------------------------//

You can use the above logic to create any number of levels

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: oTree for xBrowse sample...
Posted: Tue Dec 28, 2010 12:12 AM

Dear Mr. RAO,

Thanks so much for a great sample...

We can define number of levels by code..

What if the user wish to create level after level of tree using xbrowse? Is that possible with xbrowse (RDD)?

Regards,
Frances

HAPPY NEW YEAR!!!

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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: oTree for xBrowse sample...
Posted: Sat Jan 29, 2011 06:22 AM

Please also see the samples I posted here, using related DBFs to show as tree

viewtopic.php?f=6t=20761p=110295#p110295

&&

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: oTree for xBrowse sample...
Posted: Sun Jan 30, 2011 02:08 AM
nageswaragunupudi wrote:Please also see the samples I posted here, using related DBFs to show as tree

viewtopic.php?f=6&t=20761&p=110295#p110295




Thanks Mr. RAO... i've been waiting for your reply.

Your sample shows 2 level... i'm having problem with multiple level..

I hope you have a similar example.


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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: oTree for xBrowse sample...
Posted: Sun Jan 30, 2011 02:50 AM
fraxzi wrote:
nageswaragunupudi wrote:Please also see the samples I posted here, using related DBFs to show as tree

viewtopic.php?f=6&t=20761&p=110295#p110295




Thanks Mr. RAO... i've been waiting for your reply.

Your sample shows 2 level... i'm having problem with multiple level..

I hope you have a similar example.


Kind regards,
Frances

The logic for construction of trees is similar for any number of levels. Can you explain a situation where you are looking for a solution?
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion