Sub print_report(ByVal qt_no As string)
Dim doc As String = "test"
Dim sql As String = "select entry_date from qt_policy where qt_no ='" & st_no & "'"
Dim var(1) As String, l(1) As String
var(0) = "@qt_no" : l(0) = "QNº: " & st_no
Exportport(sql, doc, var, l, CrystalReportViewer1)
End Sub
Public Sub Exportport(ByVal sql As String, ByVal DOC_name As String, ByVal PV() As String, ByVal P_VAL() As String, ByVal crs As CrystalDecisions.Web.CrystalReportViewer)
Dim sqlConn As New SqlConnection(".............")
Dim b As New SqlDataAdapter(sql, sqlConn)
Dim dst As New DataSet
b.Fill(dst, "table")
Dim rpt As New ReportDocument()
rpt.Load(Server.MapPath("~/Reports/" & DOC_name & ".rpt"))
rpt.SetDataSource(dst.Tables(0))
If PV IsNot Nothing Or P_VAL IsNot Nothing Then
Dim PAR(UBound(PV)) As ParameterDiscreteValue
Dim PAR_F As ParameterFieldDefinitions
Dim VAL(UBound(PV)) As ParameterValues
Dim cr(UBound(PV)) As ParameterFieldDefinition
PAR_F = rpt.DataDefinition.ParameterFields
For i As Integer = 0 To UBound(PV)
cr(i) = PAR_F.Item(PV(i))
VAL(i) = cr(i).CurrentValues
PAR(i) = New ParameterDiscreteValue
PAR(i).Value = P_VAL(i)
VAL(i).Add(PAR(i))
cr(i).ApplyCurrentValues(VAL(i))
rpt.SetParameterValue(PV(i), P_VAL(i))
Next
End If
Try
With crs
.DisplayToolbar = True
.HasExportButton = False
.HasRefreshButton = False
.HasToggleParameterPanelButton = False
.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX
.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None
.ReportSource = rpt
.DataBind()
End With
Catch ex As Exception
Console.WriteLine(ex.Message)
ex = Nothing
Finally
sqlConn.Close()
dst.Dispose()
sqlConn = Nothing
dst = Nothing
End Try
End Sub
Public Sub Exportport(ByVal sql As String, ByVal DOC_name As String _
, ByVal PV() As String, ByVal P_VAL() As String _
, ByVal crs As CrystalDecisions.Web.CrystalReportViewer)
Dim sqlConn As New SqlConnection(".............")
Dim b As New SqlDataAdapter(sql, sqlConn)
Dim dst As New DataSet
b.Fill(dst, "table")
Dim rpt As New ReportDocument()
rpt.Load(Server.MapPath("~/Reports/" & DOC_name & ".rpt"))
rpt.SetDataSource(dst.Tables(0))
If PV IsNot Nothing Or P_VAL IsNot Nothing Then
Dim PAR(UBound(PV)) As ParameterDiscreteValue
Dim PAR_F As ParameterFieldDefinitions
Dim VAL(UBound(PV)) As ParameterValues
Dim cr(UBound(PV)) As ParameterFieldDefinition
PAR_F = rpt.DataDefinition.ParameterFields
For i As Integer = 0 To UBound(PV)
cr(i) = PAR_F.Item(PV(i))
VAL(i) = cr(i).CurrentValues
PAR(i) = New ParameterDiscreteValue
PAR(i).Value = P_VAL(i)
VAL(i).Add(PAR(i))
cr(i).ApplyCurrentValues(VAL(i))
rpt.SetParameterValue(PV(i), P_VAL(i))
Next
End If
Try
With crs
.DisplayToolbar = True
.HasExportButton = False
.HasRefreshButton = False
.HasToggleParameterPanelButton = False
.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX
.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None
.ReportSource = rpt
.DataBind()
End With
Catch ex As Exception
Console.WriteLine(ex.Message)
ex = Nothing
Finally
sqlConn.Close()
dst.Dispose()
sqlConn = Nothing
dst = Nothing
End Try
End Sub
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Public Class frmPreview
Dim Report As New CrystalReport1
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load
With Report
Dim cryRpt As New ReportDocument
cryRpt.Load("E:\ABCProj\ABCProj\ABCProj\Preview.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
crParameterValues.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
Dim CrystalReportViewer1 As New CrystalDecisions.Windows.Forms.CrystalReportViewer
Dim strFormula As [String], ReptName As [String]
Dim cryRpt As New ReportDocument()
Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim pfields As New ParameterFields()
Dim CrTables As Tables
Dim dt As DataTable
Dim prForWho, prCusAddr, prEmpName, strConnString, strSQL, cmdQuotRept As String
Private Sub FrmQuotation_ViewReport_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If UserSelectValue <> Nothing Then
If ds.Tables.Contains("BasicInfoReport") Then ds.Tables.Remove("BasicInfoReport")
Dim daBasicInfoReport As New SqlDataAdapter("Select QuotID,IncVat,CusID From Quotation Where QuotID = '" & UserSelectValue & "'", cn)
daBasicInfoReport.Fill(ds, "BasicInfoReport")
ShowReport()
End If
End Sub
Private Sub FillParamReport()
prForWho = "สำหรับลูกค้า"
'------------- Customer Address
If ds.Tables.Contains("CustInfo") Then ds.Tables.Remove("CustInfo")
Dim daCustInfo As New SqlDataAdapter("Select * From Customer where CusID='" & ds.Tables("BasicInfoReport").Rows(0).Item("CusID") & "'", cn)
daCustInfo.Fill(ds, "CustInfo")
If ds.Tables("CustInfo").Rows.Count > 0 Then
prCusAddr = Nothing
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_No")) = False Then
prCusAddr &= ds.Tables("CustInfo").Rows(0).Item("CusAdd_No")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Village")) = False Then
prCusAddr &= " หมู่บ้าน" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Village")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Lane")) = False Then
prCusAddr &= " ซอย" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Lane")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Moo")) = False Then
prCusAddr &= " หมู่" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Moo")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Street")) = False Then
prCusAddr &= " ถนน" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Street")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Tumbon")) = False Then
prCusAddr &= " แขวง" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Tumbon")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Amphur")) = False Then
prCusAddr &= " เขต" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Amphur")
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_Province")) = False Then
If ds.Tables.Contains("CusProvince") Then ds.Tables.Remove("CusProvince")
Dim daCusProvince As New SqlDataAdapter("Select * From Provinces where ProvinceID =" & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Province") & "", cn)
daCusProvince.Fill(ds, "CusProvince")
If ds.Tables("CusProvince").Rows.Count > 0 Then
prCusAddr &= Chr(13) & "จังหวัด" & ds.Tables("CusProvince").Rows(0).Item("ProvinceName")
End If
End If
If IsDBNull(ds.Tables("CustInfo").Rows(0).Item("CusAdd_PostCode")) = False Then
prCusAddr &= " " & ds.Tables("CustInfo").Rows(0).Item("CusAdd_Postcode")
End If
Else
prCusAddr = "-"
End If
If ds.Tables.Contains("InfoEmp") = True Then
If ds.Tables("InfoEmp").Rows.Count > 0 Then
prEmpName = ds.Tables("InfoEmp").Rows(0).Item("EmpName")
End If
End If
If ds.Tables.Contains("MyDataTable_Quotation") Then ds.Tables.Remove("MyDataTable_Quotation")
Dim daMyDataTable_Quotation As New SqlDataAdapter(cmdQuotRept, cn)
daMyDataTable_Quotation.Fill(ds, "MyDataTable_Quotation")
For Each CrTable As CrystalDecisions.CrystalReports.Engine.Table In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "พบข้อผิดพลาดขณะดึงข้อมูล กรุณาติดต่อผู้ดูแลระบบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Dispose()
End Try