oTree for xBrowse sample...

Postby anserkk » Wed Oct 15, 2008 8:46 am

Thankyou Mr.Antonio
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Postby fraxzi » 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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Tree

Postby fraxzi » Fri Dec 24, 2010 9: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: Select all  Expand view

#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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: oTree for xBrowse sample...

Postby nageswaragunupudi » Fri Dec 24, 2010 4:39 pm

Code: Select all  Expand view
/*
*
*   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:Margin:Value / oBrw:Sales:Value * 100 } )
      :cHeader          := "
%"
      :cEditPicture     := "
999.99 %"
      :bFooter          := { || aTot[ 2 ] / aTot[ 1 ] * 100 }
   END

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

   oBrw:CreateFromCode()
   oBrw:oTree: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

Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: oTree for xBrowse sample...

Postby fraxzi » 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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: oTree for xBrowse sample...

Postby nageswaragunupudi » Sat Jan 29, 2011 6:22 am

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

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: oTree for xBrowse sample...

Postby fraxzi » Sun Jan 30, 2011 2: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
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: oTree for xBrowse sample...

Postby nageswaragunupudi » Sun Jan 30, 2011 2: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
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 80 guests