FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

Once we build a Tree (LinkedList object), we can browse the tree by using

Code: Select all

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: Select all

#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
 
Image

Image

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
User avatar
Armando
Posts: 2479
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by Armando »

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

Ms. Rao,

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

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

Code: Select all


...

 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.

Image
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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

Mr. Rao,

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

Image

:D

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
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by byte-one »

Original:

Code: Select all

oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )
Fraxzi, you are using:

Code: Select all

oBrw:SetTree( 3, { 0x30082, 0x30084, 0x20097 } )
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

byte-one wrote:Original:

Code: Select all

oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )
Fraxzi, you are using:

Code: Select all

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
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

First, please try the sample below:

Code: Select all

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
 
Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
fraxzi
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

Mr. Rao,

Here's the result:

Image

:?:
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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by fraxzi »

:?:
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
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

I will get back to you
Regards

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

Re: FWH 1805 - oBrw:SetTree( [<nLevels>] ) -> Automatic Trees

Post by nageswaragunupudi »

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: Select all

   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
Post Reply