Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/04/2005, 03:39
Avatar de Iri
Iri
 
Fecha de Ingreso: septiembre-2003
Ubicación: Madrid
Mensajes: 54
Antigüedad: 21 años, 7 meses
Puntos: 0
Mensaje Ejemplo de ASP y Crystal

Hola a todos, hace un par de días que recibí un correo de un tal Efren que supuestamente me encontro en este foro, pero perdi su email y no le encuentro como usuario; él me pedía un ejemplo de ASP y Crystal, y puesto que no es el único que me lo ha pedido, he decidido colgarlo aqui; si este no es el sitio indicado pido mil disculpas por adelantado. Bueno, evidentemente los que utilicen este ejemplo tendran que modificar el código a su conveniencia, pero almenos tendrán una referencia de los objetos que utiliza ASP para Crystal:

<%@ Language=VBScript CodePage=65001%>
<%' Option Explicit%>

<%

'Response.Write Request("mdc")
'Response.End

if isEmpty(session("usuario")) or isEmpty(session("delegacion")) then
response.redirect(application("APP_HOMEPATH") & "Validacion.asp?pwd=ok")
else
dim delegacion
delegacion=session("delegacion")
end if
%>

<%
dim oRecord, oClase
set orecord=server.CreateObject("ADODB.Recordset")
set oclase=server.CreateObject("Visados.AccesoBD")
%>
<html>
<TITLE>COIIM - Informes.</TITLE>
<link REL="STYLESHEET" TYPE="TEXT/CSS" HREF="<%=application("APP_HOMEPATH")%>css/ie.css">
<LINK rel="stylesheet" type="text/css" href="<%=application("APP_HOMEPATH")%>css/estilos.css">

<head>
<body>
<form id=form1 name=form1>
<table>
<tr>
<td width=40%>&nbsp;</td>
<td align=center width=30%>
<input type=button class=botonesv name=volver onclick="document.location='informes.asp'" value="Volver a lista de informes" >
</td>
<td width=30%>&nbsp;</td>
</table>
<input type=hidden name=where value="<%=request.Form("where")%>">
<input type=hidden name=delegacion <%if Request.form("delegacion")<>"" then%>value="<%=Request.Form("delegacion")%>"<%els eif Request.form("delegaciones")<>"" then%>value="<%=Request.Form("delegaciones")%>"<%e lseif Request.QueryString("delegacion")<>"" then%>value="<%=Request.QueryString("delegacion")% >"<%elseif Request.QueryString("delegaciones")<>"" then%>value="<%=Request.QueryString("delegaciones" )%>" <%end if%>>
<input type=hidden name=cadena <%if Request.form("cadena")<>"" then%>value="<%=Request.Form("cadena")%>"<%elseif Request.QueryString("cadena")<>"" then%>value="<%=Request.QueryString("cadena")%>" <%end if%>>
<input type=hidden name=mostrar <%if Request.form("mostrar")<>"" then%>value="<%=Request.Form("mostrar")%>"<%elseif Request.QueryString("mostrar")<>"" then%>value="<%=Request.QueryString("mostrar")%>" <%end if%>>
<input type=hidden name=Subtitulo <%if Request.form("Subtitulo")<>"" then%>value="<%=Request.Form("Subtitulo")%>"<%else if Request.QueryString("Subtitulo")<>"" then%>value="<%=Request.QueryString("Subtitulo")%> " <%end if%>>
<input type=hidden name=rpt value="<%=Request.Form("rpt")%>">
</form>
</body>
</head>
</html>

<%
' Note - the CodePage=65001 is needed to display Unicode text correctly in the viewer
' if Session is null for ProcessHttpRequest
dim nomfich, theReportName, ReportName
dim where
nomfich = Request.Form ("rpt")
where=""

if nomfich <>"" then
select case nomfich
case "PROYECTOS_RETIRADOS.rpt"
if Request.Form("fecha_desde")<>"" then
where= where & "{VI_INF_RETIRADOS_POR.FECHA_RETIRADA} IN DATE (" & _
right(request.Form("fecha_desde"),4) & "," & mid(request.Form("fecha_desde"),4,2) & _
"," & left(request.Form("fecha_desde"),2) & ") TO DATE (" & _
right(request.Form("fecha_hasta"),4) & "," & _
mid(request.Form("fecha_hasta"),4,2) & "," & _
left(request.Form("fecha_hasta"), 2) & ") "
end if
end select
end if
'Response.Write( where & "<br>")
'Response.End()
if Request.Form("ReportName")<>"" then
theReportName = application("APP_PATH") & "\informes\" & Request.Form("ReportName")
elseif ReportName<>"" then
theReportName = application("APP_PATH") & "\informes\" & ReportName
end if





Dim objectFactory
Set objectFactory = CreateObject("CrystalReports.ObjectFactory.2")

'Response.ExpiresAbsolute = Now() - 1

if theReportName = "" then theReportName = Request.QueryString("ReportName")
if cadena= "" then cadena = Request.QueryString("cadena")

if mostrar= "" then cadena = Request.QueryString("mostrar")
if Subtitulo= "" then cadena = Request.QueryString("Subtitulo")



Dim viewer
Set viewer = objectFactory.CreateObject("CrystalReports.Crystal ReportInteractiveViewer")
if request.Form("where")<> "" then
where=request.Form("where")
elseif request.QueryString("where")<>"" then
where=request.QueryString("where")
end if




dim fecha_visado
fecha_visado=where
if nomfich="CONTROL_AFLUENCIA.RPT" then
where=""
'fecha_visado=mid(fecha_visado ,instr(1,"=",fecha_visado)+1,11)
end if
'Response.Write(FECHA_visado)
'Response.End

%><script>

document.form1.cadena.value='<%=cadena%>'

document.form1.mostrar.value='<%=mostrar%>'
document.form1.Subtitulo.value='<%=Subtitulo%>'

</script>
<%




Dim clientDoc
Set clientDoc = objectFactory.CreateObject("CrystalClientDoc.Repor tClientDocument")
clientDoc.Open theReportName


Dim strParametro
dim param_name, param_value







'SI TIENE PARAMETROS LE PASO EL VALOR:
param_name = "DELEGACION"



param_value = strParametro

dim paramValue 'discrete parameter value
dim param_old 'parameter field in the report
dim param_new
dim parameterfieldcollection
dim parameterfieldIndex

'Create a discrete parameter field value
set paramValue = objectFactory.CreateObject("CrystalReports.Paramet erFieldDiscreteValue")

'Set parameter field value to the new parameter value
'paramValue.Value = param_value

'Look for the parameter with the correct name (using a loop)
Set parameterfieldcollection = clientDoc.DataDefinition.ParameterFields



'Create a new parameter object
set param_new = objectFactory.CreateObject("CrystalReports.Paramet erField")

For Each parameterfieldIndex in parameterfieldcollection


'response.write(parameterfieldIndex.Name & "<br>")
If parameterfieldIndex.Name = param_name Then

strParametro= "loque sea"

paramvalue.value=strParametro
Set param_old = parameterfieldIndex
'Create a new parameter object
set param_new = objectFactory.CreateObject("CrystalReports.Paramet erField")
'Copy properties of old parameter to new parameter
param_old.CopyTo param_new

'Add discrete value to this new parameter field
param_new.CurrentValues.Add paramValue

'Modify parameter through the DataDefControler and the ParameterFiledController
clientDoc.DataDefController.ParameterFieldControll er.Modify param_old, param_new

'Clean up
set paramValue = nothing
set param_new = nothing
'break out of the loop

Next
viewer.SelectionFormula = where
viewer.Name = "page"
viewer.IsOwnForm = true
viewer.IsOwnPage = true
viewer.isDisplayGroupTree = false

viewer.URI = "interactiveViewer.asp?ReportName=" + Server.URLEncode(theReportName) + "&where=" + server.URLEncode(where) + "&DELEGACION=" + server.URLEncode(delegacion) + "&CADENA1=" + SERVER.URLEncode(CADENA1) + "&CADENA2=" + server.URLEncode(CADENA2) + "&CADENA3=" + server.URLEncode(CADENA3) + "&CADENA4=" + server.URLEncode(CADENA4) + "&CADENA5=" + server.URLEncode(CADENA5) + "&mostrar=" + server.URLEncode(mostrar) + "&Subtitulo=" + server.URLEncode(Subtitulo)
Response.Write where
'Response.End

viewer.ReportSource = clientDoc.ReportSource


Dim BooleanSearchControl
Set BooleanSearchControl = objectFactory.CreateObject("CrystalReports.Boolean SearchControl")
BooleanSearchControl.ReportDocument = clientDoc
viewer.BooleanSearchControl = BooleanSearchControl

'Response.Write viewer.URI
'Response.End

viewer.ProcessHttpRequest Request, Response
' ReportClientDocument will be automatically closed when clientDoc is released
%>
<%
set orecord= nothing
set oclase=nothing
%>
__________________
irina.exe