当前位置:编程学习 > VB >>

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

 机房收费系统中的“周结账单”有一个功能是根据选定时间的范围,显示相应的账单数据,这时就用到了“参数”的设定。
    首先,在"报表主对象"中插入参数:右击"参数集合"--插入--参数(DateBegin 和DateEnd)

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

首先,在VB中添加部件:Grid++Report Engine5.0 Type Libirary
在VB中,设置相应的代码:
[vb] 
'定义变量具有相对应的事件 
Dim WithEvents Report As grproLibCtl.GridppReport 
Private Sub Form_Load() 
    '创建报表对象 
    GRDisplayViewer1.Stop 
    Set Report = New grproLibCtl.GridppReport 
 
    '载入报表模板文件,保证相对路径 
    Report.LoadFromFile (App.Path + "\ChargeCheckDay.grf") 
[vb]
    '设置数据库连接字符串 
    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 Sub 
 
Private Sub Report_Initialize() 
'设置各个参数的值 
'开始时间 
    Report.ParameterByName("DateBegin").AsString = Format$(DTPBegin.Value, "yyyy-mm-dd")   '显示开始日期 
'结束时间 
    Report.ParameterByName("DateEnd").AsString = Format$(DTPEnd.Value, "yyyy-mm-dd")        '显示结束日期 
 
End Sub 
 
Private Sub cmdPrint_Click() 
    '打印 
    '因为报表对象的 Print 方法名与 VB 内部定义有冲突,所以要用中括号括起来 
    Report.[Print] (True) 
End Sub 
 
Private Sub cmdPrintPrevious_Click() 
    '打印预览 
    Report.PrintPreview (True) 
End Sub 

效果如图所示:


 

补充:软件开发 , Vb ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,