Page 1 of 1

How To XBRowse Tree From MariaDB Recordset Parent Child ?

Posted: Sun Mar 03, 2019 12:48 pm
by shri_fwh
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

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

Posted: Mon Mar 04, 2019 3:22 am
by shri_fwh
Dear Sir ,

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

Code: Select all

#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

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

Posted: Tue Mar 05, 2019 9:25 pm
by nageswaragunupudi

Code: Select all

#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

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

Posted: Wed Mar 06, 2019 7:50 am
by shri_fwh
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

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

Posted: Wed Mar 06, 2019 8:00 am
by nageswaragunupudi
oBrw:oTreeItem is the current TreeItem.
oBrw:oTreeItem:Cargo --> { menu_id, menu_name, menu_parent_id }

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

Posted: Sat Nov 14, 2020 8:43 pm
by goosfancito
no entiendo la recursividad a la hora de crear un tree.

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

Posted: Tue Feb 16, 2021 6:45 pm
by goosfancito
Can i to move a item group at another item group using xbrowse and tree?

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

Posted: Tue Feb 16, 2021 9:49 pm
by nageswaragunupudi
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

oItem1:Delete()
oItem2:Add( oItem1 )