PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • This lesson will teach you the following concepts
  • Overview
  • Creating the "Order form" report
  • Creating the query
  • Creating the report based on a query
  • Modifying the "Order form" report
  • Displaying the printed report from a menu option
  • Creating the popup menu
  • Associating the popup menu with the Table control
  • Print test
Lesson 4.6. Printing an order
This lesson will teach you the following concepts
  • Creating a report based on a query.
  • Printing a report based on a query with parameters.

Estimated time: 30 mn
Previous LessonTable of contentsNext Lesson
Overview
We want to give the user the ability to print the details of requested order. The report can be directly printed via the popup menu of Table control.

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)". In this case, to follow the rest of the lesson, select the "Windows 32-bit executable" configuration in the project explorer.
Creating the "Order form" report
First of all, we are going to list the information that will be displayed in the report:
  • The order characteristics: date and order number.
  • The personal customer details: name, address, zip code, city and country.
  • The characteristics of order lines:
    • Ordered quantity,
    • Product reference,
    • Product caption,
    • Total BT,
    • Total IOT.
To easily create this report, the data to print will be grouped in a query. This query can be used by the report or by any other element of WINDEV project (Table control, Looper control, ...).

Note

WINDEV proposes to create reports from several data sources: data files, queries, controls, text files, ...
In most cases, we advise you to group the data to print via a query and to create a report based on this query. To add an information into the report, all you have to do is add the corresponding item into the query.
The reports based on data files must be simple reports, which means reports used to display data coming from a single data file.

Creating the query

  • The query editor will be used to create the base query of report.
    1. Click New among the quick access buttons. The window for creating a new element is displayed: click "Query­". The wizard for query creation starts.
    2. Select the "Select" option.
      Indeed, this query will be used to select the records that will be printed in the report. Go to the next step.
    3. The query description window is displayed. To build the query, we are going to select the elements that will be displayed in the result.
    4. Double-click the items found in the analysis on the left of description window. The items taken into account are displayed in the middle of the screen.
      We want to print in the report:
      • information regarding the customer. In the "Customer" data file, double-click the FullName, Address, ZipCode, City, and Country items.
      • information regarding the order. In the "Orders" data file, double-click the OrderID and Date items.
      • information regarding the product. In the "Product" data file, double-click the Reference, Caption, and PriceBT items.
      • information regarding the order line. In the "OrderLine" data file, double-click the Quantity and TotalBT items.
      • information regarding the grand total of order. In the "Orders" data file, double-click the TotalBT and TotalIOT items.

        Note

        The order in which the items are inserted into the query is important. Indeed, this order corresponds to the order used to display the data in the report. The creation of the corresponding report will be simplified if this order is properly defined.
The description window of query is as follows:
Description of query
At this time, this query is used to select all orders and the corresponding order lines.
We want to select the data corresponding to a single order whose identifier is known. Therefore, we are going to define the order number in parameter.
  • To manage the "Order identifier" parameter:
    1. Select the Orders.OrdersID item (in the middle of the screen).
    2. Expand "Selection condition" and select "New condition".
    3. In the window that is displayed, we are going to specify that the selection condition corresponds to a parameter:
      Describing a condition
      Perform the following operations:
      • Select "Is equal to".
      • Check "the parameter".
      • Specify the parameter name: "pOrdersID".
    4. Validate the description window of condition. The number "1" is displayed on the right of Orders.OrdersID item, indicating that a selection condition was defined.
    5. Give a name to the query: type "QRY_OrderForm" instead of "QRY_NoName1" in the "Query name" area:
      Query name
    6. Validate the description window of query (green button at the bottom of the screen).
    7. The save window is displayed. Validate the proposed information.
    8. The graphic query representation is displayed:
      Graphic representation

Creating the report based on a query

  • To create a report:
    1. Click on New among the quick access buttons.
    2. The window for creating a new element is displayed: click "Report" then "Report". The wizard for report creation starts.
    3. The wizard for report creation proposes several types of reports:
      Choosing the report type
    4. Select "Table". Go to the next step.
    5. Select the data source of report. The report will be based on the query that was just created. Select "From a data file or from an existing query".
      Data source of report
      Go to the next step.
    6. In the list of data files and queries, select the "QRY_OrderForm" query. Go to the next step.
    7. The wizard asks you to specify whether a break is required. No break will be used in this report. This concept will be presented later in this tutorial. Answer "No". Go to the next step.
    8. 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 the wizard, the items are listed according to the order defined in the query:
      • The items regarding the customer will be displayed in the "Page header" block. Indeed, this information must not be repeated on each order line.
        For the FullName, Address, ZipCode, City and Country items, click the line corresponding to the item. In the "Block" column, expand the combo box and select "Page header".
        Items to display
      • The items regarding the order will also be displayed in the "Page header" block. Indeed, this information must not be repeated on each order line. For the OrdersID and Date items, click the line corresponding to the item. In the "Block" column, expand the combo box and select "Page header".
      • Furthermore, we are going to modify the caption of "OrdersID" item.
        • Select the line containing the OrdersID item.
        • Click the Caption column and type "Order #".
          Modify the caption
        • The items regarding the order lines will be displayed in the report body. These items will be displayed on all order lines of order.
      • The items regarding the order totals will be displayed in the page footer. Indeed, this information must not be repeated on each order line. For the TotalBT_Or and TotalIOT items, click the line corresponding to the item. In the "Block" column, expand the combo box and select "Page footer".
        Display blocks
        The following table presents the different assignments of items in the order presented in the wizard:
        ItemBlock
        FullNamePage header
        AddressPage header
        ZipCodePage header
        CityPage header
        CountryPage header
        OrdersIDPage header
        DatePage header
        ReferenceBody
        CaptionBody
        PriceBTBody
        QuantityBody
        TotalBTBody
        TotalBT_OrPage footer
        TotalIOTPage footer
    9. Go to the next step.
    10. The wizard proposes to create a counter, a sum or an average on the numeric items found in the report. In this report, the calculations are performed by the query. Click the "No calculation" button. Go to the next step.
    11. This step is used to define the report layout.
      Paper size
      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.
    12. Go to the next step.
    13. This screen 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.
    14. All we have to do now is give a name and a title to the report.
      • Type the title : "Order form".
      • The "RPT_Order_form" name is automatically proposed.
        End of Wizard

        Express

        The option "Report modifiable in Reports and Queries" is not available in Express version.
    15. Validate.
    16. The report being too large to be printed in Portrait mode, the report editor proposes to use the landscape mode, to reduce the table or to print the table on several pages. In our case, accept the landscape mode.
    17. Accept to reduce the table if necessary.
    18. The window for saving the report is displayed. Validate the save information.
    19. The report is displayed in edit in the report editor:
      Report editor
    20. The different order lines are grouped in a table.
  • Run this report by clicking Report Go among the quick access buttons.
    1. The report editor asks for the print destination. The print destination can be:
      Print mode
      Choose "Print preview" and validate.
    2. The report editor asks for the parameters of query used by the report. Don't forget that a parameter was used to specify the number of the order to print. For the example, type the test value "1".
      Query parameters
      Validate.
    3. The report is displayed on the screen.
      Report test
      You can:
      • Print the current page or the entire document by clicking the printer.
      • Create a duplicate copy.
      • Select a different zoom value.
      • Save the report as a Word document (in RTF format).
      • Save the report in HTML format.
      • Save the report in PDF format.
      • Save the report in XML format.
      • Create an email with the report in HTML format in message body.
      • Create an email with the report in PDF format in attachment.
      • Annotate in the document.
      • Perform a search in a document.
      • Add watermarks.
  • Close the preview window.

Modifying the "Order form" report

We are going to perform modifications regarding the layout in the report that was just created.
  • Delete the number of pages displayed in the report:
    1. Select the [PAGENUM]/[NBPAGES] control.
    2. Press the Del key on the keyboard.
  • We want to position the information regarding the customer and the order in the page header:
    1. Delete the "Order form" caption found in page header.
    2. Delete the captions found in front of the customer information (Full name, ...).
    3. Position the item containing the city beside the zip code.
    4. Select the customer details and move them (with the mouse) to the right of report.
    5. Move the order number and the order date up (to the top of "Page header" block).
  • We are going to position the totals properly in the page footer:
    1. Select the controls (captions and items) corresponding to the totals found in the page footer.
    2. Position these controls with the mouse in the bottom right corner of table.
  • Modify the print options of "Page footer" block:
    1. Display the description window of "Page footer" block:
      • Click the "Page footer" block.
      • Display the popup menu (right mouse click) and select "Block description".
    2. In the "General" tab, check the following options:
      • Print the "End of document" block AFTER the "Page footer" block on the last page.
      • The "Page footer" block is not printed at the bottom of the page, it is stuck to the previous blocks.
        Describing a block
    3. Validate the description window.
    4. The report is displayed in the report editor:
      Report editor
    5. Save the report by clicking Save among the quick access buttons.
Our report is created.
Displaying the printed report from a menu option
In our application, the "RPT_Order_form" report will be printed from an option found in the popup menu of the Table control used to list the requested orders.
As already seen, the Table control proposes an automatic menu. We want to keep the options of this automatic menu and add an option that will be used to print the selected order form.
The principle is as follows:
  1. We are going to create a new popup menu. This menu will contain the WLanguage code used to print the report.
  2. We are going to link this popup menu to the Table control and specify that the default popup menu will be displayed just after the popup menu defined for the Table control.

Creating the popup menu

  • To create a popup menu in the "WIN_Menu" window:
    1. Open (if necessary) the "WIN_Menu" window in the editor (double-click its name in the project explorer for example).
    2. On the "Window" pane, in the "Bars and menus" group, expand "Popup menus" and select "New popup menu".
    3. A new popup menu appears in the editor. This menu option includes a single option named "Menu option".
      Popup menu
    4. Display the description of popup menu:
      • Select "Menu option".
      • Display the popup menu (right mouse click).
      • Select "Description of popup menu".
    5. Give a name to the popup menu ("MENU_Order") and validate.

Note

Popup menus and windows
A popup menu is associated with a window. If a window includes several popup menus (popup menu of window, popup menus of controls, ...), all these menus are saved with the window.
  • We are now going to define the option caption and its code.
    1. Select "Menu option".
    2. Press the Space key on the keyboard: the caption becomes editable. Type the new caption ("Print the order form") and validate.
    3. Display the code associated with the option:
      • Select the option.
      • Display the popup menu (right mouse click) and select "Code".
    4. Write the following code:
      // Print preview
      iPreview()
      // Initializes the report query
      iInitReportQuery(RPT_Order_form, ...
      TABLE_QRY_FindOrders.COL_OrdersID)
      // Starts printing the report
      iPrintReport(RPT_Order_form)
      In this code:
      • iPreview is used to specify that the report print will be performed in the print preview.
      • iInitReportQuery is used to specify the parameters expected by the query associated with the report. In our case, the query expects the order number in parameter. This order number is found in the COL_OrdersID column of the TABLE_QRY_FindOrders Table control for the current row.
      • iPrintReport is used to print the specified report (the RPT_Order_form report in our case).
    5. Close the code window and the window containing the popup menu.
    6. Save the "WIN_Menu" window.

Associating the popup menu with the Table control

  • Last step: we are going to link the popup menu to the Table control.
    1. In the "WIN_Menu" window, display the "Finding orders" tab.
    2. Select the Table control and display its description ("Table description" from the popup menu of control).
    3. In the "GUI" tab, expand the "Popup menu" combo box.
    4. Check "Add a popup menu", select the "MENU_Order" menu and select "At the beginning" to specify that the menu is placed before the system menu.
      Popup menu
    5. Click inside the window to validate the popup menu.
    6. Validate.

Print test

  • Now, all we have to do is run a real test:
    1. Run the test of "WIN_Menu" window.
    2. Select the "Finding orders" tab pane.
    3. Specify the criteria and start a search.
    4. Select one of the orders displayed in the Table control.
    5. Print the order via the popup menu.
      Report test
    6. Close the print preview and the test window.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment