我正在尝试创建一个报告,以this为例,将sql查询中的数据作为数据源。
一切运行顺利,所有3条测试记录都放入数组列表中。但是,当报告显示只显示一条记录时。
你能告诉我我做错了什么吗?谢谢记录类:
Public Class RecordGastoDotacion
Dim _id, _usuario As Integer
Dim _cantidad As String
Dim _fecha, _hora As String
Dim _desc As String
Public Sub New(ByVal id As Integer, ByVal fecha As Date, ByVal hora As Date, ByVal cantidad As String, ByVal descripcion As String, ByVal usuario As Integer)
Me._id = id
Me._fecha = fecha.ToString("dd/MM/yyyy")
Me._hora = hora.ToString("hh:mm:ss")
Me._cantidad = cantidad
Me._desc = descripcion
Me._usuario = usuario
End Sub
Public Property idgasto() As Integer
Get
Return _id
End Get
Set(ByVal Value As Integer)
_id = Value
End Set
End Property
Public Property fef() As String
Get
Return _fecha
End Get
Set(ByVal Value As String)
_fecha = Value
End Set
End Property
Public Property feh() As String
Get
Return _hora
End Get
Set(ByVal Value As String)
_hora = Value
End Set
End Property
Public Property cant() As String
Get
Return _cantidad
End Get
Set(ByVal Value As String)
_cantidad = Value
End Set
End Property
Public Property descr() As String
Get
Return _desc
End Get
Set(ByVal Value As String)
_desc = Value
End Set
End Property
Public Property usuario() As Integer
Get
Return _usuario
End Get
Set(ByVal Value As Integer)
_usuario = Value
End Set
End Property
End Class
报告创建:
Cmd.CommandText = String.Format("SELECT gas.idre_gasto as idgasto, date(fe.fecha) as fef, time(fe.fecha) as feh, gas.cantidad as cant, gas.descripcion as descr, gas.re_usuario_idre_usuario as usuario FROM re_gasto as gas INNER JOIN re_corte_caja AS cor ON gas.re_corte_caja_idre_corte_caja = cor.idre_corte_caja
inner join re_fecha as fe on cor.re_fecha_idre_fecha = fe.idre_fecha WHERE date(fe.fecha) BETWEEN '{0:yyyy-MM-dd}' AND '{1:yyyy-MM-dd}' AND cor.estatus = {2}",
DateTimePicker1.Value, DateTimePicker2.Value, ESTATUS_ACTIVO)
rs = Cmd.Execute
Dim listDataSource As New ArrayList()
Do While Not rs.EOF
listDataSource.Add(New RecordGastoDotacion(CInt(rs("idgasto").Value), CType(rs("fef").Value, Date), CType(rs("feh").Value, Date),
CType(rs("cant").Value, String), CType(rs("descr").Value, String),
CInt(rs("usuario").Value)))
rs.MoveNext()
Loop
Dim gastos As New ReporteGastos() With {.Margins = New Printing.Margins(100, 100, 25, 25), .DataSource = listDataSource}
gastos.XrLabel4.Text = String.Format("Día Creación: {0}", Now.ToString("dd/MM/yyyy"))
gastos.XrLabel5.Text = String.Format("Hora Creación: {0}", Now.ToString("hh:MM"))
gastos.AddBoundLabel("idgasto", New Rectangle(100, 20, 50, 30))
gastos.AddBoundLabel("fef", New Rectangle(150, 20, 100, 30))
gastos.AddBoundLabel("feh", New Rectangle(250, 20, 100, 30))
gastos.AddBoundLabel("cant", New Rectangle(350, 20, 50, 30))
gastos.AddBoundLabel("descr", New Rectangle(450, 20, 100, 30))
gastos.AddBoundLabel("usuario", New Rectangle(550, 20, 50, 30))
gastos.XrLabel12.Text = total
Using printTool As New ReportPrintTool(gastos)
printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default)
End Using
ReporteGastos:
Imports System.Drawing
Imports DevExpress.XtraReports.UI
Public Class ReporteGastos
Public Sub AddBoundLabel(ByVal bindingMember As String, ByVal bounds As Rectangle)
' Create a label.
Dim label As New XRLabel()
' Add the label to the report's Detail band.
Detail.Controls.Add(label)
' Set its location and size.
label.Location = bounds.Location
label.Size = bounds.Size
' Bind it to the bindingMember data field.
' When the dataSource parameter is Nothing, the report's data source is used.
label.DataBindings.Add("Text", Nothing, bindingMember)
End Sub
End Class
输出:
答案 0 :(得分:1)
请参阅以下文档链接,了解ArrayList如何与XtraReport配合使用:
How to: Bind a Report to an Array List
Binding a Report to Lists
How to: Bind a Report to a Collection that Implements the ITypedList Interface
Providing Data to Reports
如果ArrayList包含多个项目,则从当前代码中它应显示多条记录。请阅读与数据源分配相关的XtraReport文档。
使用您提供的代码段检查example它是否按预期工作。您可能会以错误的方式报告报告中的某些控件。请尝试删除并添加这些与数据源逐个绑定的额外控件,以便您可以找出导致问题的控件。