FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees
Posted: Sun Jul 08, 2018 01:14 AM
Once we build a Tree (LinkedList object), we can browse the tree by using
Code (fw): Select all Collapse
oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] ).

Building a tree from a sorted set of data is a bit complex. Now, the method SetTree() simplifies the process by automating it.

Process:
First set up browse of the sorted data in the normal way from any datasource, viz., Array, DBF, Object, ADO of oQry.

Then, either during run-time or before, call oBrw:SetTree( [<nLevels>] ). nLevels defaults to 2. XBrowse automatically builds a tree object from the data using leftmost sorted columns up to the specified number of levels and also switches the browse to tree-view. We do not need to write any code for building the tree.

\fwh\samples\xbrtree.prg

You can see how simple it is to display the tree-view of any sorted data. This program also demonstrates how to toggle between tree-view and normal view.
Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX

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

function Main()

   RDDSETDEFAULT( "DBFCDX" )

   TestTree1()
   TestTree2()

return nil

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

function TestTree1()

   local oDlg, oBrw

   USE CUSTOMER NEW
   SET ORDER TO TAG STATE
   GO TOP

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL
   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE Alias()  ;
      COLUMNS "STATE", "CITY", "STREET", "ZIP", "AGE" ;
      CELL LINES NOBORDER

   oBrw:lDisplayZeros   := .f.
   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "TREE" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType == DATATYPE_RDD ;
      ACTION oBrw:SetTree( 3, { 0x30082, 0x30084, 0x20097 } )

   @ 10,200 BTNBMP PROMPT "DBF" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType != DATATYPE_RDD ;
      ACTION ( CUSTOMER->( oBrw:SetRDD( nil, nil, { "STATE", "CITY", "STREET", "ZIP", "AGE" } ) ), ;
               oBrw:GoTop() )

   ACTIVATE DIALOG oDlg CENTERED
   CLOSE CUSTOMER

return nil

function TestTree2()

   local oDlg, oFont, oBrw
   local aData, aTotal
   local aCols := { "1 AS State", "2 AS City", "3 AS Street", "4 AS Age", "5 AS Salary" }

   USE CUSTOMER NEW
   aData    := FW_DbfToArray( "STATE,TRIM(CITY),TRIM(STREET),AGE,SALARY" )
   CLOSE CUSTOMER

   aData    := FW_ArrGroupSum( aData, 1, , { 4, 5 } )
   ASORT( aData, , , { |x,y| If( x[ 1 ] == y[ 1 ], x[ 2 ] < y[ 2 ], x[ 1 ] < y[ 1 ] ) } )
   aTotal   := aData[ 1 ]
   ADel( aData, 1, .t. )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL FONT oFont

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aData COLUMNS aCols ;
      CELL LINES NOBORDER FOOTERS

   oBrw:cFooters := aTotal
   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "TREE" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType == DATATYPE_ARRAY ;
      ACTION ( oBrw:SetTree( nil, { 0x30082, 0x30084, 0x20097 } ) )

   @ 10,200 BTNBMP PROMPT "ARRAY" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType != DATATYPE_ARRAY ;
      ACTION ( oBrw:SetArray( aData, nil, nil, aCols ), oBrw:cFooters := aTotal )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil






The Second example also demonstrates the use of FW_ArrGroupSum() to automatically calculate group and grand totals of a sorted array.
Regards



G. N. Rao.

Hyderabad, India
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Sun Jul 08, 2018 02:10 AM

Mr. Rao:

Excellent work, congratulations!.

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Mon Jul 30, 2018 08:28 AM
Ms. Rao,

Can I use this "oBrw:SetTree( 3, { 0x30082, 0x30084, 0x20097 } )" on MariaDB RecordSet?

Based on FWH1805 sample "xbrtree.prg" and this:

Code (fw): Select all Collapse
...

 TEXT INTO cSQL

      select Cast(rdt_reqdat as char) as rdt_reqdat, rdt_mrnumb, rdt_mrdesc, rdt_reqnum from rdt_forms
      order by rdt_reqdat desc, rdt_mrnumb;

 ENDTEXT
 
 oRdtRS := oConn:RowSet( cSQL )
 
...

REDEFINE XBROWSE oBrw ID 1001;
         OF oFld:aDialogs[ 1 ] UPDATE;
         DATASOURCE oRdtRS AUTOSORT;
         COLUMNS 'rdt_reqdat','rdt_mrnumb','rdt_mrdesc','rdt_reqnum';
         HEADERS 'Req. Date','Ref. No.','Ref. Desciption','Req#'

         WITH OBJECT oBrw

             :lVscroll := .T.
             :lHscroll := .T.

             :aCols[4]:bStrData := {|| StrZero( oRdtRS:rdt_reqnum, 8 )}

             :SetTree( 2, { 0x30082, 0x30084, 0x20097 } )

         END 

...


Result: :-) :-) :-) ..it is eratic.

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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Mon Jul 30, 2018 09:45 AM

1) Keep sort asc
2) Let the first column be either numbers or dates. Let the data be uniform

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Mon Jul 30, 2018 11:40 PM
nageswaragunupudi wrote:1) Keep sort asc
2) Let the first column be either numbers or dates. Let the data be uniform



Mr. Rao,

I followed your advise but got the same erratic result ... :-)

:-)
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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Tue Jul 31, 2018 01:07 AM
Mr. Rao,

Same code as above but compiled with FWH1802 ... Better results but I loose FWH1805 enhancements :-)



:-)

Same good results with FWH1804 too..
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: 1048
Joined: Mon Oct 24, 2005 09:54 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Tue Jul 31, 2018 10:55 AM
Original:
Code (fw): Select all Collapse
oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )


Fraxzi, you are using:
Code (fw): Select all Collapse
oBrw:SetTree( 3, { 0x30082, 0x30084, 0x20097 } )
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Wed Aug 01, 2018 12:19 AM
byte-one wrote:Original:
Code (fw): Select all Collapse
oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )


Fraxzi, you are using:
Code (fw): Select all Collapse
oBrw:SetTree( 3, { 0x30082, 0x30084, 0x20097 } )



Hi Mr. Gunther,

it is based on Mr. Rao's sample "xbrtree.prg" from FWH1805/Release 01 ..

I wonder why the MariaDB Rowset I used differs ...\

:-)
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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Wed Aug 01, 2018 02:55 AM
First, please try the sample below:
Code (fw): Select all Collapse
function TestTree

   local oRs, oDlg, oBrw, cSql
   local oCn

   oCn   := FW_DemoDB()

   cSql  := "select * from customer where state > 'AA' order by state,city"

TEXT INTO cSql
 SELECT s.name as statename,city,street,zip,age
 FROM
 ( SELECT * FROM customer WHERE state > 'AA' ) c
 LEFT JOIN states s ON c.state = s.code
 ORDER BY statename,city
ENDTEXT

   oRs   := oCn:RowSet( cSql )

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL
   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs  ;
      COLUMNS "STATENAME", "CITY", "STREET", "ZIP", "AGE" ;
      CELL LINES NOBORDER

   oBrw:lDisplayZeros   := .f.
   oBrw:bBookMark := { |x| If( x == nil, oRs:nAt, oRs:nAt := x ) }
   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "TREE" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType == DATATYPE_ODBF ;
      ACTION oBrw:SetTree( 2, { 0x30082, 0x30084, 0x20097 } )

   @ 10,200 BTNBMP PROMPT "ROWSET" SIZE 150,30 PIXEL OF oDlg FLAT ;
      WHEN oBrw:nDataType != DATATYPE_ODBF ;
      ACTION ( oBrw:ResetData( oRs, { "STATENAME", "CITY", "STREET", "ZIP", "AGE" } ), ;
               oBrw:bBookMark := { |x| If( x == nil, oRs:nAt, oRs:nAt := x ) }, ;
               oBrw:GoTop() )

   ACTIVATE DIALOG oDlg CENTERED

   oCn:Close()

return nil


Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Wed Aug 01, 2018 05:10 AM
Mr. Rao,

Here's the result:



:-)
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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Wed Aug 01, 2018 05:58 AM

Thats correct
There are some invalid state codes and some blanks in the table.
This is a public database and anyone can enter data and there are many incomplete records.
Whatever the info is there, it is shown correctly

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Wed Aug 01, 2018 07:01 AM

Mr. Rao,

If you noticed, the display are consistently changing ... aren't they not supposed to?

:?:

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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Thu Aug 02, 2018 07:29 AM

:?:

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: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Thu Aug 02, 2018 07:55 AM

I will get back to you

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: FWH 1805 - oBrw:SetTree( [&lt;nLevels&gt;] ) -&gt; Automatic Trees
Posted: Sat Aug 04, 2018 04:26 AM
You are right. At present the logic works only with DBF. Even then, if the value of the second field in the first record is empty, the results may not be as expected.
We are in the process of fixing these issues and also extend this to Mariadb rowset also.

For now, you can test it with rowsets by adding a small workaround code:
Code (fw): Select all Collapse
   oBrw:bBookMark := { |x| If( x == nil, oRs:nAt, oRs:nAt := x ) }

while creating the browse.

To make it easy for you I have modified the sample in my above post, including this modification. Please test with this workaround.

For use in real life applications, we advise you to wait till next release and watch whatsnew.txt.
Regards



G. N. Rao.

Hyderabad, India