Public Sub CreateReport(ByVal sReport As String, ByVal arParams As Array, Optional ByVal DoParams As Boolean = True)
Dim oRpt As New ReportDocument
Dim oSubRpt As New ReportDocument
Dim Counter As Integer
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crLogOnInfo As TableLogOnInfo
Dim crConnInfo As New ConnectionInfo
Dim crParameterValues As ParameterValues
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterRangeValue As ParameterRangeValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterFieldDefinition2 As ParameterFieldDefinition
Dim strFile As String = ""
Dim fi As FileInfo
Dim tstr As String
Dim sPath As String = ""
Dim sReportPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH") & _
"\Report\" & sReport
Dim pos As Integer
Try
tstr = Microsoft.VisualBasic.Format(Now, "MM/dd/yyyy HH:mm:ss")
oRpt.Load(sReportPath)
crDatabase = oRpt.Database
crTables = crDatabase.Tables
For Each crTable In crTables
With crConnInfo
.ServerName = "Contract"
.DatabaseName = "ContractMS"
.UserID = "CMS"
.Password = "CMS"
End With
crLogOnInfo = crTable.LogOnInfo
crLogOnInfo.ConnectionInfo = crConnInfo
crTable.ApplyLogOnInfo(crLogOnInfo)
Next
crSections = oRpt.ReportDefinition.Sections
If DoParams Then
crParameterFieldDefinitions = oRpt.DataDefinition.ParameterFields()
For Counter = 0 To UBound(arParams)
crParameterFieldDefinition = crParameterFieldDefinitions.Item(Counter)
crParameterValues = crParameterFieldDefinition.CurrentValues
If Not IsArray(arParams(Counter)) Then
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = arParams(Counter)
crParameterValues.Add(crParameterDiscreteValue)
Else
crParameterRangeValue = New ParameterRangeValue
crParameterRangeValue.StartValue = arParams(Counter)(0)
crParameterRangeValue.EndValue = arParams(Counter)(1)
crParameterValues.Add(crParameterRangeValue)
End If
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Next
End If
Dim s As System.IO.MemoryStream = oRpt.ExportToStream(ExportFormatType.PortableDocFormat)
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=Report.pdf")
.BinaryWrite(s.ToArray)
.End()
End With
Catch ex As System.Exception
'LogError("cryPrinter.CreateReport", ex.ToString)
Finally
Erase arParams
End Try
End Sub
คือต้องการให้อธิบายใน Codeในส่วนนี้หน่อยค่ะ
Code (VB.NET)
Dim sReportPath As String = HttpContext.Current.Request.ServerVariables("APPL_PHYSICAL_PATH") & _
"\Report\" & sReport
และ Code (VB.NET)
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=Report.pdf")
.BinaryWrite(s.ToArray)
.End()
End With