レポート作成

3273 ワード


レポートの設定:
                    1.レポート・データの新規データセットの作成
                    2.レポートレイアウトの設計
                    3.テーブルのデータソース名の設定(datasetname)
                    4.表の各セルにデータ・ソースのフィールドを追加
レポートを接続し、次のように表示します.
かいめんそう
Imports Bll
Imports Entity

Public Class FrmReport
    Private BReport As New BllReport
       Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

        Dim mytable As New DataTable
        mytable = BReport.InquireReport(DTPStart.Text, DTPEnd.Text).Tables(0)
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", mytable))
        ReportViewer1.RefreshReport()

    End Sub
End Class

ビジネスロジック層
Imports DAL
Imports Entity
Public Class BllReport
    Private EReport As New Report
    Private DReport As New DalReport
    Public Function InquireReport(ByVal datStart As Date, ByVal datEnd As Date) As DataSet
        Dim DSreport As DataSet
        DSreport = DReport.SelectSome(datStart, datEnd)
        Return DSreport
    End Function
End Class

データアクセス層
Imports System.Data.SqlClient
Imports Entity
Public Class DalReport
    Dim connStr As String = "server=.;database=jifang2;uid=sa;Pwd=123"
    Private EReport As New Report
    ''' <summary>
    '''  
    ''' </summary>
    ''' <param name="datStart"></param>
    ''' <param name="datEnd"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function SelectSome(ByVal datStart As Date, ByVal datEnd As Date) As DataSet
        Dim sql As String = "select * from report where date between @datStart and @datEnd"
        Dim conn As New SqlConnection(connStr)
        Dim cmd As New SqlCommand(sql, conn)
        Dim sqlparam1 As New SqlParameter("@datStart", SqlDbType.DateTime)
        sqlparam1.Value = datStart
        cmd.Parameters.Add(sqlparam1)
        Dim sqlparam2 As New SqlParameter("@datEnd", SqlDbType.DateTime)
        sqlparam2.Value = datEnd
        cmd.Parameters.Add(sqlparam2)
        Dim DSreport As New DataSet
        Dim sda As New SqlDataAdapter(cmd)
        Try
            conn.Open()
            sda.Fill(DSreport)
            Return DSreport
        Catch ex As Exception
            Return Nothing
        Finally
            If Not IsNothing(conn) Then
                conn.Close()
                conn = Nothing
            End If
            If Not IsNothing(cmd) Then
                cmd.Dispose()
                cmd = Nothing
            End If
        End Try
    End Function
    End Class