|
|
|
|
|
- Lesson 6 - Printing the product catalog
- Overview
- Creating the report
- Report test
- Editing the report
- Removing captions
- Changing the product caption
- Product image, reference and description
- Product bar code
- Product price
- Product reorder date
- Report test
- Printing the report programmatically
- Adding an option to the Multiline Zone control
- Configuring the new option
- Programming the print functionality
- To sum up
Tutorial - Developing an Android and iOS application
Lesson 6 - Printing the product catalog We will cover the following topics: - Creating a form report.
- Printing the report.
20 mn This lesson will show you how to print the list of products by reference. To do so, we will create a form report to represent a data catalog. What is a report?A report provides a personalized view of information: data entered in the database, present in a text file, from a Table field, etc. The principle for creating a report is as follows: - the data to be printed comes from a data source (data file defined in an analysis, query, etc.).
- the report groups, sorts and formats the data.
The report can then be displayed in the mobile application as a PDF file.
Warning
This lesson is based on the WM Product Management example used in Lesson 1. To follow this lesson, you must have completed the steps from the previous lessons.
First, let's create a Form report. To do so, we will use the report creation wizard: - Click in the quick access buttons.
- The window for creating a new element is displayed: click "Report" then "Report". The report creation wizard starts. The report creation wizard proposes several types of reports:
- Select "Form". Go to the next step.
- Select the report data source. The report will be based on the Product data file. Select "A data file or existing query".
Go to the next step.
- Display the data files and select the "Product" data file.
Go to the next step.
- Define the data file search key. In our case, the Product data file will be looped through using the product's reference. Select the search key: "Reference".
Go to the next step.
- The wizard allows you to define the data sorting options in the report. By default, the wizard proposes the item used as search key in the data file.
Keep the default options and go to the next step.
- The wizard asks you if you want to insert breaks into the report.
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.
- We will not use breaks in this report. Select "Don't insert breaks into the report". Go to the next step.
- Specify the order in which the items will printed and how they will be distributed in the different blocks.
- ProductID will not be displayed in the report: uncheck ProductID.
- The items will be displayed in the Body block in the following order:
- Caption
- Photo
- Description
- Bar_Code
- Price
- Reference
- Quantity
- ReorderDate
- For each item, select the corresponding row and use the arrow buttons to the right to move it up or down in the list.
- Go to the next step.
- As the report displays numeric items, this step allows you to define if calculations should be performed in the report. In our example, no calculations need to be performed. Click the "No calculation" button.
Go to the next step.
- This step is used to define the report layout.
Keep the default values with the "Portrait" orientation.
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. - Go to the next step.
- This step allows you to select the report skin template. It is recommended to use the same skin template as for the windows. In our case, select "Material 3".
Go to the next step.
- Finally, give a name and a title to the report and save it.
- Enter name: "ETAT_Produit".
- Enter the title: "Product Catalog".
Warning
The name and title are different.
- Validate.
- The report is displayed in the report editor.
- Save the report (Ctrl + S).
The report is generated. We will now test the report to see the result. To test the report we have just created: - Click in the quick access buttons.
- In the print mode selection window, select "Report viewer".
- Validate. The report is run and displayed in the report viewer.
You can print the current page or the entire document by clicking the printer ("Print" tab). Close the report viewer. By using the report viewer, you can see how the report will actually look when printed. This print mode is only available during development of the mobile application. The wizard helped us obtain a ready-to-use report. To discover the features of the report editor, we will make some changes to the report created automatically so that it looks more like a product catalog. Removing captions In a report, the caption and the content of a control are independent of each other. For example, the product details are displayed by two controls: - a Static Text control that categorizes the details of the product ("Desc.:" in our report).
- a Static Text control bound to a data file item, which will display data.
In our case, to optimize the presentation of our report, remove the labels from the following fields: Label, Description, Strikethrough, Price and Reference. Changing the product caption We will display the text in Arial size 20. To do this: - Select the control that corresponds to the product name.
- Open the control description window (select "Description" in the context menu).
- On the "Style" tab, select the "Main caption" element.
- In "Font", select "Arial".
- In "Size", enter 20.
- Confirm changes and close the description window.
- Adapt the control size (select "Adapt size" in the context menu) and move it to the top left of the "Body" block.
Product image, reference and description Select the different controls in the page (Description, Bar code, Price, Reference and Reorder date) and move them to the right half of the report. Select the photo of the product. Enlarge this control and place it under the product caption. Reduce the control that contains the reference and move it below the product image. Select the control corresponding to the product description and move it to the right of the Image control. Reduce it if necessary. Product bar code The bar code of the product is displayed as plain text. We will replace it with a Bar Code control. - Delete the control that contains the bar code of the product.
- Select the controls below, and move them down.
- On the "Creation" tab, in the "Data" group, expand "Bar code" and select "EAN 128". Click in the report below the product description.
We will now bind the Bar Code control to the corresponding item in the data file: - Open the control description window (select "Description" in the context menu).
- On the "Binding" tab, select "Bar_Code" in the Product data file.
- Validate the control description window.
Product price We will modify the style of the product price so that it is visible in the catalog: - Move the price control to the right of the Bar Code control.
- Open the control description window (select "Description" in the context menu).
- On the "Style" tab, select the "Main caption" element.
- Make the following changes:
- In "Size", enter 20.
- Check the boxes "B" (Bold) and "I" (Italics).
- Confirm changes and close the description window.
- If necessary, enlarge the control to display the entire content.
Product reorder date Change the text of the "Reorder" control: - Select the "Reorder" control.
- Press the Space key on the keyboard: the label is modified.
- Enter "Reorder date".
- Validate (Press Enter).
- Open the context menu of the control and select "Adapt size".
Align the "Reorder date" control to the right: - Select the "Reorder date" control.
- On the "Modification" tab, in the "Quick edit" group, click the "Align right" icon.
- The date is automatically aligned to the right.
We will move the "Quantity" and "Reorder date" controls below the price: - Select the "Quantity" and "Reorder date" controls (and their corresponding items).
- Move them below the bar code.
Report test You will get the following report:
Save the report (Ctrl + S). The report is completed. We will now test the report to see the result. Run the report by clicking in the quick access buttons. Select "Report viewer" and validate. The report is run and displayed in the report viewer.
You can print the current page or the entire document by clicking the printer ("Print" tab). Close the report viewer and the simulator. Printing the report programmatically Now that our report is complete, we need to integrate a print functionality into our application. We will add an option to the Multiline Zone control in "WIN_Menu" to print this report.
Adding an option to the Multiline Zone control To insert a new option in "WIN_Menu": - Open the "WIN_Menu" window in the editor (e.g., double-click on it in the "Explorer" pane).
- Select the Multiline Zone control that contains the menu.
- Open the control description window (select "Description" in the context menu).
- On the "General" tab, add a new row between "Map of stores" and "Exit application":
- Click "New row".
- In the window that appears, select "Simple row with icon".
- Click "Finish".
- In the Multiline Zone control description, select the new row and move it up one position using the arrows (before "Exit application").
- Confirm changes and close the description window.
We will now modify the row we have just inserted.
Configuring the new option To change the image in the third row of the Multiline Zone control: - Click the Image control in the third row.
- Open the image description window (double-click the control).
- In the description window:
- Give a name to the image (e.g., "IMG_Print").
- Click on the right of "Image". Select "Catalog" in the context menu that appears to select an image representing the action.
- In the image catalog window, enter "Print" in the search box and press Enter.
- Double-click the image you want to select.
- In the image configuration window, select a size (80 for example, W (Width) = 80 and H (Height) = 80), give a name to the image (e.g., "Print") and validate.
- Validate the description window.
To change the text in the third row of the Multiline Zone control: - Click the Static Text control in the third row.
- Open the description window (double-click the control).
- In the "General" tab of the description window:
- Give a name to the control (e.g., "STC_Print").
- Change the caption (e.g., "Print catalog").
- Confirm changes and close the description window.
- The menu appears in the editor.
"Print catalog" appears in gray. We will copy the style of "Map of stores" and apply it to our new menu option: - Select "Map of stores".
- On the "Style" tab, in the "Style and skin template" group, select "Copy style".
- The mouse cursor turns into a brush.
- Click "Print catalog". This style is automatically applied to the control.
You get the following window: Programming the print functionality We will change the WLanguage code used to select the Multiline Zone control. - Select the Multiline Zone control.
- Open the associated WLanguage events (F2).
- Replace the line:
with:
CASE 3
iDestination(iGenericPDF)
RPT_Product.Print()
ShellExecute(iLastFile())
CASE 4
Close()
In this WLanguage code: - iDestination allows you to configure the print destination. In our case (a mobile application), the report we created will be printed as a PDF file using the iPDFGeneric constant.
- <Report>.Print prints the RPT_Product report. The corresponding PDF file is created.
- ShellExecute displays the generated PDF file in the PDF reader (returned by iLastFile) available on the current device.
- Save changes by clicking in the quick access buttons.
- Close the code window (click the "X" icon in the upper-right corner of the code editor).
Test the window and its menu options by clicking in the quick access buttons. In the simulator, the PDF file of the product catalog is generated and opened in the PDF reader installed in the current computer. Since the menu is also displayed as a sliding window in our example, the product catalog print option can also be added in the IW_MLZ_Options window. Completed project Do you want to check the end result of the steps described here?
A completed project is available. This project contains the windows and reports created and used in this lesson. To open the corrected project, on the home page, click on "Tutorial", then in the "Tutorial - Complete application with data" area, click on the "Open corrected project" link. In this lesson, we discovered how to create and edit a report, as well as how to print it programmatically. In the next lesson, we will see how to use web services in a WINDEV Mobile application.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|