View
215
Download
0
Category
Preview:
Citation preview
8/8/2019 BAADD Crystal
1/43
(c)2004 Outformations, Inc. 1
Don Robins
Outformations, Inc.
The 1st in a Series of Presentations on
Reporting with .NET
Reporting in ASP.NETCrystal Reports 9.x
Challenges and Solutions
8/8/2019 BAADD Crystal
2/43
(c)2004 Outformations, Inc. 2
Agenda
Introductory Info (10)
Reporting Requirements (15)
Reporting Challenges (15)
Reporting Solutions (25)
BREAK (15)
Architecture & Code Review (40)
Traps To Avoid (5)
Summary (5)
Q/A (15)
8/8/2019 BAADD Crystal
3/43
(c)2004 Outformations, Inc. 3
Introduction.Personal
Don Robins - dbr@outformations.com since 1985
custom business applications and solutions for desktopand (more recently) the web.
BAADD member since 1988, current VP and ADD.NET
SIG leader
Outformations, Inc. www.outformations.com
Collaborative design & software development practice
Use Case based analysis and design Rational Unified Process (RUP) Project Management
Collaboration tools and Project Workbook repositories
We develop in Microsoft, Java, Open Source technologies
8/8/2019 BAADD Crystal
4/43
(c)2004 Outformations, Inc. 4
Introduction.Personal
Roles systems analyst, lead developer, lead technical architect,
application framework integration, database designer,project management
Tech Skills ASP.NET, HTML/Javascript, VB.NET/C#, ADO.NET,ColdFusion, Lotus Notes, SQL7/2000, Access97/200x,Office, FoxPro 2.x-VFP, Crystal Reports, OLE Automation
Industries biotech, aeronautics, transportation, manufacturing,
human resources, import/export, medical,pharmaceutical, legal, broadcasting, entertainment, laborrelations, land trusts, retail, real estate, financial,publishing, technology and education
8/8/2019 BAADD Crystal
5/43
(c)2004 Outformations, Inc. 5
Introduction.Personal
Reporting with xBase, FoxPro 2.x through VFP6 Early report frameworks and templates
Early ad-hoc reporting engines
Early FoxFire! prototyping, development and beta tester
Reporting with Access 2.0, 95, 97-200x
Desktop applications and ODBC reporting
Reporting with Dynamic HTML based reporting
ColdFusion and ASP Classic dynamically generated HTML
Reporting with Lotus Notes
Notes View based reporting
8/8/2019 BAADD Crystal
6/43
(c)2004 Outformations, Inc. 6
Introduction.Personal.Intent
Share challenges faced Identify some complex reporting requirements
Identify where leverage is needed with Crystal
Share successes reached
Share ideas of how to implement solutions
Identify some best practices to leverage Crystal
Share my FMR development philosophy
Functionality Maintainability
Robustness
8/8/2019 BAADD Crystal
7/43
(c)2004 Outformations, Inc. 7
Introduction.Personal.Disclaimer
We will spend time to set high level contextbefore examining code and architecture.
My choices were made by trial and error.
My solutions may not work for you in yoursituation(s).
Most issues apply regardless of platform, but nofeasibility has been performed other than in .NET
An interactive discussion of alternatives iswelcomed during Q/A after presentation or inemail.
8/8/2019 BAADD Crystal
8/43
(c)2004 Outformations, Inc. 8
Reporting.Requirements.Overview
Application ASP.NET Database - SQLServer 2K
150+ Pages/Forms 75+ Tables in 2 DBs
150+ .NET User Controls 1000+ Fields
50+ Business Objects 500+ Stored Procedures
250+ Users in 50+ Offices 60+ SQL UDFs
Application Statistics:
Application Servers Database Servers3 Development Servers 3 Development Servers
1 Staging Server 1 Staging Server
1 Production Server 1 Production DB Server
Deployment Statistics:
8/8/2019 BAADD Crystal
9/43
(c)2004 Outformations, Inc. 9
Reporting.Requirements.Overview
3 Primary Reports: (see samples)
Relatively simple narrative document Term Sheet - 2 to 5 pages
Fairly consistent layout
Simple narrative + data
Extremely complex narrative document Fact Sheet 10 to 60 pages
Multiple sections and inconsistent layout and data
Complex narrative + data
Simple one page form style report Faxlet - 1 page
Fairly consistent form layout
Simple narrative + data
8/8/2019 BAADD Crystal
10/43
(c)2004 Outformations, Inc. 10
Reporting.Requirements.Functional
1. Always launched by the user from within thecontext ofone parent entity.
2. Document style report generated as PDF orWord DOC.
3. No Crystal viewer, no drill-down.
4. Must be generated, downloaded and opened
in the associated application on the desktopwith one mouse click.
8/8/2019 BAADD Crystal
11/43
(c)2004 Outformations, Inc. 11
Reporting.Requirements.Functional
5. Must allow user to save download as a localfile.
6. Report must reflect current state of the data,no automated batching.
7. Reports need to be launched in thebackground during workflow processes,captured and stored in the database for
retrieval on demand by users.
8. Reports must integrate with the complexapplication role based, data level security.
8/8/2019 BAADD Crystal
12/43
(c)2004 Outformations, Inc. 12
Reporting.Requirements.Non-Functional
1. Application MUST use Crystal Reports In house developer and user knowledge of Crystal
Already own licenses (next session)
They understand it is integrated with .NET
2. Output MUST emulate existing reports Database and application will support all data required
No major changes in report look and feel (at inception)
Must be highly maintainable and extendable
Re-factoring is expected after rollout
8/8/2019 BAADD Crystal
13/43
(c)2004 Outformations, Inc. 13
Reporting.Challenges
1. Must use the most flexible ASP.NET projectintegration and IDE choice.
2. Must integrate with the applications dynamicdata connectivity.
3. Must use the most maintainable, reusable androbust data retrieval method.
4. Must support flexible and dynamic parameterpassing to reports and sub-reports.
8/8/2019 BAADD Crystal
14/43
(c)2004 Outformations, Inc. 14
Reporting.Challenges
5. Must build large, diverse and complex reportswith varying data layouts and deliver with onemouse click.
6. Must output to a variety of user selectable fileformats.
7. Must allow for automatic storage and userretrieval from a row in a table.
8. Must secure the data from unauthorized usersby integrating with complex, role based,metadata driven application security.
8/8/2019 BAADD Crystal
15/43
(c)2004 Outformations, Inc. 15
Reporting.Solutions
THE CHALLENGESARE NOW CLEAR.
WHAT ARE YOUR OPTIONS?
8/8/2019 BAADD Crystal
16/43
(c)2004 Outformations, Inc. 16
Reporting.Option(0)
OPTION #1
8/8/2019 BAADD Crystal
17/43
(c)2004 Outformations, Inc. 17
Reporting.Option(1)
OPTION #2
Figure it out
Divide & Conquer
Leverage
Re-factor
8/8/2019 BAADD Crystal
18/43
(c)2004 Outformations, Inc. 18
Reporting.Solution(0)
ASP.NET Integration and IDE
Visual Studio vs. Crystal 9 Studio
VS .NET V1.0 integrated with Crystal v.8.5
Crippled functionality from within Visual Studio
Buy a developer license for Crystal 9
Embed RPT files in Project and bind to DLL?
Pros and cons of embedding
Extended reporting hooks in code behind BUT Modification requires recompilation
Drop RPT files into specified folder
Dont bind! No recompilation required
8/8/2019 BAADD Crystal
19/43
(c)2004 Outformations, Inc. 19
Reporting.Solution(1)
Dynamic Data Connectivity
Use connections in studio at design time
Maintain multiple connections in IDE
Connect as needed at design time
Save data and refresh connections at will.
Reset report object connections at runtime
Create library of generic reporting services
Pass report object and connection data Connection method iterates all master and sub-
reports resetting connections prior to generation
8/8/2019 BAADD Crystal
20/43
(c)2004 Outformations, Inc. 20
Reporting.Solution(1)
Dynamic Data Connectivity Exampleusing CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
//Set Connection Info
MyConn.UserID = GetNamedItem(MyLoc.Location, "User ID", "=", ";");
MyConn.Password = GetNamedItem(MyLoc.Location, "Password", "=", ";");
MyConn.ServerName = GetNamedItem(MyLoc.Location, "Data Source", "=", ";");
MyConn.DatabaseName = GetNamedItem(MyLoc.Location, "Initial Catalog", "=", ";");
TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
//Loop through each table and apply connection info...
foreach(CrystalDecisions.CrystalReports.Engine.Table t in pReport.Database.Tables){
crTableLogonInfo.ConnectionInfo = MyConn;
t.ApplyLogOnInfo(crTableLogonInfo);
crTableLogonInfo.TableName = t.Name;
crTableLogonInfos.Add(crTableLogonInfo);
}
8/8/2019 BAADD Crystal
21/43
(c)2004 Outformations, Inc. 21
Reporting.Solution(2)
Maintainable Robust Data Retrieval
Use stored procedures and SQL functions
Avoid embedding SQL in report objects
Create and test all required row-sets using SQLAnalyzer or equivalent tools
Allows complex and flexible data retrieval withsimple wiring to reports
Allows decoupling of report design from dataprogramming
Allows reusability of SQL objects for like reports andsub-reports
Use intelligent naming conventions
8/8/2019 BAADD Crystal
22/43
(c)2004 Outformations, Inc. 22
Reporting.Solution(2)
Stored Procedure Data Source Example
Open rptTermSheetMaster.rpt
Show how fields are bound to columns
Open usp_rptTermSheetMaster
Review complex construction of rowset
Note the naming convention
Provides intuitive mapping from report to datasource and vice versa
8/8/2019 BAADD Crystal
23/43
(c)2004 Outformations, Inc. 23
Reporting.Solution(3)
Dynamic Parameter Passing
Pass parameters at runtime
Set at design time, easy to test
Parameters can be chained into sub-reports
Determined at runtime based on context
User entry dialogs can gather and forward
Passed to generic reporting service methods
8/8/2019 BAADD Crystal
24/43
(c)2004 Outformations, Inc. 24
Reporting.Solution(3)
Dynamic Parameter Passing Example
SetParm(
ref CrystalDecisions.CrystalReports.Engine.ReportDocument pReport,
string pParmName,
string pParmValue)
ParameterValues MyValues = new ParameterValues();
ParameterDiscreteValue MyValue = new ParameterDiscreteValue();
MyValues=pReport.DataDefinition.ParameterFields[pParmName].CurrentValues;
MyValue.Value = pParmValue;
MyValues.Add(MyValue);
pReport.DataDefinition.ParameterFields[pParmName].ApplyCurrentValues(MyValues);
8/8/2019 BAADD Crystal
25/43
(c)2004 Outformations, Inc. 25
Reporting.Solution(4)
Large, Diverse, Complex Reports
Chunk reports to largest practical objects
Only one level of nesting for sub-reports
Report output as PDF can be merged (stitched)
Use third party server components wrapped inservices
Launch report sections separately or chained,allowing for diverse and hierarchical report sections
Allows unlimited size and complexity
May not work with Crystal viewers unless separatereports
8/8/2019 BAADD Crystal
26/43
(c)2004 Outformations, Inc. 26
Reporting.Solution(4)
PDFM
erge Examples w/ 3
rd
Party Component
Imports TallComponents.PDF
Imports TallComponents.PDF.Append
_AppendAll(ByVal pages As Pages, ByVal path As String)
'Bind the file specified in 'path' to the target document in 'pages'...Dim fileStream As New FileStream(path, FileMode.Open, FileAccess.Read)
Dim reader As New BinaryReader(fileStream)
Dim buffer As Byte() = reader.ReadBytes(CInt(reader.BaseStream.Length))
reader.Close()
reader = New BinaryReader(New MemoryStream(buffer, False))
Dim [source] As New Document(reader)
Dim i As Integer
For i = 0 To [source].Pages.Count - 1
pages.Append([source].Pages(i))
Next i
8/8/2019 BAADD Crystal
27/43
(c)2004 Outformations, Inc. 27
Reporting.Solution(5)
Output Variety Of Formats
Crystal Output Types:
Adobe PDF
Word DOC
Rich Text File RTF
Excel XLS
Maximum Control For User Review:
Conditionally set the output type prior to generation
Dynamically adjust HTML meta header on redirect
User is prompted with options to save or open
Opens with appropriate application on desktop
8/8/2019 BAADD Crystal
28/43
(c)2004 Outformations, Inc. 28
Reporting.Solution(5)
Output As PDF Example
ExportToPDF(ReportDocument oRD, string TargetFileName)
//Set up output configuration
DiskFileDestinationOptions _Options = new DiskFileDestinationOptions();
_Options.DiskFileName = TargetFileName;
//Set the configuration onto the report object...
oRD.ExportOptions.ExportDestinationType =CrystalDecisions.Shared.ExportDestinationType.DiskFile;
oRD.ExportOptions.ExportFormatType =CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
oRD.ExportOptions.DestinationOptions = _Options;oRD.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile;
//Build to PDF in output folder for user as specified in the output filename...
oRD.Export();
8/8/2019 BAADD Crystal
29/43
(c)2004 Outformations, Inc. 29
Reporting.Solution(5)
Redirection Example
RedirectPDFToBrowserStream(Page oPage, string OutputFileName, stringOutputPDFName)
//Send the file to the user that made the request
oPage.Response.Clear();
oPage.Response.Buffer = true;
oPage.Response.AddHeader("Content-Type","application/pdf");
//Default the name that it would be saved with...
oPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + OutputPDFName + ";");
//Set up the stream for the output file...
FileStream Fs = new FileStream(OutputFileName,FileMode.Open);
long FileSize = Fs.Length;
byte[] bBuffer = new Byte[FileSize];Fs.Read(bBuffer,0,Convert.ToInt32(FileSize));
Fs.Close();
//Stream the file back...
oPage.Response.BinaryWrite(bBuffer);
oPage.Response.Flush();
oPage.Response.Close();
8/8/2019 BAADD Crystal
30/43
(c)2004 Outformations, Inc. 30
Reporting.Solution(6)
Storage And Retrieval From Table
Convert binary output file to byte array
Can be contained in SQL Server IMAGE data type
Passed into and out of stored procedures
Create a table with report row keyed to parent
Allows content to be stored within a database
No need to manage files on the server
Scales across server farms
Piggybacks on DB backup and maintenance Increases size of database
8/8/2019 BAADD Crystal
31/43
(c)2004 Outformations, Inc. 31
Reporting.Solution(6)
Binary File Storage Example
CREATE PROCEDURE usp_ProjectReportInsert
--Purpose: Inserts a Project Report.
(@user_id int= null
,@proj_id int= null
,@prrp_vch_type_alias varchar(50) = null
,@prrp_img_file image = null
)
8/8/2019 BAADD Crystal
32/43
(c)2004 Outformations, Inc. 32
Reporting.Solution(7)
Integrate With System Security
Stored procedures retrieval leverages security
Build joins as needed to support permission logic
All complex logic maintained outside of reportobjects
If spoofed, report can launch but no data shows
Report can contain business logic driven by metadata passed in row-sets adjacent to content
8/8/2019 BAADD Crystal
33/43
(c)2004 Outformations, Inc. 33
Reporting.Solution(7)
Integrate With System Security Example
SELECT ...
FROM ...
WHERE ...
AND
--Project Phase security REQUIRES that the
--logged user_id be linked to the project in the
-- tblproj_user_role_link table, derived by UDF()...
dbo.usf_proj_IsPermitted(@user_id, @proj_id, '') = 1
8/8/2019 BAADD Crystal
34/43
8/8/2019 BAADD Crystal
35/43
(c)2004 Outformations, Inc. 35
Reporting.Demonstration
Demo the Reports:
1) Launch from Project summary page
2) Retrieve archived report3) Review call sequence from top down
8/8/2019 BAADD Crystal
36/43
(c)2004 Outformations, Inc. 36
Reporting.Services.HighLevel
Call From High Level UI Code Behind
Minimize logic in UI layer
Instantiate wrapper classProtected _report As New PTS_Report()
Initialize report and call alternate launch methods_report.InitReport()_report.Show()_report.BuildComposite()
_report.ShowComposite()
(Show code module ctlReportPanel.ascx.vb)
8/8/2019 BAADD Crystal
37/43
(c)2004 Outformations, Inc. 37
Reporting.Services.MidLevel
Build a Mid Level Services Class
Contains reporting application specific services:
SetupReport()
ConfigureReport()
SetReportParms()
GenerateReport()
DisplayReport()
DisplayReportFromArray ()
StoreReport() AppendAll(uses third party stitching component)
(Show module PTS_Report.vb) * Note: VB.NET
8/8/2019 BAADD Crystal
38/43
(c)2004 Outformations, Inc. 38
Reporting.Services.LowLevel
Build a Low Level Services Class
Contains generic reporting related services:
SetConnection()
GetUserFolder()
SetParm()
ExportToPDF ()
ExportToDOC ()
RedirectPDFToBrowserStream ()
RedirectDOCToBrowserStream()
(Show module ReportServices.cs) * Note: C#
8/8/2019 BAADD Crystal
39/43
(c)2004 Outformations, Inc. 39
Reporting.Services.Utility
Build Additional Calls Into a Utility Class
Manage auto launch and store services:
PTS_System.BuildFactSheet()
PTS_ System.BuildTermSheet()
PTS_ System.BuildFaxlet()
Pass in arguments from calling methods:
Entity keys
Template names File paths
(Show code module PTS_System.vb)
8/8/2019 BAADD Crystal
40/43
(c)2004 Outformations, Inc. 40
Reporting.Traps
1. Allow completion of compile following a project buildprior to calling any report.
2. Use temp output files with embedded session id forinsuring distinct temp files to avoid user collisions.
3. Utilize user folders for automated management,cleanup and auditing output errors.
4. Set and double check project references for desiredversion of Crystal DLLs as multiple versions may exist
on the server or development workstation.
5. Minimize complexity within the report objects formaximum flexibility and robustness.
8/8/2019 BAADD Crystal
41/43
(c)2004 Outformations, Inc. 41
Reporting.Summary
1. These solutions are not trivial
but they do work.
2. The application and reporting modules have been inproduction since June 2003, and continue to beperiodically extended and re-factored.
3. These techniques should work across developmentlanguages and databases.
4. Crystal just works and rises to the challenges IF youmanage the landmines to leverage an enormous
amount of functionality and flexibility.
5. The key to success is making development choices thatprovide FMR Functionality, Maintainability andRobustness.
8/8/2019 BAADD Crystal
42/43
(c)2004 Outformations, Inc. 42
Reporting.Resources
1. Bay Area Crystal Decisions User Group(BACDUG) holds meetings three to four timesper year in the San Francisco Bay area. Themeetings are open to all users of Crystal
Decision's products
www.sfarea.org
2. Crystal Decisions Developer Zone
www.businessobjects.com/products/dev_zone
8/8/2019 BAADD Crystal
43/43
(c)2004 Outformations Inc 43
Reporting.Questions
Q & A
Don Robins
Outformations, Inc.
dbr@outformations.com
Recommended