Page 1 of 2

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

PostPosted: Sun Jul 08, 2018 1:14 am
by nageswaragunupudi
Once we build a Tree (LinkedList object), we can browse the tree by using
Code: Select all  Expand view

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  Expand view
#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.

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

PostPosted: Sun Jul 08, 2018 2:10 am
by Armando
Mr. Rao:

Excellent work, congratulations!.

Regards

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

PostPosted: Mon Jul 30, 2018 8:28 am
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  Expand view


...

 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

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

PostPosted: Mon Jul 30, 2018 9:45 am
by nageswaragunupudi
1) Keep sort asc
2) Let the first column be either numbers or dates. Let the data be uniform

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

PostPosted: Mon Jul 30, 2018 11:40 pm
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 ... :(

:?:

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

PostPosted: Tue Jul 31, 2018 1:07 am
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..

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

PostPosted: Tue Jul 31, 2018 10:55 am
by byte-one
Original:
Code: Select all  Expand view
oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )


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

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

PostPosted: Wed Aug 01, 2018 12:19 am
by fraxzi
byte-one wrote:Original:
Code: Select all  Expand view
oBrw:SetTree( oTree,  [aBitmaps], [bOnSkip], [aCols] )


Fraxzi, you are using:
Code: Select all  Expand view
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 ...\

:?:

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

PostPosted: Wed Aug 01, 2018 2:55 am
by nageswaragunupudi
First, please try the sample below:
Code: Select all  Expand view
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

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

PostPosted: Wed Aug 01, 2018 5:10 am
by fraxzi
Mr. Rao,

Here's the result:

Image

:?:

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

PostPosted: Wed Aug 01, 2018 5:58 am
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

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

PostPosted: Wed Aug 01, 2018 7:01 am
by fraxzi
Mr. Rao,

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

:?:

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

PostPosted: Thu Aug 02, 2018 7:29 am
by fraxzi
:?:

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

PostPosted: Thu Aug 02, 2018 7:55 am
by nageswaragunupudi
I will get back to you

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

PostPosted: Sat Aug 04, 2018 4:26 am
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  Expand view

   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.