Crystal Reports for Visual Studio .NET (WebFormSample)

xiaoxiao2021-03-05  27

Crystal Reports ®

For Visual Studio .NET®

Interactivity and Reports in Web Applications

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

2

© 2003 Crystal Decisions, Inc. Crystal Decisions, Crystal Reports, Crystal Enterprise,

Crystal Analysis, Crystal Services, Crystal Care, Crystal Assist, Crystal Applications, Info

And Holos Are Trademarks Or Registered TradeMarks of Crystal Decisions, Inc. In The U.S.

And / or Other Countries. All other trademarks or registered trademarks referened is

Property of their respective owners.

Version 2.0

Crystal Decisions, Inc.

895 Emerson Street

Palo alto, CA 94301

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

3

Interactivity and Reports in Web Applications

Introduction

You can use the integrated development Environment (IDE) in Visual Studio .Net to Create

INTERACTIVITY IN YOUR Application That Hosts Crystal Reports.

In this walkthrough, you will create a web copflication using active server pages.net

(ASP.NET) IN Visual Studio .Net. The Web Application Contains Two Web Form Controls: an

Image and a web forms viewer. it supports interactivity betWeen the user and the web

Forms viewer, and interactivity between the Web Forms viewer and the Image control.

For More Information and Updates, please visitur Web site at:

http://www.crystaldecisions.com/net.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

4

Outline of the Web Application

The Web Application Will Contain There Controls:

· A Web Forms Viewer Control Hosting a Report Containing a Group Tree and Three Charts

.

· An Image Control That Will Display A Flag Corresponding to the country the user has

Chosen from Chart A.

The chain of interactions

1. The User Selects a Country Through The Web Forms Viewer Control by Drilling Down in

Chart a of the report.

2. The Web Forms Viewer Updates ITS Display of The Report Based on The SELECTED country.

3. The Image Control Accepts The Chosen Country and Displays The Corresponding Flag for

That country.

Supporting files

The Following Report and Image Files Have Been Provided with this Walkthrough:

· Sales by country.rpt

USA.JPG

中文.jpg

· France.jpg

Germany.jpg

Italy.jpg

Others.jpg

They area Available for Download from Our Web Site as Supporting Files At:

http://www.crystaldecisions.com/net.

Create The Folder "Walkthroughfiles" Under The Directory C: / INETPUB / WWWROOT. COPY OR

Download The Report and Image Files To this Folder.

THE FOLLOWING Sections Explain How To Construct The Web Application Described Above, and

How to navigate in sales by Country.rpt in a Web Forms Viewer.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

5

Creating the Web Application

Below, you will create a Visual C # Web Application That Has A Web Forms Viewer Hosting

Sales by country.rpt, and an image control displaming the flag of the country the user HAS

Chosen through the report. Sales By Country.rpt Assumes That The Sample Database,

Xtreme.mdb, Has Been Installed on C: / Program Files / Microsoft Visual Studio .NET / CRYSTAL

Reports / Samples / Database During Setup for Visual Studio .NET.TO CHANGE The location of Xtreme.mdb

If you have installed xtreme.mdb at a location Other Than The Default (i.e., c: / program

Files / Microsoft Visual Studio 7 / Crystal Reports / Samples / Databases, you Should Do A Set

Location for sales by country.rpt. To do a set location:

IN Visual Studio .NET, SELECT

File |

Open |

FILE. THIS Invokes the

Open file dialog box.

2. in the

Open file dialog box, browse to the location c: / inetpub / wwwroot /

Walkthroughfiles, and specify the file sales by country.rpt. This opens sales by

Country.rpt in The Crystal Report Designer.

Note if The Crystal Decisions Registration Wizard Appears, You Can Choose To

Register The Crystal Report Designer At this point or at a later time.

3. In The Crystal Report Designer, Right-Click In A Report Area. Choose

Database |

Set

THIS INVOKES THE

Set location dialog box.

4. in the

Set location Dialog Box, Click The Down-Arrow Under

Current Data Source.

Select the data source assumed by Sales by Country.rpt,

C: / Program Files / Microsoft

Visual Studio .NET / CRYSTAL Reports / Samples / Database / Xtreme.mdb. You Will

Point this assumed location to the actual location of the database.

5. You May Use any one of these database technologies to connect the report to the actual

Data Source: OLE DB (ADO), ODBC (RDO), Database Files (I.E., Using Native Drivers), OR

ADO.NET (XML) (Which Is Under

More Data Sources). For the purpose of this

Walkthrough, Under

Replace with, Double-Click

OLE DB (ADO). THIS INVOKES THE

Ole

DB (ADO) Dialog Box.

Note if you are already connect to xtreme.mdb, proceed with step 9. or, if you

Are Connected To Another Database THROUGH OLE DB (ADO), SELECT Make NewConnection.

6. in the

OLE DB (ADO) Dialog Box, Highlight The Old DB Provider,

Microsoft Jet 4.0

OLEDB Provider. Then Click The

Next button.

7. Provide the necessary information to access the actual data source: for

Database

Name, Click The Square Button Adjacent To The Entry Box. SELECT Xtreme.mdb According

To where you have installed it. click

NEXT.

8. Update Any Advanced Information For your data source, if Necessary. Then Click

Finish.

You will be returned to the

Set location dialog box.

9. Redirect The Report to Look for the Database in The Actual Location: in The THE

Set location

Dialog box, Under

Replace with, Highlight the Actual Location of the Database. Click

Replace. You will Find this location updated Under

Current Data Source. Then Click

CLOSE.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

6

10. If you have modified fields in xtreme.mdb, Right-Click In a Report Area, Point To

Database and SELECT

Verify Database. A Message Titled

Verify Database Suggests

You to proceed to fix up the report. click

Ok to fix Up unmapped fields in the database.

11. Choose

File |

Save Sales by Country.rpt to Save The Report with The Updated Database

Location.

Creating A Web Form

You Will Create a Visual C # Web Application Project, WebFormexample, on The Local Host

Http: // localhost.

IN Visual Studio .NET, SELECT

File |

NEW |

PROJECT. THIS INVOKES THE

New Project Dialog

Box.

2. in the

New Project Dialog Box, SELECT

Visual C # Projects in The Left Pane.

3. SELECT

ASP.NET Web Application in The Right Pane.

You May Choose to Create Your Project On Any Web Server Of Your Choice. For the purpose offs Example, you will create the project in the default project location, http: // localhost,

Which is The Local IIS Web Server.

4. ENTER "WebFormexample" in the

Location FieldAfter http: // localhost /. The Default

Project location, http:// localhost, is displayed in the

Location Field. Click

OK.

This Creates The Web Application Project, WebFormExample, AT

http: // localhost / WebFormExample.

Visual Studio Creates A Web Forms Page (with The default name "Webform1.aspx") in

The Project WebFormExample.

The Window for the Web Forms Page Consists of Two Tabs:

Design and

HTML. The Design

Tab Allows Programming Using The Visual Studio IDE. THE

HTML Tab Contains the HTML

Source That Supports asp.net. Visual Studio Automatic Or Opens the

Design Tab of

Webform1.aspx.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

Seduce

Tip in Visual Studio .NET, You Can Anchor The Toolbox by Clicking The "PIN" icon at

The Top-Right Corner of The Toolbox.

Also, Items in A

Toolbox Tab Can Be Displayed Alphabetically by Right-Clicking The Tab,

And SELECTING

Sort items alphabetically from the shringcut menu.

When you are in the design

Tab, The Toolbox Lists the Web

Form controls.

The Web Forms Tab of To

Toolbox Displays All Web Form

Controls include the Web Forms

Viewer.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

8

Inserting the Web Form Controls

With the Toolbox Set Up Up Properly, You Can Now INSERT Web Form Controls Into Your Web

Form. SELECT THE

Design Tab of Webform1.aspx if it is not already the Active Tab. You willinsert Two Controls, An Image and A Web Forms Viewer:

From the

Web Forms Tab of The Toolbox, Drag T

Image Control and Drop It ITO THE

Web form. The Image Object Has A Default Name

Image1.

2. Similarly, Drag A Web Forms Viewer Control and Drop It Into The Web Form. The Viewer

HAS a Default Name

CrystalReportViewer1.

Web Forms

Viewer Control

Image control

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

9

Binding files to the Web Forms Controls

Next, You Will Specify The Image and report Files That The Web Form Will Display.

Initialize The Image Control with a United Nations Flag Since Initially, No Country Has Been

Linking Up The Web Form Controls for Interactivity, You Will

Further Specify Which flag The Image Control Should Display Under What Conditions.

To Specify An Image File for the Image Control:

IN THE

Design Tab of Webform1.aspx, Select The Image Control. The Properties WINDOW

Automatically Displays The Properties Applicable to the Image Control. You May Click The Image

Alphabetize icon to Arrange Properties in their alphabetical order.

2. Scroll Down to the Property,

Imageurl, in The Properties Window. Specify a URL OR FULL

Path Name for the Image File That You Would Like The Image Control To Display. Specify

The URL

http://localhost/walkthroughfiles/others.jpg. this Initializes the Image

Control to Display the flag for theneited nation.

3. You May Adjust The Length And The Width of The Image Control to Display THE FLAG in The

ApproPriate Scale.

To Specify A Report File for the Web Forms Viewer Control

IN THE

Design Tab of Webform1.aspx, Select The Web Forms Viewer Control. Theproperties WINDOW Automatically Displays The Properties Applicable To IT.

2. SELECT

DataBindings in the Properties Window, And Click The Square Button to the Right

of the entry field. this Opens the

DataBindings Dialog Box.

3. in the

DataBindings Dialog Box, SELECT

Reportsource Under

Bindable Properties,

And Enter the full path name, "c: // inetpub // wwwroot // Walkthroughfiles // Sales BY

Country.rpt "(with the double quotes) Under

Custom Binding Expression. The Web

Forms Viewer Control Automatically Displays this Report At Design Time.

Specify image to display.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

10

4. Highlight Webform1.aspx in The Solution Explorer and Click THE

View Code icon. In

Webform1.aspx.cs, after the call to base.onit (e) in ONINIT, ENTER this line:

DataBind ();

5. You May Adjust The Size of the Web Forms Viewer Control As You See Fit, by first setting

The property,

Bestfitpage, To

False, and then adjusting handles of the viewer in there

Design Tab.

Select the reportsource

Property Under Bindable

Properties.

Specify a full path name

For the report file.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

11

Below Shows a Layout of The Web Form in The Visual Studio Editor, with the Image and Web

Forms viewer controls initialized.

Linking Up The Web Form Controls for Interactivity

As Described in the section "Outline of Web Application" Above, When the User Drills Down On

A Country (OR a Group of Countries for "Others") in Chart A in The Report, The Image Control

SHOULD DISPLAY THE APRIATE FLAG.TO SET UP THE Image Control To Display THE APON EVENT IMAGE UPON A Drill-Down Event in

Web Forms Viewer, You CAN IMPLEMENT The FOLLOWING:

IN THE

Design Tab of Webform1.aspx, Select the Web Forms Viewer Control.

2. In The Properties Window, Click The

Events icon. The Properties Window Automaticly

Displays all the events applicable to the web fors viewer control. if you have not

Already Done So, You May Click The

Alphabetize icon to arrenge events in their

Alphabetical order.

3. Double-Click The

Drill Event. This Activates the Editor for Webform1.cs, And Initializes A

Function named CrystalReportViewer1_drill.

4. Add The Following Lines of Code to CrystalReportViewer1_drill:

String sgroupname = "";

IF (E.NEWGROUplevel == 1)

{

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

12

sgroupname = E.NEWGroupname;

String imageurl = string.format

("http:// localhost // walkthroughfiles // {0} .jpg", sgroupname);

Image1.imageurl = imageURL;

}

Building and Running The Web Application

To build and rain the Web application:

1. from the visual studio .net menu bar, SELECT

File |

Save all to save all changes you

Have Made to The Project WebFormExample. The first time you save the solution file,

You Will Be PROMPTED with a Message About Saving WebFormExample.sln. save it to the

DEFAULT LOCATION C: / INETPUB / WWWROOT / WebFormExample.

2. SELECT

BUILD |

Build to Compile Your Application.

3. SELECT

START WITHOUT Debugging from the

Debug Menu.

4. The Web Application Automatically Starts AT

http://localhost/webformexample/webform1.aspx in your browser.

5. Try Drilling Down on a Country in Chart A of Sales by Country.rpt. For Instance, DrillDown ON USA. The United States. The Report Also

Displays Chart B Showing The Sum of Last Year's Sales for the top 5 Regions in The United

States.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

13

Navigating in The Crystal Report

Sales by country.rpt is grouped by The Four Fields - Country, Region, City and Customer

Name. It Contains a Group Tree and Charts A, B And C. You CAN SELECT A Grouping Via THE

Group Tree. You Can Also Select A Country Grouping Through Chart A.

Drilling Down In The Crystal Report

Initially, To Select a grouping via the group tree, expand the group tree by clicking on the ' '

Symbol to the left of a country node. You can the Click A Region, City, or Customer Name.

The Report Will Then Display The Sum of Last Year's Sales for the success.

You Can Also Select a Country Grouping by Drilling Down on Chart A. Chart a is a group chart

Displaying The Sum of Last Year's Sales for Each of The Top 5 Countries, And The Total of Last

Year's Sales for the rest of the counted. The user may drill down on chart a to

Select One of the top 5 Countries (OR "Others" for All Other Countries, And View In Chart B

The Sum of Last Year's Sales for Each of The Top 5 Regions in That Country (or Group of

Countries in the case of "tahers").

You can expand and

TRAVERSE The Group Tree To

SELECT a grouping.

OR, You CAN SELECT A

Country in chart a by

DRILLING DOWN IT.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page14

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

15

For Instance, To View The Sum of Last Year's Sales for the top 5 Regions in Italy, You Can Drill

Down On "Italy" in Chart A. In this Database, Since There isaly (i.e.,

Lombardia, Piedmonte and lazio) with sales, ONLY THE SUM OF LAST YEAR'S SALES OF EACH OF

THESE 3 Regions Will Be Displayed in Chart B.

Click ON A Region or Expand

The group tree to select a

City or custom.

Chart B Displays the Sum of last

Year's Sales in The Top Regions of

The country selected in chart A.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

16

At this Point, You May Click A Region in The Group Tree, or Further Expand The Group Tree To

SELECT a City or Customer to Display THE CORRESPONDING SALES. For Instance, You Can Click The

Region, Lombardia, In The Group Tree. The Report Will Display in Chart C The below last year ?s

Sales of the Two Cities in Lombardia, Bergamo and Milan.

CLICKING a Region Will Display THE

Sales of Each City in That Region.

Interactivity and Reports in Web Applications

Copyright © 2001 Crystal Decisions, Inc.

Page

In one

You May Further Expand The Group Tree and SELECT a City Or Customer Name to Display To

Corresponding Sales for That City Or Customer. For Example, IF you click the city milan, the

Report Will Show The Sales for Each Customer in Milan; In this database, Since the IS ONLY

One Customer, Milano Bike Store, In Milan, The Report Will Only Show The Sales for That

Customer.

Note That at Any Point, You Can Click THE UP-Arrow Icon In The Web Forms Viewer Toolbar To

TRAVERSE One Level Up in The Group Tree.clicking on a City in the group

Tree Will Show Sales of Each

Customer in That City.

You Can Click The Up-arrow icon

Anytime to Traverse One Level Up

In the group tree.

转载请注明原文地址:https://www.9cbs.com/read-36369.html

New Post(0)