Okay, I have the code below working in VB, but I want to put it in ASPX so
that I
can call some javascript code from
VBScript.
I want to be execute this code before I open up a new window, but only when
the user presses a button on the screen.
Anyway, I'm having a problem with correctly coding the namespace in ASP, Can
anyone tell me what I'm doing wrong? See ASP code following VB.
Thank you in advance,
Wilson Bell
Imports System.Object
Imports System.Text
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web.Design
Public Class ViewMinRpts
Inherits System.Web.UI.Page
Protected WithEvents btnViewMinFees As System.Web.UI.WebControls.LinkButton
Protected WithEvents btnChurchTithes As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblMsg As System.Web.UI.WebControls.Label
Protected WithEvents imgAcrobat As System.Web.UI.WebControls.ImageButton
Protected WithEvents lblErr As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.De{*filter*}StepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim gRptErr As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lblMsg.Text = "*Please Note: Payments made on-line take 1 to 2 days to be
reflected in reports." & vbCrLf & _
"Also, you must have Acrobat Reader loaded on your computer to view the
reports."
gRptErr = ""
If Not IsPostBack Then
lblErr.Visible = False
Dim strMinRpt, strChurchRpt As String
imgAcrobat.Attributes.Add("OnClick",
"OpenWindow('acrobatwin.aspx')")
strMinRpt = "\temp\tempMin" & Session("UID") & ".pdf"
CreateReport("\Reports\Minister Fees Statement.rpt", strMinRpt,
Session("ConstitID"), "Min")
If gRptErr = "" Then
btnViewMinFees.Enabled = True
btnViewMinFees.Attributes.Add("OnClick",
"OpenWindow('redirectMinisterpdf.aspx')")
Else
btnViewMinFees.Text = "No Minister Fees found."
btnViewMinFees.Enabled = False
gRptErr = ""
End If
End if
End Sub
Private Sub CreateReport(ByVal sReport, ByVal sPDF, ByVal sConstitID, ByVal
sRptType)
' passes report location i.e c:\inetpub\wwwroot\report.rpt
' report custom formula i.e {Table.Field1}>1200
' displays report in browser (temp.pdf)
On Error GoTo Errcode
Dim exportOpts As New ExportOptions()
Dim oRpt As New ReportDocument()
Dim conTest As Boolean
Dim rptpath, pdfpath As String
Dim diskOpts As New DiskFileDestinationOptions()
Dim strFormula As String
rptpath = Server.MapPath(sReport)
pdfpath = Server.MapPath(sPDF)
'load report
oRpt.Load(rptpath)
'log on to SQL server
Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
crLogonInfo = oRpt.Database.Tables(0).LogOnInfo
crLogonInfo.ConnectionInfo.ServerName = "server"
crLogonInfo.ConnectionInfo.DatabaseName = "DB"
crLogonInfo.ConnectionInfo.UserID = "RE7"
crLogonInfo.ConnectionInfo.Password = "re7"
oRpt.Database.Tables(0).SetDataSource("Bl")
oRpt.Database.Tables(0).TestConnectivity()
oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo)
'export report to viewer PDF
exportOpts = oRpt.ExportOptions
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat '
ExportFormatType.WordForWindows, ExportFormatType.Excel other formats
'temp file name
diskOpts.DiskFileName = pdfpath
exportOpts.DestinationOptions = diskOpts
If sRptType = "Min" Then
oRpt.RecordSelectionFormula = oRpt.RecordSelectionFormula + " and
{RECORDS.CONSTITUENT_ID}= '" & sConstitID & "'" 'existing formula + custom
End If
oRpt.Export()
If gRptErr = "" Then
oRpt.Close()
End If
Exit Sub
Errcode:
gRptErr = "Unknown"
lblErr.Text = "CreateReport - " & sRptType & " Error is: " & Err.Number & "
" & Err.Description
lblErr.Visible = True
End Sub
----------------------------------------------------------------------------
-----------------------------------------------
ASPX
Codebehind="MinisterRpt.aspx.vb" Inherits="MinRel.MinisterRpt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MinisterRpt</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET
7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name='vbscript"' content="vs_defaultClientScript">
<meta name="vs_targetSchema"
content=" http://www.*-*-*.com/ ;>
<script language="vbscript" id="clientEventHandlersVBS">
Private Sub ExecRpt
If Not IsPostBack Then
Dim strMinRpt, strChurchRpt As String
strMinRpt = "\temp\tempMin" & Session("UID") &
".pdf"
CreateReport("\Reports\Minister Fees Statement.rpt",
strMinRpt, Session("ConstitID"), "Min")
If gRptErr = "" Then
OpenWindow("redirectMinisterpdf.aspx")
Else
response.write("No Minister Fees found.")
gRptErr = ""
End If
End If
End Sub
Private Sub CreateReport(ByVal sReport, ByVal sPDF, ByVal
sConstitID, ByVal sRptType)
' passes report location i.e c:\inetpub\wwwroot\report.rpt
' report custom formula i.e {Table.Field1}>1200
' displays report in browser (temp.pdf)
On Error GoTo Errcode
Dim exportOpts As New ExportOptions()
Dim oRpt As New ReportDocument()
Dim conTest As Boolean
Dim rptpath, pdfpath As String
Dim diskOpts As New DiskFileDestinationOptions()
Dim strFormula As String
rptpath = Server.MapPath(sReport)
pdfpath = Server.MapPath(sPDF)
'load report
oRpt.Load(rptpath)
'log on to SQL server
Dim crLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
crLogonInfo = oRpt.Database.Tables(0).LogOnInfo
crLogonInfo.ConnectionInfo.ServerName = "Blackbaud70"
crLogonInfo.ConnectionInfo.DatabaseName = "DB_1"
crLogonInfo.ConnectionInfo.UserID = "RE7ODBC"
crLogonInfo.ConnectionInfo.Password = "re7odbc"
oRpt.Database.Tables(0).SetDataSource("Blackbaud70")
oRpt.Database.Tables(0).TestConnectivity()
oRpt.Database.Tables(0).ApplyLogOnInfo(crLogonInfo)
'export report to viewer PDF
exportOpts = oRpt.ExportOptions
exportOpts.ExportDestinationType =
ExportDestinationType.DiskFile
exportOpts.ExportFormatType =
ExportFormatType.PortableDocFormat ' ExportFormatType.WordForWindows,
ExportFormatType.Excel other formats
'temp file name
diskOpts.DiskFileName = pdfpath
exportOpts.DestinationOptions = diskOpts
'If sRptType = "Min" Then
oRpt.RecordSelectionFormula =
oRpt.RecordSelectionFormula + " and {RECORDS.CONSTITUENT_ID}= '" &
sConstitID & "'" 'existing formula + custom
'Else
'Dim ReportFields As FormulaFieldDefinitions =
oRpt.DataDefinition.FormulaFields()
'Dim lFormulaCount As Integer
'For lFormulaCount = 0 To ReportFields.Count - 1
'If ReportFields(lFormulaCount).FormulaName =
'ReportFields(lFormulaCount).Text =
"{GIFT.DTE} in Date (2002, 01, 01) to Date (2002, 12, 31) and " & _
' "{FUND.DESCRIPTION} = 'CHURCH TITHES' and " & _
' "{TABLEENTRIES.LONGDESCRIPTION} = 'Open' and " & _
' "{AttributeTypesCH.DESCRIPTION} = 'Church' and " & _
' "{GIFT.TYPE} = 1.00 and " & _
'' "{AttributeTypesRG.DESCRIPTION} = 'Region' and " & _
' "{AttributeTypes.DESCRIPTION} = 'Status' and " & _
' "{RECORDS.CONSTITUENT_ID} = '" & sConstitID & "'"
'oRpt.RecordSelectionFormula =
ReportFields(lFormulaCount).Text 'oRpt.RecordSelectionFormula
'End If
'Next
'End If
oRpt.Export()
If gRptErr = "" Then
oRpt.Close()
End If
Exit Sub
Errcode:
gRptErr = "Unknown"
lblErr.Text = "CreateReport - " & sRptType & " Error is: " &
Err.Number & " " & Err.Description
lblErr.Visible = True
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="btnMinisterReport" style="Z-INDEX: 101;
LEFT: 135px; POSITION: absolute; TOP: 144px" runat="server"
OnClick="ExecRpt" Text="Minister Report" Width="316px"
Height="40px"></asp:Button>
...
read more »