PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV 28 feature!
  • In this lesson you will learn 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 report to be printed from a menu option
  • Creating the context menu
  • Associating the context menu with the Table control
  • Print test
Lesson 4.5. Printing an order
In this lesson you will learn the following concepts
  • Creating a report based on a query.
  • Printing a report based on a query with parameters.
Lesson duration

Estimated time: 30 mn
Previous LessonTable of contentsNext Lesson
Overview
We will now give the user the possibility to print the details of the search order. The report can be directly printed via the context menu of the Table control.
  • 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 "Order form" report
First, we will define the data 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 the 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 the WINDEV project (Table control, Looper control, etc.).

Note

WINDEV proposes to create reports from several data sources: data files, queries, controls, text files, etc.
In most cases, it is recommended to group the data to be printed in a query and create a report based on it. To add data to the report, simply add the corresponding item to the query.
Reports based on data files must be simple reports, i.e. those displaying data from a single data file.

Creating the query

  • We will use the query editor to create the base query of the report.
    1. Click Creating an element in the quick access buttons. The new element window appears: click "Query­". The query creation wizard starts.
    2. Select the "Select" option.
      This query will allow you to select the records to be printed in the report. Go to the next step.
    3. The query description window appears. To build the query, we are going to select the elements that will be displayed in the result.
    4. Double-click the items in the analysis, to the left of the description window. The items taken into account are displayed in the middle of the screen.
      We will print the following data in the report:
      • the customer information. In the "Customer" data file, double-click the FullName, Address, ZipCode, City, and Country items.
      • the order information. In the "Order" data file, double-click the OrderID and Date items.
      • the product information. In the "Product" data file, double-click the Reference, Caption, and PriceBT items.
      • the order line information. In the "OrderLine" data file, double-click the Quantity and TotalBT items.
      • the order total price. In the "Order" data file, double-click the TotalBT and TotalIOT items.

        Note

        The order in which the items are inserted into the query is important. It is the order in which the data will be displayed in the report. The creation of the corresponding report will be simplified if this order is properly defined.
The query description window is as follows:
Query description
So far, this query is used to select all orders and the corresponding order lines.
We will select the data of a single order using an identifier. Therefore, we will define the order number as a parameter.

  • To manage the "Order ID" parameter:
    1. Select the Order.OrderID item (in the middle of the screen).
    2. Expand "Selection condition" and select "New condition".
    3. In the window that appears, we will specify that the selection condition corresponds to a parameter:
      Condition description
      Perform the following operations:
      • Select "Is equal to".
      • Check "the parameter".
      • The name of the parameter appears automatically: "ParamOrderID".
    4. Validate the condition description window. The number "1" appears to the right of the Order.OrderID 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 query description window ("OK" button).
    7. The save window is displayed. Validate the default information.
    8. The graphic query representation is displayed:
      Graphic representation

Creating the report based on a query

  • To create a report:
    1. Click Create an element in the quick access buttons.
    2. The new element window appears: click "Report" then "Report". The report creation wizard starts.
    3. The report creation wizard shows several types of reports:
      Report creation wizard - Type of report
    4. Select "Table". Go to the next step.
    5. Select the report data source. The report will be based on the query that was just created. Select "A data file or existing query".
      Report creation wizard - Data source
      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 if you want to add breaks to the report. No breaks will be used in this report. This concept will be presented later in this tutorial. Select "Don't insert breaks into the report". 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. This information does not need to 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. This information does not need to be repeated on each order line. For the OrderID and Date items, click the line corresponding to the item. In the "Block" column, expand the combo box and select "Page header".
      • Furthermore, we will change the caption of the "OrderID" item.
        • Select the line containing the OrderID item.
        • Click the Caption column and type "Order #".
          Changing the caption
        • The items regarding the order lines will be displayed in the report body. These items will be displayed for all the order lines.
      • The items regarding the order totals will be displayed in the page footer. This information does not need to 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 shows the different items assigned to the blocks in the same order they appear in the wizard:
        ItemBlock
        FullNamePage header
        AddressPage header
        ZipCodePage header
        CityPage header
        CountryPage header
        OrderIDPage 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 of 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.
      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.
    12. Go to the next step.
    13. In this step, you can:
      • Indicate if end users will be able to edit the report in "Reports and Queries".

        Express

        The option "Allow editing report in Reports and Queries" is not available in the Express version.
      • select the skin template of the report. It is recommended to use the same skin template as for the windows. In our case, select the "Phoenix" skin template and go to the next step.
    14. All we have to do now is give a name and a title to the report.
      • Enter the title : "Order form".
      • The "RPT_Order_form" name is automatically filled.
    15. Validate ("Finish").
    16. Since the report is too large to be printed in Portrait mode, the report editor proposes to use the landscape mode, reduce the table or print the table on multiple 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 mode in the report editor:
      Report editor
    20. The different order lines are grouped in a table.
  • Run this report by clicking Test element in the quick access buttons.
    1. The report editor asks for the print destination. The print destination can be:
      Choose print mode
      Select "Report viewer" and validate.
    2. The report editor requests the query parameters used by the report. Previously, we used a parameter to specify the number of the order to be printed. For the example, type the test value "1".
      Query parameters
      Validate.
    3. The report is displayed as we defined it in the report viewer.
      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).
      • Save the report as an HTML document.
      • Save the report as a PDF document.
      • Save the report as an XML document.
      • Create an email with an HTML version of the report in the message body.
      • Create an email and attach the report as a PDF document.
      • Annotate the document.
      • Perform a search in a document.
      • Add watermarks.
  • Close the report viewer.

Modifying the "Order form" report

We will make some changes to the layout of 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 will move the customer and order information to the page header:
    1. Delete the "Order form" caption from the page header.
    2. Delete the text to the left of the customer information (Full name, etc.).
    3. Move the item containing the city next to the zip code.
    4. Select the customer details and move them to the right of the report.
    5. Move up the order number and the order date (to the top of the "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 in the page footer.
    2. Move these controls to the lower-right corner of the table.
  • Change the print options of the "Page footer" block:
    1. Open the description window of the "Page footer" block:
      • Click the "Page footer" block.
      • Right-click to open the context menu 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 kept together with the previous blocks.
        Block description
    3. Validate the description window.
    4. The report is displayed in the report editor:
      Report editor
    5. Save the report by clicking Saving an element in the quick access buttons.
Our report is created.
Displaying the report to be printed from a menu option
In our application, the "RPT_Order_form" report will be printed from a context menu option in the Table control that lists the requested orders.
As already seen, the Table control contains 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 context menu. This menu will contain the WLanguage code used to print the report.
  2. We are going to link this context menu to the Table control and specify that the default context menu will be displayed just after the context menu defined for the Table control.

Creating the context menu

  • To create a context menu in the "WIN_Menu" window:
    1. Open the "WIN_Menu" window in the editor if necessary (double-click its name in the "Project explorer" pane for example).
    2. On the "Window" tab, in the "Bars and menus" group, expand "Popup menus" and select "New context menu".
    3. A new context menu appears in the editor. This menu option includes a single option named "Menu option".
      Context menu in edit mode
    4. Open the context menu description:
      • Select "Menu option".
      • Right-click to open the context menu.
      • Select "Context menu description".
    5. Name the context menu "MENU_Order" and validate.

      Note

      Context menus and windows
      Context menus are associated with the windows. If a window includes multiple context menus (window, control, etc.), they are saved with the window.
  • We are now going to define the option caption and write its WLanguage code.
    1. Select "Menu option".
    2. Press the Space key: the text becomes editable. Type "Print the order form" and validate.
    3. Display the WLanguage events associated with the option:
      • Select the option.
      • Right-click to open the context menu and select "Code".
    4. Write the following WLanguage code:
      // Print in the report viewer
      iDestination(iViewer)
      // Initializes the report query
      RPT_Order_form.InitQuery(TABLE_QRY_FindOrders.COL_OrderID)
      // Starts printing the report
      RPT_Order_form.Print()
      In this code:
      • iDestination is used to specify that the report will be printed in the report viewer.
      • <Report>.InitQuery is used to specify the parameters expected by the query associated with the report. In our case, the query expects the order number as parameter. This order number is in the COL_OrderID column of the TABLE_QRY_FindOrders Table control for the current row.
      • <Report>.Print 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 context menu.
    6. Save the "WIN_Menu" window.

Associating the context menu with the Table control

  • Last step: we are going to link the context menu to the Table control.
    1. In the "WIN_Menu" window, go to the "Find orders" tab.
    2. Open the Table control description ("Table description" in the context menu of the control).
    3. In the "UI" tab, expand the "Context menu" combo box.
    4. Check "Add a context menu", select the "MENU_Order" menu and select "At the beginning" to specify that the menu is placed before the system menu.
      Context menu
    5. Click inside the window to validate the context menu.
    6. Validate.

Print test

  • Now, all we have to do is run a real test:
    1. Test the "WIN_Menu" window.
    2. Select the "Find 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 context menu.
      Report test
    6. Close the report viewer and the test window.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 28
Comments
Click [Add] to post a comment