If I have a table "Persons" with the following columns:
ID Gender Name Address
And I would like a printout like this:
Persons// if persons.count > 0 Men// if men.count > 0
<<Name>> // the men's names
<<Address>> // the men's addresses Count: <<X>> // number of men Women// fixed header, if women.count > 0
<<Name>> // the women's names
<<Address>> // the women's addresses Count: <<X>> // number of women
<<#Persons>> // if persons.count > 0
<<#Men>> // if men.count > 0
<<:Data>>
<<Name/>> // the men's names
<<Address/>> // the men's addresses
Count: <<X/>> // number of men
<<#/Men>>
<<#Women>> // fixed header, if women.count > 0
<<:Data>>
<<Name/>> // the women's names
<<Address/>> // the women's addresses
Count: <<X/>> // number of women
<<#/Women>>
<<#/Persons>>
You need to write event handlers for the groups Persons, Men and Women to check the count in the query.
Atention: the <<# must be the first 3 chars of the paragraph.
To make this example even simpler we will skip the address field.
If the table has the following rows:
1 Men Lars2 Women Anna3 Men Hans4 Women Lisa
The result should be:
Persons Men Hans Lars Count 2 Women Anna Lisa Count 2
If the table has the following rows:
1 Women Lisa2 Women Anna3 Women Sara
The result should be:
Persons Women Anna Lisa Sara Count 3
And if the table is emtpy
The result should be, empty
Questions:
Can the text "Persons" be controlled by nesting groups or must it have its own code that checks the row count?
In my application it is not gender (Men or Women) as the sub header but an other field that can have up to 20 different values stored in the db. It would be nice not to duplicate the group 20 times. Any sugestion?
Is the sub header (in the example "Men" or "Women") to be in a HEADER band?
Is the solution for the Count row to put it in a FOOTER?
Do I have to put a filter on the table for each sub header, or is there an other way?
Back to the original question. How do I write the Groups and Bands?
Can the text "Persons" be controlled by nesting groups or must it have its own code that checks the row count?
Persons vs Person must be controlled by your code. You can use a calculated field here.
In my application it is not gender (Men or Women) as the sub header but an other field that can have up to 20 different values stored in the db. It would be nice not to duplicate the group 20 times. Any sugestion?
I would use a string field which insert the matching text. In one application I am building up "Adress" from verious fields and pass it to the event handler.
Is the sub header (in the example "Men" or "Women") to be in a HEADER band?
That is a data band since it comes after the outer group and before the inner group.
Is the solution for the Count row to put it in a FOOTER?
Thats also a field whichj is inserted when the inner group is finished. You use a calculated field here which is set to 0 when the inner group starts and incremented on each run.
Do I have to put a filter on the table for each sub header, or is there an other way?
One way is to create a query depending on the group name and start the group if the query is not empty. You have to continue the group if "Next" does not return false.
6. Back to the original question. How do I write the Groups and Bands?
The easiest would be using a simple report template designer. You need to check out the demo under Demos\WpReporter for that. It opens the field dialog which lets you insert and delete groups and bands and set the identifyer (alias).
Thats probably easier than using the token language.
In the event wptMergeBeforeProcessGroup I check the Alias and if it is:
"Persons": If Count = 1 then the table is opened, filtered and sorted. The group is printed if table is not Eof.
In the event wptMergePrepareText I check the Alias and if it is:
"Gender": It is printed if a query "Select Count ... where gender = [database field gender]" returns > 0. The query is only done if Count = 1 or Count > [result from query]
"Count": is printed if Count = [result from query]