## Lesson 3: Creating a mailing label report

In this lesson, we develop a Customer Contact Card report using the mailing label report 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 Report Set button .
2. In the New Report Set dialog, clear the text in the Report Title text box, select Mailing Label Report from the layout box, then click OK.

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

3. In the Data screen of the Mailing Label Report Wizard, check the New radio button.
4. Scroll down to Data Source 2 and expand the Queries node.
5. Click <Add Query...>, enter CustomerContactCard in the Input Query Name dialog and then click OK.
6. In the Query Editor, click Query > Add Table to add the Customer table to the query and select all columns in the table by choosing *.

7. Click OK at the bottom of the Query Editor to create the query.
8. Click Finish in the Mailing Label Report Wizard.

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 below one:

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 and define the formula in the Formula Editor as `@ContactFirstName + " " + @ContactLastName`.

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, clear 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 formula and DBFields to the report.

1. From the Resource View panel, drag the CustomerContactName formula to the Detail panel of the banded object, and then the ContactPosition DBField 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 and edit their text to "Phone:" and "Fax:" 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.

6. Resize the BandedPageHeader panel, add a label to it and edit the label 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:
   - 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, change their Font Face property to Arial and Font Size to 10.
3. Select the CustomerContactName formula and set its Bold property to true.
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 Ligntgray as well.
6. Resize the fields horizontally if data is truncated.

7. On the report tab bar, right-click the tab of the report and select Rename from the shortcut menu to rename the report as CustomerInformation.
8. Click File > Save to save the report set as CustomerContactCard.cls.
9. Click the View tab to preview the report. The report appears similar as below:

   Now, the report is ready to be printed.

10. 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 versions of the tutorial reports provided by JReport. To do so, you will need to save and close this catalog and open the TutorialReports.cat catalog file instead, which is located at `C:\JReport\Designer\Demo\Reports\TutorialReports`.

### Lesson 3 summary

In this lesson, we created a customer information report with the mailing label report 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.