|
I'm using Object Collection as data source of main report as well as subreport. I can generate report of single Distributor with a collection of sales information using OBJECT COLLECTION Technology but facing problem when i want to create report with a number of Distributors with subreport containing sales info using object collection. i.e i need to setDataSource of the subreport, which shows sales info, for each Distributor in loop. pls take a look in the following code depicting where i need help : I don't want to use any ODBC connection for subreport DataSource.
Private Sub cmdDWSH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDWSH.Click
Dim DWSHs As New ArrayList
Dim dwsh As clsDWSH
Dim RptDwsh As New DWSH (This is Crystal Report File)
Dim colDistrib As List(Of clsDistributor)
Dim DistribDA As New DistributorDataAccess
colDistrib = DistribDA.GetDistributors()
If Not colDistrib Is Nothing Then
For i = 0 To colDistrib.Count - 1
dwsh = New clsDWSH
dwsh.AreaCode = colDistrib(i).AreaCod
dwsh.AreaName = colDistrib(i).Ara
dwsh.AreaManager = ObjArea.GetObjArea(dwsh.AreaCode).ManagerNam
dwsh.DistribName = colDistrib(i).DistributorNam
dwsh.DistribAddress = colDistrib(i).Addres
dwsh.DistribMobile = colDistrib(i).Phon
dwsh.ForMonth = cboMonth.Text
dwsh.ForYear = cboYear.Text
dwsh.ProdGroup = cboProdGrp.Text
DWSHs.Add(dwsh)
--(NOTE : I NEED TO SET THE SUBREPORT DATABASE IN THIS LOOP. I DON’T KNOW WHETHER IT IS POSSIBLE)--
Next i
RptDwsh.SetDataSource(DWSHs)
--(I WANTED TO PUT THE LINE OF CODE BELOW HERE BUT IT EXECUTES WITHOUT ANY OUTPUT)--
RptDwsh.Subreports(0).SetDataSource(Sales)
--(ABOVE LINE OF CODE WORKS FINE FOR SINGLE DISTRIBUTOR AND ALL SALES INFO OF THE DISTRIBUTOR BUT I NEED A NUMBER OF DISTRIBUTORS AND SALS INFO FOR EACH DISTRIBUTOR TO BE PRINTED)--
frmRptViewer.CrystalReportViewer.ReportSource = RptDwsh
frmRptViewer.ShowDialog()
End If
Exit Sub
errHandler:
MessageBox.Show(Err.Description)
End Sub
---------------------------------------------
Private Function Sales () As ArrayList
On Error GoTo errHandler
Dim SaleList As New ArrayList
Dim ObjSale As clsSale
Dim ColSale As List(Of clsSale)
Dim SaleDA As New SaleDataAccess
Dim i As Integer
ColSale = SaleDA.GetSales(txtDistribID.Text)
If Not ColSale Is Nothing Then
For i = 0 To ColSale.Count - 1
ObjSale = New clsSale
ObjSale.SaleDate = ColSale (i).SaleDate
ObjSale.ItemName = ColSale (i).ItemName
ObjSale.QTY = ColSale (i).QTY
ObjSale.UnitPrice = ColSale (i). UnitPrice
SaleList.Add(ObjSale)
Next i
End If
Return SaleList
Exit Function
errHandler:
MessageBox.Show(Err.Description)
End Function
Edited by MasudulIslam - 19 Apr 2010 at 10:54pm
|