### Lesson 3: Creating a mailing label report

In this lesson, we develop a Customer Contact Card report using the mailing label layout. This report can be used to print rolodex cards as well as mailing labels. On each card, the following information needs to be shown:

The data source for this report is our built-in XML data, predefined as Data Source 2 in the catalog.

This lesson contains the following tasks:

- Task 1: Define the query that the report uses
- Task 2: Add objects to the report
- Task 3: Edit object properties and print the report

#### Task 1: Define the query that the report uses

1. From the JReport Designer toolbar, click the New Page Report button .
2. In the New Page Report dialog, clear the text in the Report Title text box, select Mailing Label from the layout box, then click OK.

   Be sure that JinfonetGourmetJava.cat is specified as the current catalog because it is the catalog we use in this track. For information about specifying this catalog, see Task 1, Step 2 and 3 of Lesson 1.

3. In the Data screen of the Mailing Label Wizard, click <Add Query...> in the Queries node of Data Source 2, enter CustomerContactCard in the Input Query Name dialog and then click OK.

4. In the Add Table/View/Query dialog, expand the XML connection node and then the Tables node, then select the table Customer and click to add it to the query. Click OK to close the dialog.
5. In the Query Editor, select all columns in the Customer table by choosing * and then uncheck the NodePrimaryKey and NodeForeignKey columns.

6. Click OK at the bottom of the Query Editor to create the query.
7. Switch to the Style screen in the Mailing Label Wizard and select Simple as the report style, then click Finish to create the report.

The wizard is dismissed and the empty report with an empty banded object appears.

#### Task 2: Add objects to the report

1. Select and resize the Detail panel of the banded object, to make it similar to the one below:

We will use a simple formula to create a single value out of the customer's last and first names, and similarly to the address.

1. In the Resource View panel, select <Add Formula...> in the Formulas node.

2. Enter the formula name as CustomerContactName in the Input Formula Name dialog, click OK, define the formula in the Formula Editor as `@ContactFirstName + " " + @ContactLastName` (you can copy the formula to the formula editing area directly), click File > Save to save the formula, and then click File > Close to close the dialog.

3. Create another formula named CustomerContactAddress using the same way and define it as follows:

   `@Address1 + ", " + @City + ", " + @State + " " + @PostalCode`

Now we will use one of the JReport Designer's customizations that can simplify the creation of this report.

1. Click File > Options on the menu bar.
2. In the Options dialog, select Component, remove the checkmark from the Insert field name label with field checkbox and click OK.

We don't want to show the name labels of the DBFields in this report. Now we can add our formulas and DBFields to the report.

1. From the Resource View panel, drag the CustomerContactName formula in the Formulas node to the Detail panel of the banded object, and then the ContactPosition DBField in the Customer table to the right of it.

2. Use the same way to add the following fields:

3. Add two labels to identify the Phone and Fax DBFields by selecting the detail panel and clicking Insert > Label, resize the labels and edit their text to "Phone:" and "Fax:" respectively, select the two labels by holding the Ctrl key on the keyboard and change their Bold property to false in the Report Inspector, then the report displays as follows.

4. Insert a Line drawing object just above the CustomerName DBField by clicking Insert > Drawing Objects > Line.

5. Select the Detail panel of the banded object and add a Box drawing object to enclose all the objects in the panel by clicking Insert > Drawing Objects > Box.

6. Resize the BandedPageHeader panel, add a label to it by clicking Insert > Label, then resize the label and edit its text to Customer Contact Card as the title of the report.

#### Task 3: Edit object properties and print the report

1. Select the label in the BandedPageHeader panel and change its properties in the Report Inspector as follows:
   - Bold: false
   - Font Face: Arial
   - Font Size: 14
   - Foreground: Red
2. Select all the objects in the Detail panel except the Line and the Box drawing objects by holding the Ctrl key on the keyboard, change their Font Face property to Arial and Font Size to 10 in the Report Inspector.
3. Select the CustomerContactName formula and set its Bold property to true in the Report Inspector.
4. In the Report Inspector, select the Box object and change its Border Color property to Lightgray.

5. Select the Line object and edit its Line Color property to Lightgray and Line Thickness to 0.02.
6. Resize the fields horizontally if data is truncated.

7. Hide the BandedHeader, BandedPageFooter and BandedFooter panels that don't hold any data by right-clicking the panel and select Hide from the shortcut menu.
8. On the report tab bar, right-click the report tab and select Rename from the shortcut menu, then enter CustomerInformation in the Input Report Tab Name dialog and click OK.
9. Click File > Save to save the report as CustomerContactCard.cls.
10. Click the View tab to preview the report. The report appears similar as follows:

    Now, the report is ready to be printed.

11. Click File > Print and then specify the settings in the Print dialog according to your requirements.

Notes:

- It is recommended that you click File > Options again to enable the Insert field name label with field option in the Component category, so that later when you add fields to reports, their name labels will be added automatically.
- If the report does not look correct, you can compare it to the final version of the report provided by JReport. To do so, you will need to save and close this catalog and then open the JinfonetGourmetJava.cat catalog file located at `<install_root>\Demo\Reports\TutorialReports`.

#### Lesson 3 summary

In this lesson, we created a customer information report with the mailing label layout. In the report, customer's information is enclosed in boxes so that later we can print the report and make contact cards out of it.