PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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.

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 the WINDEV home page (Ctrl + <), click "Tutorial" and select "Full application (With windows)".
A full corrected application project is also available: in the WINDEV home page (Ctrl + <), click "Tutorial" and select "Full application (Answer)".
Creating the report
  • To create a report:
    1. Click New among the quick access buttons.
    2. The window for creating a new element is displayed: click "Report" then "Report". The report creation wizard starts. The wizard for report creation proposes several types of reports:
    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". 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.
      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. As we want to create a report used to list the customers by country and by state, we are going to 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.
      • 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 region, 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.
        Go to the next step.
    11. The wizard asks you to specify whether a break is required.

      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 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 performed on the country and it is used to group all the customers living in the same country.
    12. Answer "Yes". Go to the next step.
    13. Specify the sort item on which the break must be performed. In our case, we will be using several breaks:
      • the first break is performed on the country.
      • the second break is performed on the province.
      Uncheck the "Customer.FullName" item.
    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 found in the "Start of break 1" block. The "Country" item is automatically associated with the "Start of break 1".
      • only the state will be found 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. Go to the next step.
    16. This step is used to define the report layout.
      We will 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 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 "Gensteel" 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.
    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 among the quick access buttons. The print destination can be:
  • Choose "Print preview" and validate. The report is displayed on the screen.
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 the 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:
      • Display the popup menu (right mouse click).
      • Select "Add after".
    5. In the input area, type "Reports".
    6. Select the "Reports" option:
      • Display the popup menu (right mouse click).
      • Select "Transform to expand a sub-menu".
    7. In the input area that is displayed, type "List of customers". Press Enter to validate.
  • To type the code of "List of customers" option:
    1. Select the "List of customers" option in the editor.
    2. Display the popup menu (right mouse click).
    3. Select "Code". The code editor appears.
    4. Write the following code in the event "Selecting the menu":
      // The print is performed in a preview
      iPreview()

      // Prints the report
      iPrintReport(RPT_List_of_customers)
      Let's study this code:
      • iPreview (or iDestination) is used to configure the print destination. You have the ability to 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 print will be performed in the print preview.
      • iPrintReport is used to print a report.
  • Test the window and its menu options by clicking 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 mouse click), select "Transform to expand a sub-menu".
    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".
      • Validate.
    5. Display the option code and write the following 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 study this 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 among the quick access buttons.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment