Graham Brown (CompSYS) wrote:
> Hi all
> 
> I have a bit of problem with a system which I can't get my head around and
> wonder if anyone can do me a sanity check.
> What I have is two tables arranged in header/detail fashion. The key field
> between the two is a job number
> 
> Header table stru is for the sake of argument
> 
> Jobno
> Product to be made
> Qty required
> 
> Detail stru is
> 
> Jobno
> Item number
> Product to be issued
> Qty to be issued
> Child job
> 
> 
> Child job refers to a sub assembly job. So to make a computer (assuming I'm
> going to make a monitor!)
> 
> I have Job1, product is Computer, Qty 1
> The details for this job are
> J1, Item 1, Monitor,1 required, Child J4 which shows how to make a monitor
> J1, Item 2, Keyboard, 1, No child job
> J1, Item 3, Mouse, 1, No child job
> J1, Item 4, Tower, 1, Child job J12
> 
> J4 Header has Monitor,1,
> J4 Details has
> J4, Item 1, Monitor Case, 1, no child
> J4, Item 2, Buttons, 4, no child
> J4, Item 3, TFT Panel, 1, no child
> 
> J12 header would then have Tower, 1
> J12 details
> J12, Item 1, Case, 1, no child
> J12,Item 2, MB, 1 Child job J14
> 
> J14 would then drill down onto the motherboard and so on
> 
> With the application I can easily go 15 levels deep due to the way my
> customer sets up how they build things
> 
> What I need to do is get this info into a cursor so I can populate a
> treeview with it, I currently create cursor_level1 for the children in J1
> and then create another cursor for J4 then another cursor for J12 which is
> dog slow. I have complication that in my example above if the customer needs
> two computers then all qtys underneath must be multiplied by 2. However if
> it is one computer with 2 monitors then I'll need 2 monitor cases and 8
> buttons. This quantity ripples all the way down 15 levels or however many.
> 
> Could anyone assist with an SQL statement to show the hierachy in a cursor.
> 
> Cheers
> Graham

Hi Graham, sorry if I'm late.
Haven't used Treeviews but I guess that you want an order, defining
first the roots and then the branches. If that is so, all you need to
get is in which level every record stands.

select H.Jobno, H.Product, H.Qty, Item, D.Product as DProduct, ;
        D.Qty as DQty, D.ChildJob, 0 as Level ;
into cursor crsrTreeView
from Detail D ;
inner join Header H ;
        on H.Jobno = D.Jobno

do GetTView with 'crsrTreeView', 1

Now you order crsrTreeView by Level and whatever other field you need.
Then you start defining the root and branches according to level.
...
..
.

Procedure GetTView
lparameters lcTable, lnLevel

        local lcCursor, lcParentJobs

        lcCursor = sys(2015)
        lcParentJobs = sys(2015)

        select Jobno ;
        into cursor (lcParentJobs)
        from (lcTable) ;
        where Jobno not in (select ChildJob from (lcTable) ;
                                        where Level < lnLevel)

        if RecCount(lcParentJobs) > 0   && Increase Level
                select T.Jobno, Product, Qty, Item, ;
                        DProduct, DQty, ChildJob, ;
                        iif(!IsNull(PJ.Jobno), 1, 0) + Level as Level ;
                into (lcCursor) ;
                from (lcTable) T ;
                left join (lcParentJobs) as PJ ;
                        on PJ.Jobno = T.Jobno

                use in select(lcTable)
                use dbf(lcCursor) again in 0 alias (lcTable)
                use in select(lcCursor)
                do GetTView with lcTable, (lnLevel + 1)
        endif

return


Haven't tried the code (not even sure about syntax, just wrote it in
this mail) so it might not do exactly what it's meant to do, but you get
the general idea.
If you decide to try it, please tell me if it improved your previous
situation.
Cheers.



_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/[EMAIL PROTECTED]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to