导读:进行完了日结报表的制作,大松一口气。不过,刚开始看着周结账单中的两个参数问题,也是愁了很久。不过,只要思想不滑坡,办法总比困难多。接下来,就写写我制作周结账单报表的过程。

一、添加参数

1,在日结账单中,报表已经是这个样子。



2,给报表添加参数。在报表数据中,右击参数,选择添加。

备注:有时候可能会没见着报表数据,打开视图,最下面选择报表数据。



3,设置参数属性。

注意:在选择数据类型时,有日期时间型,但这里我用的是文本。因为在实际应用中我只运用了日期,而如果将这边的参数类型设置为日期时间,那在U层的参数赋值就会有点小问题(后面会跟着时间,查询出错)。


4,添加文本框,将参数拖拽过去。如下图

5,为参数附表达式。右击文本框——表达式——常见函数——日期和时间:



到这里,参数的添加就完成了,接下来,就是在代码中的具体应用。


二、实际应用

查询两个日期间的数据不难,这里主要是说明U层中,关于报表的使用。


1,U层控件添加设置



2,代码实现

<span style="font-size:18px;"><span style="font-family:KaiTi_GB2312;font-size:24px;"> Private Sub btnQuery_Click(sender As Object, e As EventArgs) Handles btnQuery.Click

        '截止日期不能小于起始日期
        If DTP2.Value < DTP1.Value Then
            MsgBox("截止日期不能小于起始日期")
            DTP2.Focus()
            Exit Sub
        End If

        Dim strStartDate As String = DTP1.Value.Date.ToString()
        Dim strEndDate As String = DTP2.Value.Date.ToString()

        Dim listCheckInfo As New List(Of Model.CheckInfoM)
        Dim FCheck As New Facade.CheckOutFA
        listCheckInfo = FCheck.QueryByRDate(strStartDate, strEndDate)

        '填充报表
        '返回的泛型集合为0,则里边没有东西  
        If listCheckInfo.Count > 0 Then

            '定义报表数据源  
            Dim rptDataSource As New ReportDataSource
            '数据源的名称,也就是连接数据库时设置的数据集名称  
            rptDataSource.Name = "DataSet1"
            rptDataSource.Value = listCheckInfo
            '说明ReportViewer承载的报表名  
            ReportViewer1.LocalReport.ReportEmbeddedResource = "Charge.UI.ReportWeek.rdlc"
            '设置两个参数的值  
            Dim StartDate As ReportParameter = New ReportParameter("StartDate", strStartDate)
            ReportViewer1.LocalReport.SetParameters(New ReportParameter() {StartDate})

            Dim EndDate As ReportParameter = New ReportParameter("EndDate", strEndDate)
            ReportViewer1.LocalReport.SetParameters(New ReportParameter() {EndDate})
            '清空ReportViewer的数据源  
            ReportViewer1.LocalReport.DataSources.Clear()
            '加载ReportViewer的数据源为rptDataSource  
            ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
            '刷新ReportViewer  
            Me.ReportViewer1.RefreshReport()

        Else
            MsgBox("这段时间内没有您要的查询内容,请重新选择时间!", MsgBoxStyle.Exclamation, "警告")
            Exit Sub

        End If


    End Sub
</span></span>


三、个人收获

 在周结账单中,只是添加了两个参数,但在刚开始的时候,还是让自己忙活了很久。好在后来终于是给解决了,在这途中,我觉得还是得相信自己的能力,有时候做着做着就烦了,就不想做。但,希望就在你前方。或许,再多查一个资料,再多问一个同学,更甚至是,自己再多憋一分钟,问题就能解决。



posted on 2015-02-23 10:00  何红霞  阅读(239)  评论(0编辑  收藏  举报