|
| 1 | + |
| 2 | + '============================================================================== |
| 3 | + ' Constants |
| 4 | + '============================================================================== |
| 5 | + ' Location of reports created by the client |
| 6 | + Private Const sswReportOutputURL = "http://localhost/SSWAccessReporter/Reports/" |
| 7 | + |
| 8 | + ' IP or Computer name of the computer that is running SSW Access Report Server. |
| 9 | + Private Const sswDestinationComputer As String = "127.0.0.1" |
| 10 | + |
| 11 | + ' These constants are used in place of the format type enum |
| 12 | + ' (Note: You should include these in all ASP's that use the report client) |
| 13 | + Public Const sswFormatHTML = 0 |
| 14 | + Public Const sswFormatPDF = 1 |
| 15 | + Public Const sswFormatRTF = 2 |
| 16 | + Public Const sswFormatSNP = 3 |
| 17 | + Public Const sswFormatTXT = 4 |
| 18 | + Public Const sswFormatXLS = 5 |
| 19 | + |
| 20 | + '============================================================================== |
| 21 | + ' Page Calls |
| 22 | + '============================================================================== |
| 23 | + Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load |
| 24 | + If Page.IsPostBack Then |
| 25 | + lblMessage.Text = "" |
| 26 | + End If |
| 27 | + End Sub |
| 28 | + Private Sub ReportName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportName.SelectedIndexChanged |
| 29 | + ReportFilter.Visible = False |
| 30 | + ReportFilter2.Visible = False |
| 31 | + |
| 32 | + If ReportName.SelectedItem.Value = "Invoice" Then |
| 33 | + ReportFilter.Visible = True |
| 34 | + ElseIf ReportName.SelectedItem.Value = "Sales By Category" Then |
| 35 | + ReportFilter2.Visible = True |
| 36 | + End If |
| 37 | + End Sub |
| 38 | + Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click |
| 39 | + |
| 40 | + '============================================================================== |
| 41 | + ' Generates the report and redirects the user to the report. If there was an |
| 42 | + ' error while generating, the error message will be displayed on the page. |
| 43 | + '============================================================================== |
| 44 | + Dim strReportFilter As String = "" |
| 45 | + ' Report filter is only used for the Invoice report in this sample (set blank if other report) |
| 46 | + If ReportFilter.Visible Then |
| 47 | + strReportFilter = ReportFilter.SelectedItem.Value.ToString() |
| 48 | + ElseIf ReportFilter2.Visible Then |
| 49 | + strReportFilter = ReportFilter2.SelectedItem.Value.ToString() |
| 50 | + End If |
| 51 | + |
| 52 | + Try |
| 53 | + ' Generate report and get the path of the file |
| 54 | + Dim strFileName As String = GetReport(DatabseName.SelectedItem.Value.ToString, ReportName.SelectedItem.Value.ToString, ReportFormat.SelectedItem.Value.ToString, strReportFilter) |
| 55 | + |
| 56 | + ' Get the file name of the file |
| 57 | + strFileName = GetFileName(strFileName) |
| 58 | + |
| 59 | + ' Redirect to the report (Note: This requires the output URL) |
| 60 | + Call Response.Redirect(sswReportOutputURL & strFileName) |
| 61 | + |
| 62 | + Catch exp As Exception |
| 63 | + lblMessage.Text = "Report creation Failed: " & exp.Message |
| 64 | + End Try |
| 65 | + |
| 66 | + End Sub |
| 67 | + |
| 68 | + '============================================================================== |
| 69 | + ' Private Routines |
| 70 | + '============================================================================== |
| 71 | + Private Function GetReport(ByVal strDatabaseName As String, ByVal strReportName As String, ByVal enmReportFormat As ReportClient.ReportClient.EnumReportFormat, ByVal strReportFilter As String) |
| 72 | + '============================================================================== |
| 73 | + ' Generates a report, and returns the File Name. The file will be placed in the |
| 74 | + ' reports directory as specified in the server options. |
| 75 | + '============================================================================== |
| 76 | + |
| 77 | + Dim strReturn As String = "" |
| 78 | + Dim objReportClient As New ReportClient.ReportClient(sswDestinationComputer) |
| 79 | + Try |
| 80 | + strReturn = objReportClient.GetReport(strDatabaseName, strReportName, strReportFilter, "", enmReportFormat) |
| 81 | + Catch exp As Exception |
| 82 | + Throw New Exception(exp.Message, exp) |
| 83 | + End Try |
| 84 | + |
| 85 | + Return strReturn |
| 86 | + End Function |
| 87 | + Private Function GetFileName(ByVal strPath As String) As String |
| 88 | + '============================================================================== |
| 89 | + ' Gets the name of a file when handed a fully qualified path. eg: |
| 90 | + ' c:\inetpub\wwwroot\reports\Report1.snp => Report1.snp |
| 91 | + '============================================================================== |
| 92 | + Return Mid(strPath, InStrRev(strPath, "\") + 1, Len(strPath) - InStr(strPath, "\")) |
| 93 | + End Function |
0 commit comments