Grid++Report 入手教程:VB 通过Grid Report 显示时间

来源:互联网 发布:高中地理视频教学软件 编辑:程序博客网 时间:2024/06/08 14:32

    机房收费系统中的“周结账单”有一个功能是根据选定时间的范围,显示相应的账单数据,这时就用到了“参数”的设定。

    首先,在"报表主对象"中插入参数:右击"参数集合"--插入--参数(DateBegin 和DateEnd)

    然后,在报表模版中插入综合文字框:--插入--部件框--综合文字框,然后点击文字框,在里面输入参数名和显示的文字,格式为[#Parameter1#],如图所示(设定了时间显示格式):

 

首先,在VB中添加部件:Grid++Report Engine5.0 Type Libirary

在VB中,设置相应的代码:

'定义变量具有相对应的事件Dim WithEvents Report As grproLibCtl.GridppReportPrivate Sub Form_Load()    '创建报表对象    GRDisplayViewer1.Stop    Set Report = New grproLibCtl.GridppReport    '载入报表模板文件,保证相对路径    Report.LoadFromFile (App.Path + "\ChargeCheckDay.grf")
    '设置数据库连接字符串    Report.DetailGrid.Recordset.ConnectionString = "Provider=SQLOLEDB;Data Source=192.168.24.54;Initial CataLog=Charge_zlj;UID=sa;PWD=123456"    '显示日结账中,最新一条记录    Report.DetailGrid.Recordset.QuerySQL = "select top 1 * from  CheckDay order by Date desc"    '设置报表查询显示器控件的关联报表对象    GRDisplayViewer1.Report = Report    '启动报表运行    GRDisplayViewer1.Start    End SubPrivate Sub Report_Initialize()'设置各个参数的值'开始时间    Report.ParameterByName("DateBegin").AsString = Format$(DTPBegin.Value, "yyyy-mm-dd")   '显示开始日期'结束时间    Report.ParameterByName("DateEnd").AsString = Format$(DTPEnd.Value, "yyyy-mm-dd")        '显示结束日期End SubPrivate Sub cmdPrint_Click()    '打印    '因为报表对象的 Print 方法名与 VB 内部定义有冲突,所以要用中括号括起来    Report.[Print] (True)End SubPrivate Sub cmdPrintPrevious_Click()    '打印预览    Report.PrintPreview (True)End Sub

效果如图所示: