FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour XBROWSE WITH oTREE OF 2 TABLES
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
XBROWSE WITH oTREE OF 2 TABLES
Posted: Sat Jun 16, 2018 02:28 AM

Greetings, I know that there is a lot of this, but I am really in relation to the most lost topic that Adan mothers day ...

I have 2 tables in mysql, one I have a product so I call it COMPOSITE and in another table the products that make it up ... Example ...
- PASTEL (composed by) - TABLE 1
* flour
* eggs <- TABLE 2
* milk
* etc.

I need to show in a xBrowse the product PASTEL and with a TREE the products that compose it with their respective quantities and cost of each component and that of the total cost of the PASTEL showing or not the products that compose it, I hope to have explained, I need the tip of the thread to start with this, greetings ... thanks ... :shock:

what I need is to show the information in an xBrowse with oTree, example:

code! description!

001! CAKE ! <--- COMPOSITE PRODUCT

! -> sugar <--- component 1

! -> flour <--- component 2

! -> milk <--- component 3

002! xPRODUCT!

GOOGLE TRANSLATOR...

TEMA ESPAÑOL:

viewtopic.php?f=6t=35738

&

Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE WITH oTREE OF 2 TABLES
Posted: Sat Jun 16, 2018 12:48 PM
I think you are using FWH Mariadb library.
I give you a sample using states and customer tables. You can adapt the logic to your recipes work.
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn, oRs, oCust, oStates, oTree

   oCn      := FW_DemoDB()

   oCust    := oCn:RowSet( "SELECT state,city FROM customer ORDER BY city" )
   oStates  := oCn:RowSet( "SELECT code,name FROM states ORDER BY name" )
   oStates:AddChild( oCust, "state = states.code" )

   oTree    := MakeTree( oStates )

   XBROWSER oTree SETUP oBrw:aCols[ 1 ]:AddBitmap( { FWDArrow(), FWRArrow() } )

   oCn:Close()

return nil

function MakeTree( oStates )

   local oTree
   local code, i, j

   oStates:GoTop()

   TREE oTree
   for i := 1 to oStates:KeyCount()
      TREEITEM oStates:name
      oStates:SyncChild()
      if oStates:oChild:KeyCount() > 0
         TREE
         for j := 1 to oStates:oChild:KeyCount()
            TREEITEM oStates:oChild:City
            oStates:oChild:Skip( 1 )
         next
         ENDTREE
      endif
      oStates:Skip( 1 )
   next
   ENDTREE

return oTree
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE WITH oTREE OF 2 TABLES
Posted: Sat Jun 16, 2018 02:46 PM
Another alternative
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn, oRs, oTree

   oCn      := FW_DemoDB()

   oRs   := oCn:RowSet( "SELECT c.state, s.name, GROUP_CONCAT( c.city ) AS cities FROM customer c LEFT JOIN states s on c.state = s.code GROUP BY c.state ORDER BY name" )
   oRs:GoTop()
   oTree := MakeTree( oRs )
   XBROWSER oTree TITLE "States and Cities" SETUP oBrw:aCols[ 1 ]:AddBitmap( { FWRArrow(), FWDArrow() } )

   oCn:Close()

return nil

function MakeTree( oRs )

   local oTree

   oRs:GoTop()

   TREE oTree
   do while !oRs:Eof()
      if !Empty( oRs:name ) .and. !Empty( oRs:Cities )
         TREEITEM oRs:name
         TREE
            AEval( HB_ATokens( oRs:Cities, "," ), <|c|
                              TREEITEM c
                              return nil
                              > )

         ENDTREE
      endif
      oRs:Skip( 1 )
   enddo
   ENDTREE

return oTree


Regards



G. N. Rao.

Hyderabad, India
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: XBROWSE WITH oTREE OF 2 TABLES
Posted: Sat Jun 16, 2018 04:31 PM

Greetings Mr. RAO, I am using mysql with tdolphin, little by little I will migrate to FWH Mariadb library, but for the moment I need to solve as I have now, I will guide me with the example I put and any questions, I will write again, thank you .. . :shock:

Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE WITH oTREE OF 2 TABLES
Posted: Sun Jun 17, 2018 02:30 AM
My second sample works with Dolphin, tmysql and ado.
But the limitation is that it can only display names. We can not have additional columns to show quantity, etc.
This sample has no such limitations. Works with Dolphin, tmysql and ado
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oCn, oRs, oTree

   oCn      := FW_DemoDB()

   oRs   := oCn:Query( "SELECT c.state, s.name, c.city, c.age, c.salary FROM customer c LEFT JOIN states s on c.state = s.code ORDER BY name" )
   oTree := MakeTree( oRs )
   XBROWSER oTree TITLE "States/Cities" ;
      SETUP ( oBrw:aCols[ 1 ]:AddBitmap( { FWRArrow(), FWDArrow() } ), ;
              oBrw:cEditPictures := { nil, "99", "999,999.99" }, ;
              oBrw:lDisplayZeros := .f., ;
              oBrw:cHeaders := { "Item", "Age", "Salary" } )

   oCn:Close()

return nil

function MakeTree( oRs )

   local oTree
   local cname

   oRs:GoTop()

   TREE oTree
   do while !oRs:Eof()
      if Empty( oRs:name ) .or. Empty( oRs:city )
         oRs:Skip( 1 )
      else
         TREEITEM oRs:name CARGO { 0, 0.00 }
         cname    := oRs:name
         TREE
         do while oRs:name == cname .and. !oRs:Eof()
            TREEITEM oRs:city CARGO { oRs:age, oRs:salary }
            oRs:Skip( 1 )
         enddo
         ENDTREE
      endif
   enddo
   ENDTREE

return oTree
.

Regards



G. N. Rao.

Hyderabad, India
Posts: 811
Joined: Tue May 06, 2008 04:28 AM
Re: XBROWSE WITH oTREE OF 2 TABLES
Posted: Wed Jun 20, 2018 05:58 AM

Hi Rao,

Relative to your sample, can I request for another sample using MariaDB Parent-Child record set showing 4 levels of sub-tree :?:

Please..

:D

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

Continue the discussion