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

  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 Query Editor, click Query > Add Table on the menu bar.
  5. In the Add Data dialog, expand the XML connection node, select the table Customer and click to add it to the query, then click OK to close the dialog.
  6. Select all columns in the Customer table by choosing * and then uncheck the NodePrimaryKey and NodeForeignKey columns.

  7. Click OK at the bottom of the Query Editor to create the query.
  8. 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:
  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:

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.