您的位置:首页 > 编程语言 > VB

机房收费系统之结账与报表(三)VB与报表代码《一学就会傻瓜版》

2013-11-08 11:50 543 查看
如果不明白逻辑关系没做包表模板的、建议先看前面的详细讲解

有错请及时指出、有错必改、方便大家!(点击进入)

机房收费系统之报表(上)逻辑关系
机房收费系统之报表(中)周报表***
机房收费系统之报表(下)VB与报表代码



在第二篇博客中报表模板做好了、VB中要先添加控件、然后用代码调用报表模板

1.添加Grid++Report 的控件、如图

2.选择名字为GRDisplayViewer的控件、放到From上(蓝色第一个)

3.其他控件也放上去、名字如下图(跟我名字一样才能用.名字不一样要改代码)



4.开始时间和结束时间用的是时间控件DTPicter时间控件,部件载入名上图有(本人忘了是哪个了……)

5.引用(菜单--工程--引用)引用Grid++Re…………如图



6.代码(复制进去应该就行了、有详细备注、实在不懂的可以点我

Dim WithEvents Report As grproLibCtl.GridppReport  '实例化报表</SPAN>
'报表刷新
Private Sub cmdCheckDay_Click()
    Dim txtsql As String
    '判定终止日期不能小于起始日期
    If StartDateView.Value > EndDateView.Value Then '条件限制
        MsgBox "终止日期不能小于起始日期!", ,"温馨提示"
        Exit Sub
    End If

    Report.DetailGrid.Recordset.ConnectionString = ConnectString '数据源连接数据库直接调用写好的模块内容
    If txtBalance.Text = "" Then '判断上期text里是否为空
        '查询日期1到日期2的记录
        txtsql = "select * from ReportForms_Info where cast(convert(varchar,date) as datetime) between '" & _
                 StartDateView.Value & "' and '" & EndDateView.Value & "'"
    Else
        '如果上期余额的text里不为空则查询日期1到日期2中、上期余额是文本中的记录
        txtsql = "select * from ReportForms_Info where cast(convert(varchar,date) as datetime) between '" & _
                 StartDateView.Value & "' and '" _
                 & EndDateView.Value & "' And Balance = '" & txtBalance.Text & "'"
    End If

    '显示报表中的内容
    Report.DetailGrid.Recordset.QuerySQL = txtsql
    grdWeekliyBill.Refresh

    '报表模板上的4个日期或时间赋值
    Report.ParameterByName("Date1").Value = Format$(StartDateView.Value, "yyyy-mm-dd")
    Report.ParameterByName("Date2").Value = Format$(EndDateView.Value, "yyyy-mm-dd")
    Report.ParameterByName("Date3").Value = Date
    Report.ParameterByName("time").Value = Time

End Sub
'预览
Private Sub cmdpreview_Click()
    Report.PrintPreview (True)
End Sub

'打印
Private Sub cmdput_Click()
    Report.[Print] (True)
End Sub

'载入窗体
Private Sub Form_Load()
    '创建报表对象
    Set Report = New grproLibCtl.GridppReport
    '载入报表模版文件
    Report.LoadFromFile (App.Path & "\周报表.grf")
    '设置数据连接串
    Report.DetailGrid.Recordset.ConnectionString = ConnectString

    '查询语句
    txtsql = "select * from ReportForms_Info where cast(convert(varchar,date) as datetime) between '" & StartDateView.Value & "' and '" & EndDateView.Value & "'"
    Report.DetailGrid.Recordset.QuerySQL = txtsql '执行
    '显示报表中的内容
    grdWeekliyBill.Report = Report
    grdWeekliyBill.Start

    '报表模板上的4个日期或时间赋值
    Report.ParameterByName("Date1").Value = Format$(StartDateView.Value, "yyyy-mm-dd")
    Report.ParameterByName("Date2").Value = Format$(EndDateView.Value, "yyyy-mm-dd")
    Report.ParameterByName("Date3").Value = Date
    Report.ParameterByName("time").Value = Time

End Sub




有错请及时指出、有错必改、方便大家!

机房收费系统之报表(上)逻辑关系
机房收费系统之报表(中)周报表***
机房收费系统之报表(下)VB与报表代码



—————一开始真被TA唬住了!———chenchen
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: