机房收费系统中的Grid++Report报表设计器的应用
在进行账单查询功能的时候我应用了Grid++Report报表设计器,下面我就为大家介绍一下,还望大家多多指点。
首先,在Grid++Report报表设计器中进行报表界面的设置。在属性编辑窗口中这里对报表头、标题行、内容行进行设置,具体的操作不在赘述,我设计的报表界面如下所示。
其次,在机房收费系统项目中的UI层中添加应用,在COM中选择Grid++Report Designer 5.6Type Library和Grid++Report Engine Plugin 5.6Type Library。
再次,在代码编辑器中加入Grid++Report类型库名字空间引用,即为Imports grproLib。
最后在代码编辑器中进行编辑,来应用报表设计器进行账单查询:
'加入Grid++Report类型库名字空间引用
Imports grproLib
''' <summary>
''' 查询账单
''' </summary>
''' <remarks></remarks>
Public Class frmQueryItemsBill
'定义Grid++Report报表主对象
Private Report As New GridppReport
Dim NameField As grproLib.IGRField
'上次消费余额
Dim PriorperiodCashField As IGRField
'本期充值金额
Dim CurrentCreditField As IGRField
'本期消费金额
Dim CurrentConsumptionField As IGRField
'本期退卡金额
Dim CurrentAmountrefundedField As IGRField
'本期总金额
Dim CurrentCashField As IGRField
'结账时间
Dim DateField As IGRField
''' <summary>
''' 加载账单
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub frmQueryItemsBill_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'载入报表模板数据
Report.LoadFromFile(GetReportTemplatePath() + "Bill.grf")
'连接报表事件
AddHandler Report.Initialize, AddressOf ReportInitialize
AddHandler Report.FetchRecord, AddressOf ReportFetchRecord
'设定查询显示器关联的报表
AxGRDisplayViewer1.Report = Report
DateTimePicker1.Value = New DateTime(Year(Now), Month(Now), 1)
DateTimePicker2.Value = New DateTime(Year(Now), Month(Now), 1)
PriorperiodCashField = Report.FieldByName("PriorperiodCash")
CurrentCreditField = Report.FieldByName("CurrentCredit")
CurrentConsumptionField = Report.FieldByName("CurrentConsumption")
CurrentAmountrefundedField = Report.FieldByName("CurrentAmountrefunded")
CurrentCashField = Report.FieldByName("CurrentCash")
DateField = Report.FieldByName("Date")
AxGRDisplayViewer1.Start()
End Sub
''' <summary>
''' 刷新
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnFreshen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFreshen.Click
If CStr(DateTimePicker1.Value) > CStr(DateTimePicker2.Value) Then
MsgBox("对不起起始时间应该小于结束时间")
Exit Sub
End If
AxGRDisplayViewer1.Stop()
AxGRDisplayViewer1.Start()
End Sub
''' <summary>
''' 打印预览
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnPreview_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPreview.Click
Report.PrintPreview(True)
End Sub
''' <summary>
''' 打印
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnPrinter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrinter.Click
Report.Print(True)
End Sub
''' <summary>
''' 报表初始化
''' </summary>
''' <remarks></remarks>
Private Sub ReportInitialize()
Report.ControlByName("SubTitle").AsStaticBox.Text = _
"从" + CStr(DateTimePicker1.Value) + "至" + CStr(DateTimePicker2.Value)
End Sub
Public Function GetReportTemplatePath() As String
Dim FileName As String = Application.StartupPath.ToLower()
Dim Index As Integer = FileName.LastIndexOf("bin")
FileName = FileName.Substring(0, Index)
GetReportTemplatePath = FileName
End Function
''' <summary>
''' 添加报表记录
''' </summary>
''' <remarks></remarks>
Private Sub ReportFetchRecord()
'定义开始结账实体
Dim entityBeginAccount As New Entity.AccountInfoEntity
'定义结束结账实体
Dim entityEndAccount As New Entity.AccountInfoEntity
'定义B层结账
Dim bllAccount As New BLL.AccountBLL
'定义数据表
Dim dt As DataTable
'定义返回的数据行
Dim intRows As Integer
entityBeginAccount.BookDate = DateTimePicker1.Value
entityEndAccount.BookDate = DateTimePicker2.Value
dt = bllAccount.InquiryAccount(entityBeginAccount, entityEndAccount)
'添加账单记录
intRows = dt.Rows.Count
For intRows = 0 To (intRows - 1)
Report.DetailGrid.Recordset.Append()
PriorperiodCashField.AsInteger = dt.Rows(intRows).Item("PriorAmount")
CurrentCreditField.AsInteger = dt.Rows(intRows).Item("RechargeAmount")
CurrentConsumptionField.AsInteger = dt.Rows(intRows).Item("ConsumeAmount")
CurrentAmountrefundedField.AsInteger = dt.Rows(intRows).Item("RemoveCardAmount")
CurrentCashField.AsInteger = dt.Rows(intRows).Item("TotalAmount")
DateField.AsString = dt.Rows(intRows).Item("BookDate")
Report.DetailGrid.Recordset.Post()
Next
End Sub
因为B层和D层的代码不涉及Grid++report的应用我就不为大家展示。账单查询界面如下图所示:
这是我用的添加查询记录的方法。开始我本来是想将DataTable中的数据以单元格的形式循环遍历到到Grid++report中,但是未能实现,望有高手多多指教。