Page 1 of 1

Mr. Rao Pls your help

Posted: Fri Jan 29, 2021 6:40 pm
by Armando
Hi. Mr. Rao:

Would you help us, we need make a tree in a xBrowse, this is our
code but it does not show us the records, why?

Code: Select all

#include "fivewin.ch"
#Include "Ado.ch"

FUNCTION TestTree()
   LOCAL oRsLoc, oDlg, oFont, oBrw

   oRsLoc := FW_OpenRecordSet(oApp:oCon,"SELECT " +;
                                          "* " +;
                                       "FROM " +;
                                          "Locales ",;
                                       "ORDER BY " +;
                                          "LOC_CAL,LOC_LOC",adLockOptimistic,adOpenDynamic,0)

   oRsLoc:MoveFirst()

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
    DEFINE DIALOG oDlg RESOURCE "TestTree"

        REDEFINE XBROWSE oBrw ID 200 OF oDlg;
            DATASOURCE oRsLoc;
            COLUMNS "LOC_CAL","LOC_LOC","LOC_GAS","LOC_LUZ","LOC_AGU","LOC_REN";
            HEADERS "Calle/Local","Local","Gastos","Luz","Agua","Arriendo";
         CELL LINES NOBORDER

         WITH OBJECT oBrw
            :SetTree( 2 )
            :oTree:OpenAll()
            :lDisplayZeros := .f.
         END

   ACTIVATE DIALOG oDlg CENTERED
   oFont:END()
RETURN(NIL)
 
With best regards

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 4:26 am
by nageswaragunupudi
This seems to be working with DBF but not ADO.
We are looking into it and will come back to you.
Please give us a little time.

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 10:48 am
by richard-service
nageswaragunupudi wrote:This seems to be working with DBF but not ADO.
We are looking into it and will come back to you.
Please give us a little time.
Dear Mr.Rao

How about use TMySQL? Compatible?

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 3:10 pm
by Armando
Mr. Rao:

Don't worry, take your time.

Regards

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 3:45 pm
by Armando
Mr. Richard:

I'm afraid not yet.

Regards

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 8:01 pm
by nageswaragunupudi
richard-service wrote:
nageswaragunupudi wrote:This seems to be working with DBF but not ADO.
We are looking into it and will come back to you.
Please give us a little time.
Dear Mr.Rao

How about use TMySQL? Compatible?
It should work with TMySql as it is.
It worked for me with FWH built-in MySql library.
This is my test.

Code: Select all

   oCn := maria_Connect( "localhost,fwh,root,password" )
   oRs := oCn:RowSet( "select * from customer order by state,city" )

   DEFINE DIALOG oDlg SIZE 800,600 PIXEL TRUEPIXEL
   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs ;
      COLUMNS "STATE", "CITY", "FIRST", "SALARY" ;
      CELL LINES NOBORDER

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

   ACTIVATE DIALOG oDlg CENTERED //ON INIT oBrw:SetTree( 2 )
 
Please try with TMySql and let us know.
You need to use "ORDERBY fld1, fld2" in your query and then use the same fld1,fld2 as the first two fields in xBrowse.

Problem is only with ADO.

Re: Mr. Rao Pls your help

Posted: Sat Jan 30, 2021 11:59 pm
by Armando
Mr. Rao:

Many thanks, I don't use TMySql at all. Just FWH, MySQL & ADO. :cry:

Regards

Re: Mr. Rao Pls your help

Posted: Sun Jan 31, 2021 12:49 pm
by nageswaragunupudi
My reply about TMySql was intended for Mr. Richard.

Re: Mr. Rao Pls your help

Posted: Sun Jan 31, 2021 1:24 pm
by nageswaragunupudi
The facility to convert a normal browse of ordered data into a Tree browse by calling oBrw:SetTree( nLevels, [aBitmaps] ) is working in case of datasources, which accept GOTO( 0 ) (similar to :BookMark := 0) and when Eof() returns blank values for fields. So, this is working with DBF, RowSets, Arrays, etc, but not with ADO.

Setting oRs:Bookmark := 0.0 errors out and when oRs:Eof() we can not access any field values.

For this reason, we need to modify xbrowse to handle ADO recordsets. These modifications are made in FWH 21.01.

We publish here the changes you can make to xbrowse.prg to make it work for ADO recordsets.

1) Please locate this line of code in the method SetTree(...) (line 7790 in FWH 2012)

Code: Select all

      bOnSkip     := { || Eval( bBookMark, ::oTreeItem:cargo ) }
 
Please replace this single line code with the following code:

Code: Select all

      if lAnd( ::nDataType, DATATYPE_ADO )
         bOnSkip     := { || If( Empty( ::oTreeItem:Cargo ),,Eval( bBookMark, ::oTreeItem:cargo ) ) }
         AEval( ::aCols, { |o| AdoTreeBlocks( o ) }, nLevels + 1 )
      else
         bOnSkip     := { || Eval( bBookMark, ::oTreeItem:cargo ) }
      endif
 
After making this change, add this static function anywhere in the xbrowse.prg.

Code: Select all

static function AdoTreeBlocks( oCol )

   local bEditValue  := oCol:bEditValue
   local oBrw        := oCol:oBrw

   oCol:bEditValue := { |x,o| If( Empty( oBrw:oTreeItem:Cargo ), ;
                              uValBlank( Eval( bEditValue ) ), ;
                              Eval( bEditValue, x, o ) ) }


return nil
 
With these two changes, your application code will work as expected.

Re: Mr. Rao Pls your help

Posted: Sun Jan 31, 2021 2:14 pm
by nageswaragunupudi
We discussed how to convert a normal browse of ordered data into a tree-browse at runtime. This is provided as an extra feature.

Still, the normal and standard way is to first create a tree object from the data and then browse the tree object.

Here is an example:

Code: Select all

#include "fivewin.ch"

function Main()

   local oCn, oRs, oTree, tmp
   local oDlg, oBrw

   oCn   := FW_OpenAdoConnection( "xbrtest.mdb" )
   if oCn == nil
      return nil
   endif
   oRs   := FW_OpenRecordSet( oCn, "SELECT * FROM CUSTOMER ORDER BY STATE,CITY,FIRST" )

   oRs:MoveFirst()
   TREE oTree
      do while !oRs:Eof()
         TREEITEM oRs:Fields( "state" ):Value ;
            CARGO { uValBlank( oRs:Fields( "first" ):Value ), uValBlank( oRs:Fields( "salary" ):Value ) }
         tmp := oRs:Fields( "state" ):Value
         TREE
         do while !oRs:Eof() .and. oRs:Fields( "state" ):Value == tmp
            TREEITEM oRs:Fields( "city" ):Value CARGO { oRs:Fields( "first" ):Value, oRs:Fields( "salary" ):Value }
            oRs:MoveNext()
         enddo
         ENDTREE
      enddo
   ENDTREE
   oRs:MoveFirst()
   oTree:OpenAll()

   DEFINE DIALOG oDlg SIZE 550,600 PIXEL TRUEPIXEL
   @ 20,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oTree COLUMNS 1, 2 ;
      HEADERS "STATE>CITY", "FIRST", "SALARY" ;
      CELL LINES NOBORDER

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

   ACTIVATE DIALOG oDlg CENTERED

return nil
 
Image