FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Sun Mar 03, 2019 12:48 PM

Dear Mr Rao Sir ,

I need your help to create XBrowse Tree from MariaDB rowset which having recursive relationship parent / child in the same table columns having ( id , parent_id , name )

I have searched in the forum I found the example on MariaDB Xbrowse Tree but it is based on the Level. But do not know how many levels we have in the parent child relationship.

Could you please help / post the example for the same. Thanks in advance...!

Thanks
Shridhar

Thanks

Shridhar

FWH 24.04, BCC 7 32 bit, MariaDB
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Mon Mar 04, 2019 03:22 AM
Dear Sir ,

Created table in the DEMO DB server the table name is t_menu.

Code (fw): Select all Collapse
#include "fivewin.ch"

static oCn

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

function main

   if ( oCn := FW_DemoDB() ) == nil
      return nil
   endif

   oCn:lShowErrors := .t.



   CreateTables()
return nil

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

function CreateTables()

   local n, i, aDet := {}


   oCn:DropTable( "t_menu" )


   if !oCn:TableExists( "t_menu" )
      oCn:CreateTable( "t_menu", { ;
         { "menu_id"       ,  'N', 14, 0, "PRI" }, ;
         { "menu_name"     ,  'C', 50, 0 },;
         { "parent_menu_id",  'N', 14, 0 } } )

      oCn:Insert( "t_menu", "menu_id,menu_name,parent_menu_id", ;
         {  { 1, "Master" , nil }, ;
            { 2, "Transaction" , nil }, ;
            { 3, "Accounts" , 1 }, ;
            { 4, "Items"    , 1 }, ;
            { 5, "Others"   , 1 }, ;
            { 6, "Tax"      , 5 }, ;
            { 7, "Category" , 5 }, ;
            { 8, "Voucher"    , 2 }, ;
            { 9, "Quick Entry", 8 }, ;
            { 10, "Multple Entry", 8 }, ;
            { 11, "Inventory"    , 2 }, ;
            { 12, "Sales"        , 11 }, ;
            { 13, "Purchase"     , 11 }, ;
            { 14, "Returns"      , 11 }, ;
            { 15, "Sales Return" , 14 }, ;
            { 16, "Purchase Return" , 14 }, ;
            { 17, "Credit Note"    , 11 }, ;
            { 18, "Debit  Note"    , 11 }   } )
   endif

   xbrowser oCn:rowset( "t_menu" ) TITLE "MASTER TABLE"


return nil

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


Thanks
Shridhar
Thanks

Shridhar

FWH 24.04, BCC 7 32 bit, MariaDB
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Tue Mar 05, 2019 09:25 PM
Code (fw): Select all Collapse
#include "fivewin.ch"

static oCn

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

function Main()

   local oTree

   oCn   := FW_DemoDB()

   oTree := MakeRecurseTree()

   XBROWSER oTree COLUMNS 1 SETUP ( ;
      oBrw:cHeaders := { "Item", "Code" }, ;
      oBrw:aCols[ 1 ]:AddBitmap( { 0x30071, 0x30075, "c:\fwh\bitmaps\treevh.bmp" } ) ;
      )

   oCn:Close()

return nil

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

static function MakeRecurseTree( oParentItem )

   local oTree, aData, aItem, oItem
   local nParent  := 0

   if oParentItem != nil
      nParent  := oParentItem:Cargo[ 1 ]
   endif

   aData    := oCn:Execute( "SELECT * FROM t_menu WHERE IFNULL( parent_menu_id, 0 ) = ?", { nParent } )

   if !Empty( aData )

      TREE oTree

      for each aItem in aData
         TREEITEM oItem PROMPT aItem[ 2 ] CARGO aItem
         MakeRecurseTree( oItem )
      next

      ENDTREE

   endif

return oTree

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


Regards



G. N. Rao.

Hyderabad, India
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Wed Mar 06, 2019 07:50 AM

Dear Sir ,

Thank you very much...! You have made XBROWSE extremely powerful.

May I ask one suggestion / help on how we should detect of user selection of the menu, I mean the menu/item which does not have any child.

Thanks
Shridhar

Thanks

Shridhar

FWH 24.04, BCC 7 32 bit, MariaDB
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Wed Mar 06, 2019 08:00 AM

oBrw:oTreeItem is the current TreeItem.
oBrw:oTreeItem:Cargo --> { menu_id, menu_name, menu_parent_id }

Regards



G. N. Rao.

Hyderabad, India
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Sat Nov 14, 2020 08:43 PM

no entiendo la recursividad a la hora de crear un tree.

FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Tue Feb 16, 2021 06:45 PM

Can i to move a item group at another item group using xbrowse and tree?

FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?
Posted: Tue Feb 16, 2021 09:49 PM
goosfancito wrote:Can i to move a item group at another item group using xbrowse and tree?


Assume you want to move oItem1 (it may be a group or not) next to another item oItem2.
Then
Code (fw): Select all Collapse
oItem1:Delete()
oItem2:Add( oItem1 )
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion