Crystal Reports is one of the world's leading software packages for creating interactive reports. It provides developers with an array of tools for developing rich reports that can be published on the Web or integrated within Windows applications. This book provides a detailed guide to the functionality provided with Crystal Reports for Visual Studio .NET and shows you how to integrate reports into your .NET applications.
Who is this book for?
This book I s for programmers who want a comprehensive guide to the functionality included with Crystal Reports for Visual Studio .NET.
This book is mainly aimed at readers who have some experience with Crystal Reports. However, the book will also prove valuable to readers who are new to Crystal Reports, and want a guide to this reporting tool that is included within Visual Studio .NET.
This book will teach you how to:
Create reports with the assistance of the Expert
Integrate reports into Windows and web-based applications
Create XML Report Web Services
Work with ADO. NET
Use formulas and logic in reports
Develop distributed reporting applications
Deploy reporting applications
Introduction
Who Is This Book For?
What You Need to Use This Book
What Does This Book Cover?
Style Conventions
Customer Support
Sample Code and Updates
Errata
Technical Support
p2p.wrox.com
Chapter 1: Crystal Reports. NET Overview
What is Crystal Reports?
A Brief History
What Can You Do with Crystal Reports. NET?
How is Crystal Reports. NET Different from Previous Versions of Crystal
Reports?
Integrated Design Environment
Any Language, Any Time
Integration Methods
Ease of Use
Building Enterprise Applications
Report Architecture
Report Designer
Incompatibilities
Crystal Reports. NET Benefits
Leverage Existing Development and Skills
Tight Visual Studio .NET Integration
Windows and Web Report Viewers
Easy Deployment
ADO.NET
XML Report Web Services
Installing Crystal Reports. NET
Learning from Sample Applications
Installing Sample Applications
Sample Reports
Sample Data
Tutorials
Summary
Chapter 2: Getting Started with Crystal Reports. NET
The Sample Files
Planning Your Report Design
Creating a Crystal Report
Adding a Report to Your Application
Using a Report Expert
Working with the Report Design Environment
Menus and Toolbars
Setting Default Properties
Report Design Basics
Report Sections
Report Formatting
Field Objects
Sorting and Grouping
Record Selection and Filtering
Advanced Report Design Techniques
Charting and Graphing
Cross-Tabs
Subreports
Optimizing Report Performance
Summary
Chapter 3: Report Integration for Windows-Based Applications
Obtaining the Sample Files
Planning Your Application
Exploring the Development Environment
Starting a New Windows Application with VB.NET
Determining the Correct Object Model
Understanding the CrystalDecisions.Windows. Forms Namespace
Using the Crystal Report Viewer for Windows Forms
Adding a Report to your Application
Adding the Report Viewer to a Windows Form
Binding a Report to the Report Viewer
Passing Database Logon Info
Setting Report Record Selection
Customizing the Appearance and Layout of the Report Viewer
Viewer Methods
Using Viewer Events
Drilling into Report Details
Drilling Down on Subreports
Dealing with Report Exceptions
Summary
Chapter 4: Report Integration for Web-Based Applications
Obtaining the Sample Files
Planning Your Application
A Brief History of Crystal Web Development
Exploring the Development Environment
Before You Get Started
Starting a New Web Application with VB.NET
Determining the Correct Object Model
Understanding the CrystalDecisions.Web Namespace
Using the Crystal Report Viewer for Web Forms
Adding a Report to Your Application
Adding the Report Viewer to a Web Form
Binding a Report to the Report Viewer
Customizing the Appearance and Layout of the Report Viewer
Viewer Methods
Printing Your Report
Using Viewer Events
Summary
Chapter 5: Creating XML Report Web Services
Obtaining the Sample Files
XML Report Web Services Overview
What Are XML Report Web Services?
How Would I Use an XML Report Web Service?
Creating XML Report Web Services
Creating Basic Report Web Services
Creating Report Web Services with Multiple Reports
Utilizing the Generic Report Web Service
Consuming XML Report Web Services
External Report Web Service
internal Report Web Service
Generic Report Web Service
Deployment Considerations
Summary
Chapter 6: Working with .NET Data
The Sample Files
Data Access with Crystal Reports. NET
Database Files
Relational Databases
OLAP Data
Crystal Dictionaries, Queries, and Info Views
Other Data Sources
Working with Data Sources
Setting Database Options
Adding a Database or Table to a Report
Using the Visual Linking Expert
Verifying Database Structures Used in Your Report
Changing a Database Location
Setting a Database Alias
Working with SQL Commands and Expressions
Defining Virtual Tables
Creating SQL Expressions
Working with ADO.NET
An ADO.NET Dataset
Viewing the Contents of a Dataset
Creating a Report from an ADO.NET Dataset
Viewing Reports Containing an ADO.NET Dataset
Summary
Chapter 7: Formulas and Logic
Integrating Formulas and Logic into your Reports
Database Structures
Application Data
Crystal SQL Commands
Crystal SQL Expressions
Formulas
Working with the Formula Editor
Controlling the Editor's Appearance
Controlling the Syntax Type
Checking for Syntax Errors
Creating Formulas with Basic Syntax
What is Basic Syntax?
Basic Syntax Coding Conventions
Simple Operators
Arithmetic
Boolean
Comparison
Type Conversion
Summary Functions
String Functions
Date and Period Functions
Print State and Document Properties
Control Structures
If,,.Then Statements
Select Statements
Creating Formulas with Crystal Syntax
Differences from Basic Syntax
Creating Record Selection Formulas
Working with Conditional Formatting
Understanding Conditional Formatting
Conditional Formatting for Boolean Properties
Conditional Formatting for Multiple-Outcome Properties
Summary
Chapter 8: Working with the Crystal Reports Engine
Obtaining the Sample Files
Understanding the CrystalDecisions. CrystalReports. Engine Namespace
Customizing Reports Using the Report Engine
Getting Started
Printing and Exporting
Working with Databases
Working with Areas and Sections
Working with Report Objects
Summary
Chapter 9: Distributing Your Application
Distribution Overview
Getting Started
Setup Projects
Web Setup Projects
Merge Module Project
Setup Wizard
Basic Deployment Requirements
Operating System
Hardware
Deploying Windows Applications
Creating a New Setup Project
Selecting Project Outputs
Determining Runtime File Requirements
Adding Merge Modules
Working with Licensing
Building your Setup Project
Testing and Deploying your Setup Project
Deploying Web Applications
Preparing Your Web Server
Creating the Setup Project
Building your Setup Project
Testing and Deploying your Setup
Summary
Appendix A: Troubleshooting
Troubleshooting Resources
Crystal Decisions Knowledge Base
Crystal Decisions Library
Crystal Decisions Downloads
Crystal Decisions Technical Support
Microsoft Newsgroups
MSDN
Google Groups
Sources of Errors
Existing Reports
Report Designer
Database and Data-related
Subreports
Exporting
Windows Forms Viewer
Web Forms Viewer
XML Report Web Services
Appendix B: Migrating Applications to Crystal Reports. NET
Using Crystal Reports 8.5 in Visual Studio .NET
Our Sample Reports
A New Visual Basic .NET Report Viewer
Changing our Visual Basic .NET Report Viewer
Invalid Features in the Complex Report
Migrating from VB6
Our Sample Application
The Upgrade Wizard
The New Code
Summary
Appendix C: Crystal vs. Basic Syntax
Functions
Mathemetical
String Functions
Date/Time Functions
Arrays
Operators
Arithmetic
Conversion
String
Variable Declarations
Index
Welcome to Prossional Crystal Reports for Visual Studio .NET. Crystal Reports is one of the world's leading software packages for creating interactive reports. The reports let users view data and the trends therein, and they can be published on the Web or integrated within applications. With more than four million licenses shipped, Crystal Reports is the leader among Windows report writers. Crystal Reports has been in the Visual Studio box since 1993, but the latest version, Crystal Reports .NET, is now integrated more closely than ever before with Visual Studio .NET. This book will detail the functionality provided with Crystal Reports for Visual Studio .NET, and how, when, and where you should integrate reports into your .NET applications.
Why incorporate reports into applications? Virtually all applications need to present data to users, but any work beyond basic formatting - charts or conditional formatting, for example - can be very complex to program manually. In this book, we will provide you with the practical, high value, real- world information that you need to understand the array of tools that Crystal Reports for Visual Studio .NET provides for developers, so that you can immediately begin creating rich reports that can be integrated into your Windows and web-based applications.
We begin with an overview of Crystal Reports for Visual Studio .NET, introducing the technology and what we can use it for, and the benefits of integrating Crystal Reports with the .NET Framework. We then go on to create some reports, and learn how to integrate them into both Windows and web-based applications. We examine XML Web Services, and how to work with ADO.NET and formulas and logic in our reports, then finish by developing distributed reporting applications, and looking at how to deploy the applications we have created throughout the book.
This book does not attempt to be all-inclusive, and it will not teach basic .NET techniques. To be al~le to deliver a functional guide to Crystal Reports for Visual Studio .NET, we assume that you have a grasp of essential programming techniques, in this case, a knowledge of programming in Visual Basic .NET, and experience using Visual Studio .NET, and that you can apply these skills to a new technology.
Examples are carefully chosen to demonstrate the capabilities of Crystal Reports for Visual Studio .NET and aid you in understanding the techniques that you can apply when you begin to use this technology in your .NET applications.
Who Is This Book For?
This book is for programmers who want a comprehensive guide to the functionality included with Crystal Reports for Visual Studio .NET. It's assumed that you have some knowledge of .NET and experience with Visual Studio .NET.
This book is mainly aimed at readers who have some experience with Crystal Reports. However, the book will prove valuable for readers who are new to Crystal Reports, and want a guide to this free reporting tool they've discovered within Visual Studio .NET.
What You Need to Use This Book
There are software and knowledge requirements for successful progress through this book.Software
Microsoft Windows 2000 or XP Professional
Visual Studio .NET Professional or higher
SQL Server 2000 or MSDE
Knowledge
Some knowledge of the Visual Studio .NET development environment is assumed
Some very basic knowledge of SQL is assumed
What Does This Book Cover?
This book covers the features of Crystal Reports for Visual Studio .NET that you'll find yourself using time and again to build complex reports and integrate them into different .NET applications. We start by explaining how Crystal Reports fits into the .NET platform and how it differs from previous versions of Crystal Reports. Then, we discuss the key techniques we can use:
Creating reports using the Expert
Integrating reports into Windows and web-based applications
Creating XML Report Web Services
Working with ADO.NET
Using Formulas and Logic in our reports
Developing Distributed Reporting Applications
Deploying our applications
Chapter 1 - Crystal Reports. NET Overview: In this chapter, we take our first look at Crystal Reports for Visual Studio .NET (Crystal Reports. NET), including how the product is different from other version of Crystal Reports, how to find and run the sample applications that are included, and where to find the tutorials that will get you up to speed with the product. We will also take a look at the new Crystal Reports. NET architecture, and learn how it fits in to the .NET Framework. Whether you are an experienced application developer looking to move to Visual Studio .NET or you are developing your first application and have never heard of Crystal Reports, it all starts here.
Chapter 2 - Getting Started with Crystal Reports. NET: In this chapter, we will be looking at the Crystal Reports Designer within Visual Studio .NET and learn how to create and import reports for use in Windows or web applications. By the end of the chapter, we will have the skills to develop our own basic reports and can move on to the actual integration of these reports into our application. If you have used Crystal Reports before, some of the material in this chapter will be familiar.
Chapter 3 - Report Integration for Windows-based Applications: In this chapter, we are going to look at how to integrate and view the reports that we created in the last chapter from Windows applications, and how to customize our reports at run time using the rich object models provided. Throughout the chapter we will be looking at code examples to illustrate the use of various features and by the end of the chapter, we should be familiar with the majority of report integration concepts, and be ready to apply them to our own application development.
Chapter 4 - Report Integration for Web-based Applications: In this chapter, we are going to look at how to integrate and view reports from within web-based applications created with Visual Studio .NET. In addition, we will look at some of the run-time customizations that can be made to our reports, as well as some issues around web-application deployment. As we go through this chapter, we will be building forms for use in web-based reporting applications, which demonstrate many of the features of Crystal Reports. NET that can be used in our own web applications.
Chapter 5 - Creating XML Report Web Services: We have now seen how to integrate reports into Windows and web-based applications, but now we need to learn how to leverage those skills and work with XML Report Web Services. This chapter will teach us to identify what an XML Report Web Service is and understand how it can be used in our application. We will also create a Report Service from an existing Crystal Report and utilize the service with the Crystal Windows or Web Viewer.
Chapter 6 - Working with .NET Data: In this chapter we take a step back to look at what lies underneath the reports we have created - the data our report is based on and how Crystal Reports. NET uses this data. We will look at the way Crystal Reports works with different data sources and how it interacts with ADO.NET. At the end of this chapter, we will have an understanding of how Crystal Reports.NET interacts with different data sources, the options for working with these data sources, and how to use ADO.NET as a data source for our report development.
Chapter 7 - Formulas and Logic: This chapter will narrow our focus to look at where the majority of Crystal Reports development time is spent: writing formulas and logic. We will discover the best way to add calculations and logic to our reports, and learn enough syntax and code to handle most situations. We will also see how to differentiate between the two different 'flavors' of the Crystal Formula Language, and how to write our own record selection and conditional formatting formulas.
Chapter 8 - Working with the Crystal Reports Engine: In this chapter, we will be looking at the Crystal Reports Engine, the functionality it provides and some of the advanced integration techniques that we can use in our own application. We learn to identify when to use the Crystal Reports Engine namespace, how to integrate it into our application, and how to use the features contained within the properties, methods and events associated with the engine.
Chapter 9 - Distributing Your Application: Finally, with our development and testing finished, we will, in this chapter, look at one of the last steps in the software development life cycle - the actual deployment of our application to the end users. We will examine the tools Visual Studio .NET provides to help distribute applications, and how these tools can be used to distribute applications that integrate Crystal Reports. This chapter has been designed so that if you are only interested in deploying Windows applications, you can turn immediately to that section and get started. Likewise, if you are developing web applications, there is a separate section for web deployment. By the end of this chapter, we will be able to identify the set-up and distribution tools within Visual Studio .NET, and understand how they can be used to package and distribute our application. We will also be able to create a set-up package from an application that integrates Crystal Reports and successfully install it on a target machine.Style Conventions
We have used a number of different styles of text and layout in this book to help differentiate between the different kinds of information. Here are examples of the styles we used and an explanation of what they mean.
Code has several font styles. If it is a word that we are talking about in the text - for example, when discussing a For... Next loop - it is in this font. If it is a block of code that can be typed as a program and run, then it is in a gray box:
Private Sub Buttonl Click(ByVal sender As System. Object,
ByVal e As System. EventArgs) Handles Buttonl.Click
End Sub
Sometimes, you will see code in a mixture of styles, like this:
Private Sub Buttonl Click(ByVal sender As System. Object,
ByVal e AS System. EventArgs) Handles Buttonl.Click
MsgBox(TextBoxl.Text)
End Sub
In cases like this, the code with a white background is code that we are already familiar with. The line highlighted in gray is a new addition to the code since we last looked at it. Code with a white background is also used for chunks of code that demonstrate a principle, but which cannot be typed in and run on their own.
Advice, hints, and background in~brmation comes in this type of font.
Important pieces of information come in boxes like this.
Important Words are in a bold type font.
Words that appear on the screen, or in menus like File or Window, are in a similar font to the one you would see on a Windows desktop.
Keys that you press on the keyboard like Ctrl and Enter are in italics.
Commands that you need to type in on the command line are shown with a > for the prompt, and the input in bold, like this:
>something to type on the command line
Customer Support
We always value hearing from our readers, and we want to know what you think about this book: what you liked, what you didn't like, and what you think we can do better next time. You can send us your comments, either by returning the reply card in the back of the book, or by e-mail to feedback@wrox.com. Please be sure to mention the book's ISBN and title in your message.
Sample Code and Updates
As you work through the examples in this book, you may decide that you prefer to type in all the code by hand. Many readers prefer this because it is a good way to get familiar with the coding techniques that are being used. However, whether you want to type the code in or not, we have made all the source code for this book available at the Wrox.com web site.
When you log on to the Wrox.com site at http://www.wrox.com/, simply locate the title through our Search facility or by using one of the title lists. Now click on the Download Code link on the book's detail page and you can obtain all the source code.
The files that are available for download from our site have been archived using WinZip. When you have saved the attachments to a folder on your hard drive, you need to extract the files using a de- compression program such as WinZip or PKUnzip. When you extract the files, the code is usually extracted into chapter folders. When you start the extraction process, ensure your software (WinZip, PKUnzip, and so on) has Use folder names under Extract to: (or the equivalent) checked. The book assumes all of the code is located on your C: \ drive, so the path of the examples described in the book will begin c: \CrystalReports \ChapterXX\, where XX is the chapter number. If you extract the code to somewhere other than the C: \ drive, please keep this in mind when you are working with the examples.
Even if you like to type in the code, you can use our source files to check the results you should be getting - they should be your first stop if you think you might have typed in an error. If you don't like typing, then downloading the source code from our web site is a must! Either way, it will help you with updates and debugging.Registration for code download is not mandatory for this book, but should you wish to register for yourcode download, your details will not be passed to any third party. For more details you may view ourterms and conditions, which are linked from the download page.
Errata
We've made every effort to make sure that there are no errors in the text or in the code. However, noone is perfect and mistakes do occur. If you find an error in this book, like a spelling mistake or a faultypiece of code, we would be very grateful for feedback. By sending in errata, you may save anotherreader hours of frustration, and of course, you will be helping us provide even higher qualityinformation. Simply e-mail the information to support@wrox.com; your information will be checkedand if correct, posted to the errata page for that title, or used in subsequent editions of the book.
To find errata on the web site, log on to http://www.wrox.com/, and simply locate the title through ourSearch facility or title list. Then, on the book details page, click on the Book Errata link. On this pageyou will be able to view any errata that have been submitted and checked through by editorial.Technical SupportIf you wish to directly query a problem in the book with an expert who knows the book in detail then e-mail support@wrox.com. A typical e-mail should include the following things:
The book name, last four digits of the ISBN (7744 for this book), and page number of the problem in the Subject field.
Your name, contact information, and the problem in the body of the message.
We won't send you junk mail. We need the details to save your time and ours. When you send an e-mail message, it will go through the following chain of support:
1. Customer Support - Your message is delivered to one of our customer support staff, who
are the first people to read it. They have files on most frequently asked questions and will
answer anything general about the book or the web site immediately.
2. Editorial - Deeper queries are forwarded to the technical editor responsible for that book.
They have experience with the programming language or particular product, and are able
to answer detailed technical questions on the subject. Once an issue has been resolved,
the editor can post the errata to the web site.
3. The Authors - Finally, in the unlikely event that the editor cannot answer your problem,
they will forward the request to the author. We do try to protect the author from any
distractions to their writing, however, we are quite happy to forward specific requests to
them. All Wrox authors help with the support on their books. They will mail the customer
and the editor with their response, and again all readers should benefit.
Note that the Wrox support process can only offer support to issues that are directly pertinent to the content of our published title. Support for questions that fall outside the scope of normal book support is provided via the community lists of our http ://p2p,wrox.com/forum.
p2p.wrox.com
For author and peer discussion, join the P2P mailing lists. Our unique system provides programmer to programmerTM contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mail support system. Be confident that your query is being examined by the many Wrox authors, and other industry experts, who are present on our mailing lists. At p2p.wrox.com you will find a number of different lists that will help you, not only while you read this book, but also as you develop your own applications.
To subscribe to a mailing list just follow this these steps:
1. Go to http://p2p.wrox.com/and choose the appropriate category from the left menu bar.
2. Click on the mailing list you wish to join.
3. Follow the instructions to subscribe and fill in your e-mail address and password.
4. Reply to the confirmation e-mail you receive.
5. Use the subscription manager to join more lists and set your mail preferences.