'公共报表参数
Public objArRpt As New Object
Public sysArCnnString As String
Public sysArSqls As String
‘窗体ReportView,上面放一个Viewer1,加载窗体时根据公共报表参数装载报表
Private Sub ReportView_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As New System.Data.SqlClient.SqlConnection(sysArCnnString)
Dim cmd As New System.Data.SqlClient.SqlCommand(sysArSqls)
Dim rd As System.Data.SqlClient.SqlDataReader
cmd.Connection=cn
cn.Open()
rd=cmd.ExecuteReader()
objARrpt.DataSource=rd
Viewer1.LoadDocument(objARrpt)
Viewer1.Width=Me.Width -(Viewer1.Top*2)
Viewer1.Height=Me.Height-(Viewer1.Left*2)
End Sub
‘增加一个Activereport 9区域报表(基于代码)
"SaDepartment"
‘功能窗体上有打印按钮,打印时赋值公共参数,打开窗体ReportVi ew
Private Sub btnPrint_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
On Error Resume Next
Dim frmPrint As New ReportView
objARrpt =New SaDepartment
sysArCnnString="Data Source=" & DBSrv & ";Initial Catalog=" & DBPer & ";Integrated Security=False;User ID=" & DBUser & "assword=" & DBPwd & ";"
sysArSqls="Select dt.DeptNo,dt.DeptName,dt.Persons,IsNull(empl.ServicePersons,0) As ServicePerson " _
& "From Department As dt Left Join (Select DeptNo,Count(SerialNumber) As ServicePersons From Employee Group By DeptNo) As empl On dt.DeptNo=empl.DeptNo " _
& "Order By dt.DeptNo"
frmPrint.MdiParent=Main
frmPrint.StartPosition=FormStartPosition.CenterParent
frmPrint.WindowState=FormWindowState.Maximized
frmPrint.Show()
End Sub |