PDA

View Full Version : Trouble with Tree Control and Mapped Table


ABC123

Jerry Gray
04-15-2008, 10:03 AM
Has anyone tried creating a Tree Control against a Mapped Table? I've been fighting this part time for about 4 days now.

I have a Mapped Table which includes 3 fields from 1 file and 1 field from another file.

I don't get any error messages, it is simply that the Tree Control won't expand. I have narrowed it down to the 1 field outside of the primary file in the Mapped Table. To verify the problem with the Mapped Table, I modified my primary file (Schedule_raw) to include the field (full_name_short) from the secondary file (Staff) and filled the field with an operation. Using the newly modified file, the Tree Control expands as expected.

Unfortunately, the only example of dynamically loading a tree (in the learning xdialog base) only expands as the branch is selected. I've worked with it enough to fry my brain. :eek:

Judging from other threads, I'm sure the question will be asked "Why are you using a Tree Control?"

For this particular file, it takes 3 fields to uniquely identify a record: Week_Ending, Employee_ID (or name) and Position. I suppose I could use 3 drop down lists to accomplish the same thing but the Tree Control seems more efficient from a user viewpoint. My intent is to return the 3 variables to query the file for schedule changes. If anyone knows of a better mouse trap, I am open to suggestion(s).

If needed, I can supply a zipped database but it should be easy to recreate from any application.

I will send a bug report if it can be verified by someone else.

Jerry Gray

Selwyn Rabins
04-15-2008, 09:35 PM
Has anyone tried creating a Tree Control against a Mapped Table? I've been fighting this part time for about 4 days now.

I have a Mapped Table which includes 3 fields from 1 file and 1 field from another file.

I don't get any error messages, it is simply that the Tree Control won't expand. I have narrowed it down to the 1 field outside of the primary file in the Mapped Table. To verify the problem with the Mapped Table, I modified my primary file (Schedule_raw) to include the field (full_name_short) from the secondary file (Staff) and filled the field with an operation. Using the newly modified file, the Tree Control expands as expected.

Unfortunately, the only example of dynamically loading a tree (in the learning xdialog base) only expands as the branch is selected. I've worked with it enough to fry my brain. :eek:

Judging from other threads, I'm sure the question will be asked "Why are you using a Tree Control?"

For this particular file, it takes 3 fields to uniquely identify a record: Week_Ending, Employee_ID (or name) and Position. I suppose I could use 3 drop down lists to accomplish the same thing but the Tree Control seems more efficient from a user viewpoint. My intent is to return the 3 variables to query the file for schedule changes. If anyone knows of a better mouse trap, I am open to suggestion(s).

If needed, I can supply a zipped database but it should be easy to recreate from any application.

I will send a bug report if it can be verified by someone else.

Jerry Gray

please send a bug report with an attached file that allows us to duplicate the problem.

there is one outstanding bug report on mapped tables involving a mapped table that joins two tables. When fields from the child table are used in a report, the wrong value is shown.

There is another outstanding bug report that involves an embedded browse on a form that displays a mapped table. the embedded browse displays fine, but if you put fields from the table on the form itself (not in the embedded browse), the browse and the stand-alone field are not synchronized as they should be. both bugs reports are actually the same bug. these bugs are on the bug list and will be fixed shortly.

it is possible that your bug is also actually the same as the two reported bugs, but we won't know until we see your example.

Jerry Gray
04-16-2008, 09:30 AM
Selwyn,

I wanted to do some more work before I sent a bug report. I'm glad I did, as I find that my tree works the same for both a Mapped Table and a Set.

I am still having problems but it doesn't appear to be linked to the Mapped Table.

The problem I'm having is that the tree expands properly for the week_ending date so it shows one record for each date. When a date branch is opened, it lists all of the records, not just the records for that date. This is my first venture into the trees and I must confess I'm thoroughly confused and afraid I've lost my way.

The file sche_w_name is a mapped table using schedule_raw as the primary file and staff as the second file. There are multiple records for each week_ending date. Within those records, a staff member can have multiple records, determined if they work in multiple positions. Each staff record can have only one position. I expect the tree to look something like:



week_ending
|_>full_name_short
|_>Position (i.e.Floor)
|_>Position (i.e.Deal)
|_>full_name_short
|_>Position (i.e. Floor)
etc...


I need to return the values for week_ending, employee_id and position to retrieve the record from schedule_raw for changes. It takes all three fields to uniquely identify the record.

I have attached a zipped database if someone wants to give me some pointers.

This is the script (Select_X_Mapped)for the tree. It started as Selwyn's example from Learning Xdialog, Lesson 12 - Tree Controls, "Select a customer - Populate dynamically from a table" example.



'Date Created: 28-Jun-2006 09:07:04 AM
'Last Updated: 16-Apr-2008 06:59:00 AM
'Created By : Selwyn
'Updated By : Owner
dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(dtoc(week_ending))+'|{EXPAND=Expanding tree...}!expandSname('+quote(alltrim(dtoc(week_ending)))+')'"
filterExpn = "week_ending<> { / / } .and.unique_key_value()"
orderExpn = "week_ending"
dim treeList as c
treeList = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
dim selected as c = ""
'The enable expression for the OK button looks to see if the 'selected' variable starts with 'ID:'
'If so, then we know we are at an endpoint in the tree.
dim flagOK as l = .f.
ui_dlg_box("Select Employee",<<%dlg%
[%X;S=BLR;D="|"%.50,20selected^<treelist];
{justify=right}
<10&OK!ok?left(selected,3)="ID:"> <Cancel>;
%dlg%,<<%code%
if a_dlg_button ="ok" then
flagOK = .t.
end if
%code%)

if flagOK = .t. then
ui_msg_box("","You selected employee number: " + substr(selected,5))

end if

function expandSname as c (Sname as c )
ui_yield()
dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(full_name_short)+'|{EXPAND=Expanding tree...}!expandPost('+ alltrim(Position) +')'"
filterExpn = "unique_key_value() .and. full_name_short=" + quote(Sname)
orderExpn = "week_ending" + "Sname"
expandSname = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
if expandSname = "" then
expandSname = "<None>"
end if

end function

function expandPost as c (post as c )
ui_yield()

dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(Position)"
filterExpn = "unique_key_value() .and. Position=" + quote(post)
orderExpn = "Position"
expandPost = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
if expandPost = "" then
expandPost = "<None>"
end if

end function

Thanks in advance,
Jerry Gray

Selwyn Rabins
04-16-2008, 11:41 AM
Selwyn,

I wanted to do some more work before I sent a bug report. I'm glad I did, as I find that my tree works the same for both a Mapped Table and a Set.

I am still having problems but it doesn't appear to be linked to the Mapped Table.

The problem I'm having is that the tree expands properly for the week_ending date so it shows one record for each date. When a date branch is opened, it lists all of the records, not just the records for that date. This is my first venture into the trees and I must confess I'm thoroughly confused and afraid I've lost my way.

The file sche_w_name is a mapped table using schedule_raw as the primary file and staff as the second file. There are multiple records for each week_ending date. Within those records, a staff member can have multiple records, determined if they work in multiple positions. Each staff record can have only one position. I expect the tree to look something like:



week_ending
|_>full_name_short
|_>Position (i.e.Floor)
|_>Position (i.e.Deal)
|_>full_name_short
|_>Position (i.e. Floor)
etc...


I need to return the values for week_ending, employee_id and position to retrieve the record from schedule_raw for changes. It takes all three fields to uniquely identify the record.

I have attached a zipped database if someone wants to give me some pointers.

This is the script (Select_X_Mapped)for the tree. It started as Selwyn's example from Learning Xdialog, Lesson 12 - Tree Controls, "Select a customer - Populate dynamically from a table" example.



'Date Created: 28-Jun-2006 09:07:04 AM
'Last Updated: 16-Apr-2008 06:59:00 AM
'Created By : Selwyn
'Updated By : Owner
dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(dtoc(week_ending))+'|{EXPAND=Expanding tree...}!expandSname('+quote(alltrim(dtoc(week_ending)))+')'"
filterExpn = "week_ending<> { / / } .and.unique_key_value()"
orderExpn = "week_ending"
dim treeList as c
treeList = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
dim selected as c = ""
'The enable expression for the OK button looks to see if the 'selected' variable starts with 'ID:'
'If so, then we know we are at an endpoint in the tree.
dim flagOK as l = .f.
ui_dlg_box("Select Employee",<<%dlg%
[%X;S=BLR;D="|"%.50,20selected^<treelist];
{justify=right}
<10&OK!ok?left(selected,3)="ID:"> <Cancel>;
%dlg%,<<%code%
if a_dlg_button ="ok" then
flagOK = .t.
end if
%code%)

if flagOK = .t. then
ui_msg_box("","You selected employee number: " + substr(selected,5))

end if

function expandSname as c (Sname as c )
ui_yield()
dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(full_name_short)+'|{EXPAND=Expanding tree...}!expandPost('+ alltrim(Position) +')'"
filterExpn = "unique_key_value() .and. full_name_short=" + quote(Sname)
orderExpn = "week_ending" + "Sname"
expandSname = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
if expandSname = "" then
expandSname = "<None>"
end if

end function

function expandPost as c (post as c )
ui_yield()

dim filterExpn as c
dim orderExpn as c
dim contentExpn as c
dim tablename as c
tablename = "sche_w_name"
contentExpn = "alltrim(Position)"
filterExpn = "unique_key_value() .and. Position=" + quote(post)
orderExpn = "Position"
expandPost = table.external_record_content_get(tablename,contentExpn,orderExpn,filterExpn)
if expandPost = "" then
expandPost = "<None>"
end if

end function

Thanks in advance,
Jerry Gray



I have not studied your example in detail, but if you look at the contents of your tree control when it is originally displayed, the string variable 'treelist' looks like this:



4/06/2008|{EXPAND=Expanding tree...}!expandSname("04/06/2008")
04/13/2008|{EXPAND=Expanding tree...}!expandSname("04/13/2008")
04/20/2008|{EXPAND=Expanding tree...}!expandSname("04/20/2008")

this makes sense. it means than when you expand an entry (say the entry for 4/06/2008), the function 'expandSname()' will be called and '04/06/2008' will be passed into the function).

on the other hand, after you exapand one of the top nodes, the 'treelist' variable looks like this:




04/06/2008|Darlene Soub|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Terry Tanner|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Christina Dossier|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Leilani Colder|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Tommy Garish|{EXPAND=Expanding tree...}!expandPost(Floor)
......
04/06/2008|Denise Runner|{EXPAND=Expanding tree...}!expandPost(Deal)
04/06/2008|John Dunlope|{EXPAND=Expanding tree...}!expandPost(Deal)
04/06/2008|Alice Wonder|{EXPAND=Expanding tree...}!expandPost(Deal)
04/13/2008|{EXPAND=Expanding tree...}!expandSname("04/13/2008")
04/20/2008|{EXPAND=Expanding tree...}!expandSname("04/20/2008")





this does NOT make sense.

it says that when you expand a second level node, the following function call will be made:

expandPost(Floor)

this will fail because there (presumably) is no variable called 'floor'.

I can't say for sure what you meant to do, but I presume you might have meant:

expandPost("Floor")

Howevever, even that does not seem to make sense as why would same function call be used for multiple people?

04/06/2008|Darlene Soub|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Terry Tanner|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Christina Dossier|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Leilani Colder|{EXPAND=Expanding tree...}!expandPost(Floor)
04/06/2008|Tommy Garish|{EXPAND=Expanding tree...}!expandPost(Floor)

Jerry Gray
04-16-2008, 01:44 PM
Selwyn,

When I looked at your example, it was a 3 level tree, State, City and Customer.

My data is 3 levels, Date, Name and Position.

The original tree level is Week_ending date which is expanded with the function expandSname. Names are expanded with the function expandPost.

Most names will have a single position record for each week. The first person who has 2 positions is Maria Wind.

I would think the records would have to be sorted so the two records for Maria Wind would be together in order for the expansion to work but they aren't. The second record for Maria Wind is positioned further down in the table. Also the names are not specific to the date selected in the tree.

The casino industry is a strange bird. A person can have several jobs at different pay rates (even different departments but we don't need to go there). On the schedule for my department, we have Floor supervisors and Dealers. The multiple position people are called Dual Rates; Floor supervisors some days and Dealers on the others.

For my development, I am working with a single shift schedule. It consists of 5 Floor Supervisors, 10 Dual Rates and 24 dealers. 5 + 10 + 10 + 24 = 49 records for 1 shift each week. A full schedule for this casino department would normally be around 120 records per week. Later, I will add a 4th level to the tree to show the shift the person works. I will probably do this as the top level.

If this gets applied to a large casino, there can be 600 to 800 records per week for the table games department.

Thanks for taking a look. I'm going to keep working on it, learning as I go.

Jerry Gray

Selwyn Rabins
04-16-2008, 01:51 PM
Selwyn,

When I looked at your example, it was a 3 level tree, State, City and Customer.

My data is 3 levels, Date, Name and Position.

The original tree level is Week_ending date which is expanded with the function expandSname. Names are expanded with the function expandPost.

Most names will have a single position record for each week. The first person who has 2 positions is Maria Wind.

I would think the records would have to be sorted so the two records for Maria Wind would be together in order for the expansion to work but they aren't. The second record for Maria Wind is positioned further down in the table. Also the names are not specific to the date selected in the tree.

The casino industry is a strange bird. A person can have several jobs at different pay rates (even different departments but we don't need to go there). On the schedule for my department, we have Floor supervisors and Dealers. The multiple position people are called Dual Rates; Floor supervisors some days and Dealers on the others.

For my development, I am working with a single shift schedule. It consists of 5 Floor Supervisors, 10 Dual Rates and 24 dealers. 5 + 10 + 10 + 24 = 49 records for 1 shift each week. A full schedule for this casino department would normally be around 120 records per week. Later, I will add a 4th level to the tree to show the shift the person works. I will probably do this as the top level.

If this gets applied to a large casino, there can be 600 to 800 records per week for the table games department.

Thanks for taking a look. I'm going to keep working on it, learning as I go.

Jerry Gray


You might find it helpful to take the 'tree_selectCustomer' script in learning xdialog and underneath the actual tree control, put a button:

<show>


then in the event handler section put this:


if a_dlg_button = "show" then
a_dlg_button = ""
showvar(treeList)
end if


now run the script and each time after you expand a node, click the button to see what's in the tree.

this makes is much easier to figure out what's going on.

it is really actually quite simple. the functions are executed to dynamically expand the tree. you should be able to test the functions that you write independently of the tree to make sure that the function calls are returning the correct data.

Jerry Gray
04-16-2008, 01:57 PM
Thanks Selwyn. That will help as it is trial and error at this point.

Jerry Gray

Now I can see how it's being built. Thanks again!