Inquiridor
Scripts ASP + Crystal Report 9

Pergunta
-
Olá Gente,
Gostaria de saber como trabalhar com ASP e Crystal Report para gerar, visualizar relatórios... Minhas dúvidas são:
a) Quais arquivos e/ou componentes serão necessários instalar no servidor para que eu possa trabalhar com o Crystal?
b) Alguém tem algum exemplo (script) onde através de uma página ASP eu chamo o Crystal?
Já procurei "pra caramba" aqui na net, mas só dão exemplos incompletos, tenho certeza que alguém já passou por esta dificuldade e conseguiu resolver, eu agradeço quem poder ajudar...
Sds,
Augusto
Todas as Respostas
-
Augusto,
Para chamar uma report vc pode usar alguma coisa do tipo:
Function Initialize()
If Not IsObject (session("oApp")) Then
Set session("oApp") = Server.CreateObject("CrystalRuntime.Application.9")
End IfIf IsObject(session("oRpt")) then
Set session("oRpt") = nothing
End if
End FunctionFunction Report(ReportName)
Dim PathRPT
PathRPT = Path & ReportName & ".RPT"
Set session("oRpt") = session("oApp").OpenReport(PathRPT, 1)session("oRpt").MorePrintEngineErrorMessages = False
session("oRpt").EnableParameterPrompting = False
session("oRpt").DiscardSavedDataSet Database = session("oRpt").Database
Set Tables = Database.Tables
Set Table1 = Tables.Item(1)
Table1.SetPrivateData 3, session("oRs")End Function
Vc deve erguer o report nessa página:
<%
'This file contains the HTML code to instantiate the Smart Viewer ActiveX.
'
'You will notice that the Report Name parameter references the rptserver.asp file.
'This is because the report pages are actually created by rptserver.asp.
'Rptserver.asp accesses session("oApp"), session("oRpt") and session("oPageEngine")
'to create the report pages that will be rendered by the ActiveX Smart Viewer.
'
%>
<HTML>
<HEAD>
<TITLE><%=strReportTitle%></TITLE>
</HEAD>
<BODY BGCOLOR=C6C6C6 ONUNLOAD="CallDestroy();" leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0><OBJECT ID="CRViewer"
CLASSID="CLSID:2DEF4530-8CE6-41c9-84B6-A54536C90213"
WIDTH=100% HEIGHT=100%
CODEBASE="/viewer9/activeXViewer/activexviewer.cab#Version=9,2,0,442" VIEWASTEXT>
<param name="EnableRefreshButton" value=<%=EnableRefreshButton%>>
<param name="EnableGroupTree" value=<%=EnableGroupTree%>>
<param name="DisplayGroupTree" value=<%=DisplayGroupTree%>>
<param name="EnablePrintButton" value=<%=EnablePrintButton%>>
<param name="EnableExportButton" value=<%=EnableExportButton%>>
<param name="EnableDrillDown" value=<%=EnableDrillDown%>>
<param name="EnableSearchControl" value=<%=EnableSearchControl%>>
<param name="EnableAnimationControl" value=<%=EnableAnimationControl%>>
<param name="EnableZoomControl" value=<%=EnableZoomControl%>>
</OBJECT><SCRIPT LANGUAGE="VBScript">
<!--
Sub Window_Onload
On Error Resume Next
Dim webBroker
Set webBroker = CreateObject("WebReportBroker9.WebReportBroker")
if ScriptEngineMajorVersion < 2 then
window.alert "IE 3.02 users on NT4 need to get the latest version of VBScript or install IE 4.01 SP1. IE 3.02 users on Win95 need DCOM95 and latest version of VBScript, or install IE 4.01 SP1. These files are available at Microsoft's web site."
else
Dim webSource
Set webSource = CreateObject("WebReportSource9.WebReportSource")
webSource.ReportSource = webBroker
webSource.URL = "rptserver.asp"
webSource.PromptOnRefresh = True
CRViewer.ReportSource = webSource
end if
CRViewer.ViewReport
End Sub
-->
</SCRIPT><script language="javascript">
function CallDestroy()
{
window.open("Cleanup.asp");
}
</script></BODY>
</HTML>E por último, aqui está uma página para limpar as variáveis de sessão. Eu me lembro que se essa página não for executada a estação pode travar... :
<HTML>
<HEAD>
<TITLE>Session Cleanup</Title>
</HEAD>
<BODY Onload="CallClose();">
<%
Session.Contents.Remove("oPageEngine")
Session.Contents.Remove("oRpt")
Session.Contents.Remove("oApp")%>
<SCRIPT LANGUAGE="Javascript">function CallClose()
{
window.close();
}
</SCRIPT>
</BODY>
</HTML>
<%
'The javascript code is used to close the newly opened browser window once the page has run
Response.End
'These last two lines terminate that user's active session and flushes html to the browser.
%>Sinceramente, faz muito tempo que eu não mexo com isso, mas acho que pelo menos é um caminho.
Com relação as DLLs eu não tenho muito a dizer. No site da Crystal vc talvez consiga baixar um pacote para o servidor.
[]'s e Boa sorte!
Diego Bonilha