How To XBRowse Tree From MariaDB Recordset Parent Child ?

Post Reply
shri_fwh
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

How To XBRowse Tree From MariaDB Recordset Parent Child ?

Post 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
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 ?

Post 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
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

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

Post 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
Regards

G. N. Rao.
Hyderabad, India
shri_fwh
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

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

Post 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
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

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

Post by nageswaragunupudi »

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

G. N. Rao.
Hyderabad, India
User avatar
goosfancito
Posts: 1392
Joined: Fri Oct 07, 2005 7:08 pm

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

Post by goosfancito »

no entiendo la recursividad a la hora de crear un tree.
Un aporte chico hace grandes cambios.
Apoyemos al proyecto "Hogar pimpinela"
Bajate la aplicación (gratuita) y encuentra en ella toda la info de como podes colaborar.
GRACIAS!
https://play.google.com/store/apps/deta ... .acomprar
User avatar
goosfancito
Posts: 1392
Joined: Fri Oct 07, 2005 7:08 pm

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

Post by goosfancito »

Can i to move a item group at another item group using xbrowse and tree?
Un aporte chico hace grandes cambios.
Apoyemos al proyecto "Hogar pimpinela"
Bajate la aplicación (gratuita) y encuentra en ella toda la info de como podes colaborar.
GRACIAS!
https://play.google.com/store/apps/deta ... .acomprar
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

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

Post 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 )
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply