PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
New WINDEV 25 feature!
  • This lesson will teach you the following concepts
  • Overview
  • Creating the report
  • Starting the report print by programming
Lesson 4.7. Printing a list of customers
This lesson will teach you the following concepts
  • Creating a report with breaks.
  • Starting the report print.
Lesson duration

Estimated time: 20 mn
Previous LessonTable of contentsNext Lesson
Overview
This lesson is used 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.

Answer

If you did not create the windows in the previous lessons, you can follow this lesson by opening a corrected project: in WINDEV's home page (Ctrl + <), click "Tutorial" and select "Full application (With windows)".
A full corrected application project is also available: in WINDEV's home page (Ctrl + <), click "Tutorial" and select "Full application (Answer)".
Creating the report
  • To create a report:
    1. Click Creating an element among 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 data source of report. The report will be based on the Customer data file. Select "From a data file or from an existing query".
      Report creation wizard - Data source
      Go to the next step.
    5. In the list of data files and queries, select the "Customer" data file. Go to the next step.
    6. Define the data file search key. In our case, the Customer data file will be browsed using the customer's full name. Select the "FullName" search key.
      Report creation wizard - Browsing the data file
      Go to the next step.
    7. We are now going to define the sort option of data 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 is displayed, select the Customer.Country item.
        Report creation wizard - Adding a 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. Modify the order of sort items. The customers must be sorted by country, by state, then in alphabetical order.
      • The "Customer.Country" item appears in second sort item. Select this item and move it in first sort item via the arrow buttons.
      • The "Customer.StateProvinceRegion" item appears in third sort item. Select this item and move it in second sort item via the arrow buttons.
        Report creation wizard - Data printing order
        Go to the next step.
    11. The wizard asks you to specify whether a break is required.

      Remark

      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 NECESSARILY linked to a sort.
      You will notice the presence of a break header and footer.
      The information common to the different rows is found in the break header.
      The totals, counters, ... are found 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 our case, we will be using 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
      We will keep the default values with the "Portrait" orientation.

      Remark

      Print margins
      When choosing the print margins, don't forget to take into account the physical margins of printers. The physical margins of printers are margins where no print is allowed. Furthermore, the physical margins differ according to the type of printer.
    17. Go to the next step.
    18. This step allows you to select the skin template used for the report. We recommend that you use the same skin template as the one used for the windows. In our case, select the "Phoenix" skin template for example and go to the next step.
    19. All we have to do now is give a name and caption to the report and save it.
      • Type 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
    23. The report is displayed in the report editor. Save the report.
The report is completed. Let's now run the report test to see the result.
  • Run this report by clicking Run the element test among the quick access buttons. The print destination can be:
    Choose print mode
  • Choose "Report viewer" and validate. The report is run and displayed in the report viewer.
    Displaying the report
You have the ability to print the current page or the entire document by clicking the printer ("Print" pane).
Starting the report print by programming
Our report being completed, we are going to create a menu in our "WIN_Menu" window to print this report directly.
  • To insert a menu into the "WIN_Menu" window:
    1. Display the "WIN_Menu" window in the editor (double-click its name in the "Explorer" pane for example).
    2. On the "Window" pane, 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:
      • Open the popup menu (right click).
      • Select "Add after".
    5. In the input area, type "Reports".
      Creating a menu option
    6. Select the "Reports" option:
      • Open the popup menu (right click).
      • Select "Transform to expand a submenu".
    7. In the input area that is displayed, type "List of customers". Press Enter to validate.
      Creating a menu option
  • To type the WLanguage code of the option "List of customers":
    1. Select the "List of customers" option in the editor.
    2. Open the popup menu (right click).
    3. Select "Code". The code editor appears.
    4. Write the following code in the event "Selecting the menu":
      // The report is printed in the report viewer
      iDestination(iViewer)
       
      // Prints the report
      iPrintReport(RPT_List_of_customers)
      Let's study this code:
      • iDestination allows you to configure the print destination. You can print:
        • 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 printed in the report viewer window.
      • iPrintReport is used to print a report.
  • Test the window and its menu options by clicking Run the element test among the quick access buttons.
  • We are now going to modify this menu by adding an option used to exit from the application.
    1. In the editor, select the "Menu" option.
    2. In the popup menu (right click), select "Transform to expand a submenu".
    3. In the input area that is displayed, type "Exit".
    4. We are going to associate this menu option with the "Alt + F4" shortcut:
      • Select the "Exit" option.
      • In the popup menu (right mouse click), select "Option description".
      • In the "General" tab, in the "Keyboard shortcut" area, select "F4" and check "Alt".
        Choosing a keyboard shortcut
      • Validate.
    5. Display the WLanguage code of the option and write the following WLanguage code in the event "Selecting the menu":
      // Asks the user whether he wants to exit from the application
      IF YesNo(No, "Exit from the 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 him a question. The user can give an answer to the question via 2 buttons: yes or no.
      • EndProgram (called if the user clicks "Yes") is used to end the application.
  • Run the window test by clicking test the element among the quick access buttons.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 25
Comments
Click [Add] to post a comment