PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV 27 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Creating the report
  • Printing the report through programming
Lesson 4.6. Printing a list of customers
In this lesson you will learn the following concepts
  • Creating a report with breaks.
  • Printing the report.
Lesson duration

Estimated time: 20 mn
Previous LessonTable of contentsNext Lesson
Overview
This lesson will show you how to print a list of customers, grouped by country and by state or province.
To do so, we are going to use a table report in order to clearly represent a list of data.
  • Open the project you worked on in the previous lesson.
    1. Go to the WINDEV home page (Ctrl + <).
    2. On the home page, click "Tutorial", then in "Part 4 - Full application with data", double-click "Full application (Exercise)".
    3. A dialogue box prompts you to open the project you worked on in the previous lesson. You can open the local copy or the original project. Select "Open the local copy".

Answer

A corrected project is available. This project contains the different reports created in this lesson. To open the corrected project, go to the home page and click "Tutorial", then in "Part 4 - Full application with data", double-click "Full application (Answers)".
Creating the report
  • To create a report:
    1. Click Creating an element in the quick access buttons.
    2. The element creation window appears: click "Report" then "Report". The report creation wizard starts. The report creation wizard proposes several types of reports:
      Report creation wizard - Type of report
    3. Select "Table". Go to the next step.
    4. Select the report data source. The report will be based on the Customer data file. Select "From a data file or existing query".
      Report creation wizard - Data source
      Go to the next step.
    5. In the list of data files and queries, select "Customer". Go to the next step.
    6. Define the data file search key. In our case, the Customer data file will be looped through using the customer's full name. Select the "FullName" search key.
      Report creation wizard - Loop through the data file
      Go to the next step.
    7. We will now define the data sorting options in the report. By default, the wizard proposes the item used as search key in the data file. Since we want to create a report to list customers by country and by state, we will add a sort on these two items.
    8. To add a sort on the country:
      • Click on "+" to add a sort item.
      • In the window that appears, select the Customer.Country item.
        Report creation wizard - New sort
      • Validate.
    9. To add a sort on the state:
      • Click on "+" to add a sort item.
      • In the window that is displayed, select the Customer.StateProvinceRegion item.
      • Validate.
    10. Change the order of the sort items. The customers must be sorted by country, by state, then in alphabetical order.
      • The "Customer.Country" item appears as the second sort item. Select it and move it to the first position using the arrows.
      • The "Customer.StateProvinceRegion" item appears as the third sort item. Select it and move it to the second position using the arrows.
        Report creation wizard - Data printing order
        Go to the next step.
    11. The wizard asks you if you want to add breaks to the report.

      Note

      What is a break?
      A Break is an operation used to group the records (or rows) according to one or more criteria. Caution, the records (or rows) will be printed.
      A break is ALWAYS linked to a sort.
      You will notice the presence of a break header and footer.
      The information common to the different rows is in the break header.
      The totals, counters, etc., ... are in the break footer.
      This break is used to group a set of records according to the same criterion. In our example, the break is set on the country and it is used to group all the customers living in the same country.
      Report creation wizard - Break
    12. Answer "Yes". Go to the next step.
    13. Specify the sort item on which the break must be set. In this case, we will use several breaks:
      • the first break is set on the country.
      • the second break is set on the state.
      Uncheck the "Customer.FullName" item.
      Report creation wizard - Break
    14. Go to the next step.
    15. You are going to specify the order in which the items will be printed and how they will be distributed in the different blocks. In our example:
      • only the country will be in the "Start of break 1" block. The "Country" item is automatically associated with the "Start of break 1".
      • only the state will be in the "Start of break 2" block. The "StateProvinceRegion" item is automatically associated with the "Start of break 2".
      • only the FullName, Address, ZipCode, City, StateProvinceRegion and Country items will be displayed in the report.
      Uncheck the CustomerID, Complement, Phone, Cell and Email items.
      Report creation wizard - Items to display
      Go to the next step.
    16. This step is used to define the report layout.
      Report creation wizard - Paper format
      Keep the default values with the "Portrait" orientation.

      Note

      Print margins
      When choosing the print margins, don't forget to take into account the physical margins of the printers. The physical margins of the printers are margins where no print is allowed. Furthermore, the physical margins may be different according to the type of printer.
    17. Go to the next step.
    18. This step allows you to select the report skin template. It is recommended to use the same skin template used on the windows. In our case, select the "Phoenix" skin template for example and go to the next step.
    19. Finally, give a name and a title to the report and save it.
      • Enter the title: "List of customers".
      • Keep the name proposed by default: "RPT_List_of_customers".
    20. Validate.
    21. Validate in order to switch to landscape mode.
    22. Accept to reduce the report by validating.
      Report in edit mode
    23. The report is displayed in the report editor. Save the report.
The report is completed. We will now test the report to see the result.
  • Run this report by clicking Test element in the quick access buttons. The print destination can be:
    Choose print mode
  • Select "Report viewer" and validate. The report is run and displayed in the report viewer.
    Report preview
You can print the current page or the entire document by clicking the printer ("Print" tab).
Printing the report through programming
Once our report is complete, we will create a menu in the "WIN_Menu" window to directly print the report.
  • To insert a menu into the "WIN_Menu" window:
    1. Open "WIN_Menu" in the editor (double-click its name in the "Project explorer" pane, for example).
    2. On the "Window" tab, in the "Bars and menus" group, expand "Main menu" and select "Add main menu".
    3. A menu is inserted into the window, below the title bar. This menu contains an option named "Menu".
    4. Select the "Menu" option:
      • Right-click to open the context menu.
      • Select "Add after".
    5. In the input area, type "Reports".
      New menu option
    6. Select the "Reports" option:
      • Right-click to open the context menu.
      • Select "Transform to expand a submenu".
    7. In the input area that is displayed, type "List of customers". Press Enter to validate.
      New menu option
  • To type the WLanguage code of the "List of customers" option:
    1. Select the "List of customers" option in the editor.
    2. Right-click to open the context menu.
    3. Select "Code". The code editor appears.
    4. Write the following code in the "Selecting the menu" event:
      // The report is displayed in the report viewer
      iDestination(iViewer)
       
      // Prints the report
      RPT_list_of_customers.Print()
      Let's analyze this code:
      • iDestination allows you to configure the print destination. You can generate a report to be printed:
        • in a text file,
        • in HTML format,
        • in PCL format,
        • in PDF, RTF, XLS or XML format,
        • on a fax.
        In our case, the report will be generated in the report viewer window.
      • <Report>.Print is used to print reports.
  • Test the window and its menu options by clicking Test element in the quick access buttons.
  • We will a menu option to exit the application.
    1. In the editor, select the "Menu" option.
    2. Right-click to open the context menu and select "Transform to expand a submenu".
    3. In the input area that appears, type "Exit".
    4. We are going to associate this menu option with the "Alt + F4" shortcut:
      • Select the "Exit" option.
      • Right-click to open the context menu and select "Option description".
      • In the "General" tab, in the "Keyboard shortcut" area, select "F4" and check "Alt".
        Keyboard shortcut
      • Validate.
    5. Open the WLanguage code of the option and write the following code in the "Selecting the menu" event:
      // Requires user confirmation to exit the application
      IF YesNo(No, "Exit application?") = Yes THEN
      // End of application
      EndProgram()
      END
      Let's take a look at this WLanguage code:
      • YesNo is used to establish a dialog with the user by asking a question. The user can answer the question via 2 buttons: yes or no.
      • EndProgram (called if the user clicks "Yes") is used to end the application.
  • Test the window by clicking test the element in the quick access buttons.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 27
Comments
Click [Add] to post a comment