CRYSTAL REPORTS

ANTONIOBSJ 13/02/2012 14:26:03
#394590
Boa tarde, amigos.

Alguém tem um exemplo simples para abrir um relatório do Crystal Reports no ASP Clássico. Só abrir [Ô]sem frescuras[Ô].
TECLA 16/02/2012 20:00:12
#394965
Resposta escolhida
Veja se te ajuda.

<%@Language=VBScript %>

<%

reportname = [Ô]announceReport.rpt[Ô]

[ô]This line creates a string variable called reportname that we will use to pass
[ô]the Crystal Report filename (.rpt file) to the OpenReport method.
[ô]To re-use this code for your application you would change the name of the report
[ô]so as to reference your report file.

[ô]CREATE THE APPLICATION OBJECT
If Not IsObject (session([Ô]oApp[Ô])) Then
Set session([Ô]oApp[Ô]) = Server.CreateObject([Ô]Crystal.CRPE.Application[Ô])
End If

[ô]This [Ô]if/end if[Ô] structure is used to create the Crystal Reports Application
[ô]object only once per session. Creating the application object - session([Ô]oApp[Ô])
[ô]loads the Crystal Reports automation server (cpeaut32.dll) into memory.
[ô]
[ô]We create it as a session variable in order to use it for the duration of the
[ô]ASP session. This is to elimainate the overhead of loading and unloading the
[ô]cpeaut32.dll in and out of memory. Once the application object is created in
[ô]memory for this session, you can run many reports without having to recreate it.

[ô] CREATE THE REPORT OBJECT
[ô]
[ô]The Report object is created by calling the Application object[ô]s OpenReport method.

Path = Request.ServerVariables([Ô]PATH_TRANSLATED[Ô])
While (Right(Path, 1) <> [Ô]\[Ô] And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend

[ô]This [Ô]While/Wend[Ô] loop is used to determine the physical path (eg: C:\) to the
[ô]Crystal Report file by translating the URL virtual path (eg: http://Domain/Dir)

[ô]OPEN THE REPORT (but destroy any previous one first)

If IsObject(session([Ô]oRpt[Ô])) then
Set session([Ô]oRpt[Ô]) = nothing
End if

set Session([Ô]options[Ô]) = Session([Ô]oApp[Ô]).options
Session([Ô]options[Ô]).MatchLogonInfo = 1

Set session([Ô]oRpt[Ô]) = session([Ô]oApp[Ô]).OpenReport(path & reportname, 1)

set crtable1 = session([Ô]oRpt[Ô]).Database.Tables.Item([Ô]hosp_unit_all[Ô])
crtable1.SetLogonInfo [Ô]icom[Ô], [Ô] [Ô], [Ô]hr[Ô], [Ô]hr[Ô]

[ô]This line uses the [Ô]PATH[Ô] and [Ô]reportname[Ô] variables to reference the Crystal
[ô]Report file, and open it up for processing.
[ô]
[ô]Notice that we do not create the report object only once. This is because
[ô]within an ASP session, you may want to process more than one report. The
[ô]rptserver.asp component will only process a report object named session([Ô]oRpt[Ô]).
[ô]Therefor, if you wish to process more than one report in an ASP session, you
[ô]must open that report by creating a new session([Ô]oRpt[Ô]) object.

set session([Ô]oRptOptions[Ô]) = Session([Ô]oRpt[Ô]).Options
session([Ô]oRptOptions[Ô]).MorePrintEngineErrorMessages = 0

[ô]These lines disable the Error reporting mechanism included the built into the
[ô]Crystal Report Print Engine (CRPE32.DLL). This is done for two reasons:
[ô]
[ô]1. The print engine is executed on the Web Server, so any error messages
[ô] will be displayed there. If an error is reported on the web server, the
[ô] print engine will stop processing and you application will [Ô]hang[Ô].
[ô]
[ô]2. This ASP page and rptserver.asp have some error handling logic desinged
[ô] to trap any non-fatal errors (such as failed database connectivity) and
[ô] display them to the client browser.
[ô]
[ô]**IMPORTANT** Even though we disable the extended error messaging of the engine
[ô]fatal errors can cause an error dialog to be displayed on the Web Server machine.
[ô]For this reason we reccomend that you set the [Ô]Allow Service to Interact with Desktop[Ô]
[ô]option on the [Ô]World Wide Web Publishing[Ô] service (IIS service). That way if your ASP
[ô]application freezes you will be able to view the error dialog (if one is displayed).


[ô]====================================================================================
[ô] Retrieve the Records and Create the [Ô]Page on Demand[Ô] Engine Object
[ô]====================================================================================

On Error Resume Next
session([Ô]oRpt[Ô]).ReadRecords
If Err.Number <> 0 Then
Response.Write [Ô]An Error has occured on the server in attempting to access the data source[Ô]
Else

If IsObject(session([Ô]oPageEngine[Ô])) Then
set session([Ô]oPageEngine[Ô]) = nothing
End If
set session([Ô]oPageEngine[Ô]) = session([Ô]oRpt[Ô]).PageEngine
End If
[ô]Response.Write [Ô]An Error has occured on the server in attempting to access the data source[Ô]
[ô] INSTANTIATE THE CRYSTAL REPORTS SMART VIEWER
[ô]
[ô]When using the Crystal Reports automation server in an ASP environment, we use
[ô]the same page on demand [Ô]Smart Viewers[Ô] used with the Crystal Web Report Server.
[ô]The are four Crystal Reports Smart Viewers:
[ô]
[ô]1. ActiveX Smart Viewer
[ô]2. Java Smart Viewer
[ô]3. HTML Frame Smart Viewer
[ô]4. HTML Page Smart Viewer
[ô]
[ô]The Smart Viewer that you use will based on the browser[ô]s display capablities.
[ô]For Example, you would not want to instantiate the Java viewer if the browser
[ô]Line 200
[ô]did not support Java applets. For purposes on this demo, we have chosen to
[ô]define a viewer. You can through code determine the support capabilities of
[ô]the requesting browser. However that functionality is inherent in the Crystal
[ô]Reports automation server and is beyond the scope of this demonstration app.
[ô]
[ô]We have chosen to leverage the server side include functionality of ASP
[ô]for simplicity sake. So you can use the SmartViewer*.asp files to instantiate
[ô]the smart viewer that you wish to send to the browser. Simply replace the line
[ô]below with the Smart Viewer asp file you wish to use.
[ô]
[ô]The choices are SmartViewerActiveX.asp, SmartViewerJave.asp,
[ô]SmartViewerHTMLFrame.asp, and SmartViewerHTMLPAge.asp.
[ô]Note that to use this include you must have the appropriate .asp file in the
[ô]same virtual directory as the main ASP page.
[ô]
[ô]*NOTE* For SmartViewerHTMLFrame and SmartViewerHTMLPage, you must also have
[ô]the files framepage.asp and toolbar.asp in your virtual directory.


[ô]
%>
Tópico encerrado , respostas não são mais permitidas