Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Two Parent Problem
Message
De
13/07/2001 06:28:21
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
12/07/2001 23:51:59
Michael Gass
Instructional Software, Inc.
Kirkland, Washington, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00530093
Message ID:
00530139
Vues:
18
This message has been marked as the solution to the initial question of the thread.
>I would like to click on a company name in a company list box and have the jobs display for a person who's name is selected in a list of employees in a second list box. Each of these employees has multiple jobs in multiple companies so I would also like to click on a person's name in the employee list box and have the jobs display that the person has in the selected company from the first list box. At any point in time jobs are displayed for the selected person in the selected company.
>
>There must be an easy way to do this but it's not a typical many-to-many relationship. It's probably taught in Database 101 but I missed it. Any ideas?
>
>Thanks!

Michael,
You can get what you want with SQLs, right ? So you can do it with listboxes too. First w/o listboxes at all SQL would look like :
* Companies
select distinct company, compid ;
 from companies ;
 into cursor crsComps nofilter

* Employee 
* Assuming we don't want to restrict to employee of selected company
* Otherwise add a where clause like 
* where employee.compid = crsComps.CompId
select distinct lastname-(', '+FirstName) as EmpName, empid ;
 from employee ;
 into cursor crsEmployee nofilter

* Jobs with restrictriction to Company+Employee
select Job,JobExtra,JobId,CompId,EmpId ;
 from Jobs ;
 where Jobs.compid = crsComps.CompId ;
  and jobs.EmpId = crsEmployee.EmpId ;
 into cursor crsJobs
Now all you need is to make these into listboxes :)
*lstCompany.init
with this
 .Rowsourcetype = 3
 .RowSource = ;
[select distinct company, compid ]+;
[ from companies ]+;
[ into cursor crsComps nofilter]
 .ColumnCount = 1 && Don't want to show id and no need to play with columnwidts
endwith

* Gotfocus or some other place you want to refresh a listbox content
this.Requery() && For comapny we don't need this but using as a template
this.ListIndex = 0 && Again we don't need here but for only jobs probably
As you can see for listbox all we do is to 'stringify' SQL as RowSource :) You'd create the other listboxes the same way. You're free to have columncount 1-fcount() and only need to set columnwidths for columncount columns. You don't need to set boundto anything since you wouldn't use it at all. Instead you'd always use cursorname and fieldname to query a value. ie : at anytime you could get compid from companies listbox saying crsComps.CompID. Only exception to this is where you set listindex to 0. With SQL is rowsource record pointer moves in its cursor implicitly :)
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform