How to write Groups and Bands to group a table on a value?

  • I use WPTools 6 + WPReporter

    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

    How do I write the Groups and Bands?

    • Offizieller Beitrag


    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.

    Julian

    • Offizieller Beitrag

    Thats the template in WPT format

  • To make this example even simpler we will skip the address field.
    If the table has the following rows:

    Code
    1 Men Lars2 Women Anna3 Men Hans4 Women Lisa

    The result should be:

    Code
    Persons  Men    Hans    Lars  Count 	2  Women    Anna    Lisa  Count 	2


    If the table has the following rows:

    Code
    1 Women Lisa2 Women Anna3 Women Sara

    The result should be:

    Code
    Persons  Women    Anna    Lisa    Sara  Count 	3


    And if the table is emtpy

    Code

    The result should be, empty

    Code


    Questions:
    1. Can the text "Persons" be controlled by nesting groups or must it have its own code that checks the row count?
    2. 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?
    3. Is the sub header (in the example "Men" or "Women") to be in a HEADER band?
    4. Is the solution for the Count row to put it in a FOOTER?
    5. Do I have to put a filter on the table for each sub header, or is there an other way?
    6. Back to the original question. How do I write the Groups and Bands?

    • Offizieller Beitrag
    Zitat

    1. 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.

    Zitat

    2. 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.

    Zitat

    3. 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.

    Zitat

    4. 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.

    Zitat

    5. 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.

    Code
    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.

    Julian

  • This is how I solved it.

    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]


    <<#GROUP1 "Persons">>
    <<:HEADER>>
    Persons
    <<:DATA "Gender">>
    <<gender>>
    <<:DATA>>
    <<name>>
    <<:DATA "Count">>
    Count: <<Count>>
    <<#/GROUP1 "Persons">>

    Thank you for all the help!