How To XBRowse Tree From MariaDB Recordset Parent Child ?

How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby shri_fwh » 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 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby shri_fwh » Mon Mar 04, 2019 3:22 am

Dear Sir ,

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

Code: Select all  Expand view

#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 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby nageswaragunupudi » Tue Mar 05, 2019 9:25 pm

Code: Select all  Expand view
#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

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


Image
Regards

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

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby shri_fwh » Wed Mar 06, 2019 7: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 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby nageswaragunupudi » Wed Mar 06, 2019 8:00 am

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

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

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby goosfancito » Sat Nov 14, 2020 8: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/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby goosfancito » Tue Feb 16, 2021 6: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/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: How To XBRowse Tree From MariaDB Recordset Parent Child ?

Postby nageswaragunupudi » Tue Feb 16, 2021 9: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: Select all  Expand view

oItem1:Delete()
oItem2:Add( oItem1 )
 
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests