Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
One Table (Treeview)
Message
From
10/05/2006 19:28:21
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01120782
Message ID:
01120844
Views:
8
>Hi friends,
>
>I use to create one table for each information like this:
>
>Table_A                Table_B                Table_C
>ID_A  1-------+        ID_B   1--------+      ID_C
>GroupName     |        SubGroupName    |      ProductName
>              +----N   ID_A            +---N  ID_B
>
>
>This way is easy to get the products that are part of some subGroup or Group. But I have a problem here, because I limited it to 3 levels (Group / SubGroup / Product).
>
>Now I have a problem that I can't say 3 or 5 or 9 levels. So, I think I have to do that:
>
>Table_A               Table_C
>ID_A  1-------+---+   ID_C
>GroupName     |   |   ProductName
>ID_A_Main  N--+   +---N  ID_A
>
>
>So, I can add any number of levels I want. And I can't add a Product for a Group that has a "Main Group". Until here, no problem.
>
>My question is: After users add a lot of groups, they will want to get some information about one major group or any other level. Beside that, they will want to print a report divided by Group / SubGroup / SubSubGroup / ... / Product.
>
>Said that, I have no idea how handle it! Anybody can help me?

Rodolfo,
As always there are several ways (and the one here is not my favorite but shows a way to do it):
Select ;
  Padr(Padl(1,3,'_')+cust_id,20) As nodekey,;
  Space(20) As parentkey,;
  Padr(Company,100) As NodeText ;
  from (_samples+"data\customer") ;
  into Cursor crsTree ;
  readwrite

Insert Into crsTree (nodekey,parentkey,NodeText) ;
  Select ;
  padl(2,3,'_')+order_id As nodekey,;
  padl(1,3,'_')+cust_id As parentkey,;
  Textmerge('[<<order_id>>] <<order_date>>') As NodeText ;
  from (_samples+"data\orders")

Insert Into crsTree (nodekey,parentkey,NodeText) ;
  Select ;
  padl(3,3,'_')+order_id+padl(line_no,3,'_') As nodekey,;
  padl(2,3,'_')+order_id As parentkey,;
  '['+oi.order_id+'] item:['+Transform(oi.line_no)+'] '+pr.prod_name As NodeText ;
  from (_samples+"data\orditems") oi ;
  inner Join (_samples+"data\products") pr On oi.product_id = pr.product_id ;
  order By order_id,line_no


#Define tvwFirst	0
#Define tvwChild	4
Public oForm
oForm = Createobject('myForm')
oForm.Show

Define Class myForm As Form
  Height = 600
  Width  = 600
  DoCreate = .T.
  Caption = "TreeView sample"

  Add Object myTree As OleControl With ;
    Height = 600, ;
    Width = 600, ;
    OleClass = 'MSComCtlLib.TreeCtrl'

  *-- Fill the tree values
  Procedure filltree
    Select crsTree
    With This.myTree.nodes
      Scan
        If Empty(parentkey)
          .Add(,tvwFirst,nodekey,NodeText)
        Else
          .Add(parentkey, tvwChild, nodekey, NodeText )
        Endif
      Endscan
    Endwith
  Endproc

  Procedure Init
    With This.myTree
      .linestyle =1
      .labeledit =1
      .indentation = 5
      .Scroll = .T.
    Endwith
    This.filltree()
  Endproc
Enddefine
PS: Also check UT magazine June 2001 issue.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform