Using the Crystal Repository

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 5 - Working with the Crystal Repository
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

The repository in Crystal is a database in which certain report objects can be stored independently of their RPT files. Figure 5.1 depicts the concept of sharing a report object by extracting it from one report and adding it to different report. As a centralized resource, it can be used by any report you write.

click to expand
Figure 5.1. Sharing report objects

In Crystal Reports 9, the repository is implemented as a Microsoft Access 2000 database. You can use this database exactly as it is installed (the default behavior), or you can create your own repository database. Crystal Reports manages direct interactions with the database through a drag-and-drop interface in the Formula Workshop and several action buttons on Crystal dialog windows. The basic idea of the repository is twofold:

  • Add objects to the repository from a report.

  • Add repository objects to a report from the repository.

    Note 

    You do not need to have Microsoft Access installed on your machine to use the Crystal Repository; all that is required is the presence of the repository database in a location known to Crystal Reports and an ODBC connection to it. The information for the default sample database is configured for you when Crystal Reports is installed.

Opening the Repository

The Crystal Repository can be opened by choosing View > Repository Explorer from the menu or by clicking the toolbar icon.

The repository can store and share the following types of report objects:

  • Images (bitmaps)

  • Text objects

  • Commands (SQL commands)

  • Custom functions

Images, text objects, and commands can be accessed through the Repository Explorer shown in Figure 5.2. Custom functions are accessed through the Formula Workshop, which can be opened with the Formula Workshop toolbar icon.


Figure 5.2. The Repository Explorer

The Repository Explorer can be docked into position along the edge or can be dragged and dropped as a free-floating window. The images, text objects, and commands visible in Figure 5.2 are supplied with Crystal Reports. You can add objects to this list as well as delete the ones that are not useful to you.

There are two parts to the repository for viewing purposes. Notice in Figure 5.2 that no custom functions are visible in the repository. To see custom functions stored in the repository, you need to access the repository using the Formula Workshop and view the formula portion of the repository through the Workshop Tree. Figure 5.3 shows the Workshop Tree containing a custom function called SixSigma, which exists in the repository.


Figure 5.3. The Workshop Tree

The SixSigma custom function is currently in use by the open report; the vertical line connector symbol to the left of the function name denotes this.

Managing Repository Objects

The Images, Text Objects, and Commands folders that display by default in the repository are created automatically for you. You can add folders of your own to sort and manage the objects for your projects. To add a folder, select the name of the repository in the Repository Explorer; when the menu displays, choose New Folder and give the folder a name. Figure 5.4 shows the default set of folders, a custom folder named VistaNations as well as subfolders, and the menu used to create new folders. Folders can be nested in a hierarchy, one beneath the other, by selecting a folder and right-clicking to display the New Folder menu from the folder level.


Figure 5.4. The folders in the repository

You can also delete the default folders by right-clicking the folder and choosing the Delete option from the menu. Deleting a folder from the repository deletes the objects contained in the folder; in other words, the objects are deleted from the repository.

Warning 

Once an object is deleted from the Repository, there is no undo command to reverse the deletion. You can, however, re-create the object using the same name.

Adding Objects to the Repository

Objects are added to the repository in one of three ways depending on the object type. Use one of the following areas in Crystal Reports to add an object:

  • The report’s Design or Preview window

  • The Formula Workshop

  • The Database Expert

    Note 

    The name you give an object should be meaningful enough to give an idea of the purpose of the object.

You can drag text objects and bitmap images directly from their position in a report into a folder in the Repository Explorer window. After you drop the object into a folder, the Object Information dialog shown in Figure 5.5 displays. You can give the object a meaningful name, provide the author’s name, and type a description of the object. Selecting the object in the report and right-clicking it also displays a menu from which you can choose Add To Repository.

click to expand
Figure 5.5. Adding text and bitmap objects

Custom functions are added to the repository from the Formula Workshop. Select the function in the Workshop Tree, right-click it to display the submenu, and choose the Add To Repository option. You can also click the Add To Repository toolbar icon in the Formula Workshop after selecting the custom function.

Once a custom function is added to the repository, it is said to be “connected” to the repository; the vertical bar icon to the left of the function denotes that it is connected. The Add Customs Functions To Repository dialog displays at this point, as shown in Figure 5.6.


Figure 5.6. Adding custom functions

Adding SQL commands to the repository begins at the point when you select a data source using the Database Expert. When you choose a data source, the Add Command icon is an available option.

When you choose Add Command as a data source, the dialog shown in Figure 5.7 displays so that you can code a SQL command directly. To add the SQL command to the repository, enable the Add To Repository check box at the bottom left of the dialog.

click to expand
Figure 5.7. Adding a SQL command to the repository

The Add Item dialog, shown in Figure 5.8, displays; type a name for the object, set the name of the author, type a description, and choose a folder location in the repository to place the object. The default description is the SQL command itself.

click to expand
Figure 5.8. Describing a SQL command object

When you use a SQL command as a data source, it displays in the Database Expert with a “connected” icon to the left of its name. This is shown in Figure 5.9.

click to expand
Figure 5.9. A SQL command as a data source

Modifying Repository Objects

Modifying an object that is stored in the repository requires a few steps to accomplish the complete task. Objects in the repository are stored in Read-only mode; they cannot be changed directly in the repository. In addition, once an object has been added to a report, it is connected to the repository and therefore cannot be changed. To modify a repository object and update it in the repository, do the following:

  1. Drag the object from the repository into the report.

  2. Right-click the object and choose Disconnect From Repository.

  3. Modify the object.

  4. Right-click the object and choose Add To Repository.

Whenever you add an object to the repository, a dialog will appear asking you to give it a name. If you save it back into the repository using the same name it had previously, a confirmation dialog will appear to verify that you want to complete the task.

After a repository object is modified, a global report setting controls whether the change will be made available to the reports that use the object. All reports that use the repository object and are connected to it can potentially be affected by the changes you make, including changes to the object’s name and its contents. Report objects not connected to the repository are not affected. You can control whether repository changes are propagated to connected reports in two ways:

  • Use a global report setting to force updates to all report using it.

  • When the report is opened, choose to update the report.

To set a global option that will be in effect for all reports created that contain repository objects, choose File > Options, go to the Reporting tab, and enable the Update Connected Repository Objects When Loading Reports option shown in Figure 5.10.

click to expand
Figure 5.10. Setting a global option to update connected repository objects

Alternatively, you can make the decision to refresh from the repository when opening an individual report. When you open a report using the File > Open method, the dialog in Figure 5.11 displays. Notice the Update Repository Objects check box at the bottom of the dialog. This option is automatically enabled when the global report option is set and automatically disabled when it is not set. Use this option to override the global setting.

click to expand
Figure 5.11. Updating connected repository objects when a report is opened

Note 

The option to update repository objects is not available from the Crystal Reports welcome dialog (Welcome To Crystal Reports), which is often set to display automatically when Crystal Reports opens. You can choose to cancel out of this dialog and use the File > Open menu option.

Deleting Repository Objects

To delete an object from the repository, select the object in either the Repository Explorer (for images, text objects, and SQL commands) or the Workshop Tree (for custom functions), right-click the object, and choose the Delete option from the menu. You can also use the Delete key on the keyboard to delete a selected item.

Deleting an object from the repository does not affect the reports that previously used the object. This is true for both linked and unlinked repository objects. If an object is linked from a report to the repository and then deleted from the repository, the link is broken and a copy of the object remains in the report in editable mode. Likewise, if a linked repository object is deleted from the report, the link is broken, the report object is deleted, and the repository object remains intact.

Building a Report Using Repository Objects

Objects stored in the repository are globally available to all report designers using the repository. When an object is added to a report, the original object remains in the repository; a copy of the object is placed in the report. A link exists between the object in the report and its original in the repository. Linked objects have the advantage of being able to be automatically updated when you make a change to the object in the repository. When the object is in the report and linked or connected to the repository, however, the object is read-only and cannot be modified. Refer to the earlier section, “Modifying Repository Objects,” to learn how to update repository objects.

Adding a Repository Object to a Report

A repository object can be added to a report in several ways depending on the object’s type. Text objects and bitmap image objects can be added directly to a report from the Repository Explorer. Select the object and drag and drop it into position on the report.

Custom functions stored in the repository are added to a report from the Workshop Tree of the Formula Workshop. Expand the Repository Custom Functions Tree, select the custom function you want to use, and then click the Add To Report toolbar icon, as shown in Figure 5.12, or right-click and choose Add To Report from the menu.

click to expand
Figure 5.12. Adding a repository custom function to a report

The repository contains a set of prebuilt custom functions that may replace many of the User Function Libraries (UFL) in use in earlier versions of Crystal Reports applications. These custom functions have been coded for you and can be called from any report. They also make great examples to demonstrate how to code your own custom functions! You can also disconnect the function from the repository, modify it for your own purposes, and place it back in the repository. Table 5.1 lists the built-in custom functions in the repository and the folder category where they are located. The names of the functions are fairly descriptive and give you an idea of what each function does.

Table 5.1: Prebuilt Repository Custom Functions

Category

Function Name

Date

cdDateAddSkipHolidays

Date

cdDateAddSkipWeekends

Date

cdDateDiffSkipHolidays

Date

cdDateDiffSkipWeekends

Date

cdEasterDate

Date

cdFirstDayOfMonth

Date

cdFirstDayOfQuarter

Date

cdLastDayOfMonth

Date

cdLastDayOfQuarter

Date

cdSpecialDateRange

Date

cdStatutoryHolidays

Finance

cdConvertUSToCanadian

Format

cdFormatCurrencyUsingScaling

Format

cdFormatDateRange

Format

cdFormatDateRangeArray

Format

cdFormatNumberRange

Format

cdFormatNumberRangeArray

Format

cdFormatNumberUsingScaling

Format

cdFormatStringRange

Format

cdFormatStringRangeArray

Format

cdFormatTimeInterval

Geographic

cdExpandRegionAbbreviation

Geographic

cdExpandRegionAbbreviationCanada

Geographic

cdExpandRegionAbbreviationUSA

Math

cdIncreaseCurrencyByAPercentage

Math

cdIncreaseNumberByAPercentage

Math

cdPercentageDifference

SQL commands are added to a report by using the Database Expert to use a SQL command as a data source for a report; see the earlier discussion on this topic in the “Adding Objects to the Repository” section.

Disconnecting a Repository Object from a Report

Report objects that are linked to the repository cannot be edited. To edit them, they must first be disconnected from the repository. To do this, select the object in the report and right-click it. When the submenu displays, choose the Disconnect From Repository option. At this point, the disconnected report object can be edited.

Deploying Reports

An object in a report that has been added from the repository is a copy of the original object. As a copy, it is stored in the RPT file directly. The repository database is not needed when the report is opened for display. However, if the repository is available and the object is connected to the repository, it is available to be updated by the repository if any changes have been made to it since the time it was added to the report.

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net