Reporting: Create a typed dataset from Business Objects that can be bound at design time to reports,...


Reporting: Create a typed dataset from Business Objects that can be...
Author
Message
Jerome Barnett
Jerome Barnett
StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)StrataFrame Beginner (12 reputation)
Group: Forum Members
Posts: 10, Visits: 65
I needed to create some reports which need data from multiple tables. Originally I was creating Business Objects based off of views..but that's just ugly to me so.....



I created a dataset that I could bind Crystal Reports to at design time.



First I created a class that would output an .xsd file with the dataset schema.



Imports System.Data

Imports MicroFour.StrataFrame.Business



Public Class CreatePICDataset



Private Shared GenderBO As New PICData.Gender

Private Shared InsuranceCardBO As New PICData.InsuranceCard

Private Shared InsuranceTypeBO As New PICData.InsuranceType

Private Shared LanguageBO As New PICData.Language

Private Shared PatientBO As New PICData.Patient

Private Shared PatientHistoryBO As New PICData.PatientHistory

Private Shared RaceBO As New PICData.Race

Private Shared VoterRegBO As New PICData.VoterReg

Private Shared PICDS As New DataSet



Public Shared Sub CreateDataset()

PICDS.DataSetName = "PICDataSet"

AddBOTableToDataset(GenderBO)

AddBOTableToDataset(InsuranceCardBO)

AddBOTableToDataset(InsuranceTypeBO)

AddBOTableToDataset(LanguageBO)

AddBOTableToDataset(PatientBO)

AddBOTableToDataset(PatientHistoryBO)

AddBOTableToDataset(RaceBO)

AddBOTableToDataset(VoterRegBO)

PICDS.WriteXmlSchema("C:\PICDataSet.xsd")

End Sub



Private Shared Sub AddBOTableToDataset(ByVal myBO As BusinessLayer)

myBO.FillDataTable("Select * from " & myBO.TableName & " where 1 = 0")

PICDS.Tables.Add(myBO.CurrentDataTable)

End Sub



End Class







I call the CreateDataSet method of this class anytime I change my BO's /DB structure. I then copy the output file to my project and set it as an embedded resource.



I then created a class which inherits from dataset and reads it's schema from the embedded .xsd file in the project



Imports System.Data



Public Class PICDataset

Inherits DataSet



Private AppAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()

Private AppAssemblyPath As String = Me.AppAssembly.GetName().Name().Replace(" ", "_")



Public Sub New()

Try

Me.ReadXmlSchema(GetResource("PICDataSet.xsd"))

Catch ex As Exception

MsgBox(ex.Message)

End Try

End Sub



Private Function GetResource(ByVal FileName As String) As System.IO.Stream

Try

Return Me.AppAssembly.GetManifestResourceStream(Me.AppAssemblyPath & "." & FileName)

Catch ex As Exception

MessageBox.Show("Error returning resource: " & ex.ToString(), "GetResource!", MessageBoxButtons.OK, MessageBoxIcon.Error)

Return Nothing

End Try

End Function



End Class




At design time I can now bind a report to a Typed Dataset (you could go a step further and add the relationships in code, but I do this in Crystal)



At runtime to populate my dataset for a report, I create an instance of the dataset class and add tables using the currentdatatable from my business objects



Dim ds As New PICDataset

ds.Tables(PatientBO.TableName).Load(PatientBO.CurrentView.ToTable.CreateDataReader)

ds.Tables(GenderBO.TableName).Load(GenderBO.CurrentDataTable.CreateDataReader)

ds.Tables(LanguageBO.TableName).Load(LanguageBO.CurrentDataTable.CreateDataReader)

ds.Tables(RaceBO.TableName).Load(RaceBO.CurrentDataTable.CreateDataReader)

ds.Tables(InsuranceCardBO.TableName).Load(InsuranceCardBO.CurrentDataTable.CreateDataReader)

rptPIF_English.SetDataSource(ds)




Hopefully this helps someone.



Jerome
Ralph Rutschmann
Ralph Rutschmann
StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)StrataFrame Novice (81 reputation)
Group: Forum Members
Posts: 69, Visits: 1.3K
Thank you very much, Jerome! :-)



I don't know if it helped someone other so far, but it helped me a lot!



Thanks again and friendly greetings,



Ralph
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Jerome,



Thanks for this very nice sample. There is a forum for just this sort of thing, the StrataFrame Users Contributed Samples (http://forum.strataframe.net/Forum26-1.aspx) forum, and I posted there, linking back to this post. It could get lost here BigGrin



Thanks!
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yeah, I might need to move this post... just have to remember how to do it.
StrataFrame Team
S
StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)StrataFrame Developer (3.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
There, it's now in the samples Smile
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.7K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ben,



You should probably delete my link to it then. No need to have it here twice.



(I didn't know you could move stuff...that's cool w00t )
Charles Thomas Blankenship...
Charles Thomas Blankenship
StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)StrataFrame User (350 reputation)
Group: Awaiting Activation
Posts: 172, Visits: 12K
Hi Jerome:



You wouldn't mind if I added this to my examples project would you?



I believe I'll put this in the Chapter 10 slot.



Thanks,



C. T. Blankenship

Charles T. Blankenship
Senior Consultant
Novant Consulting, Inc.
704.975.7152
http://www.novantconsulting.com
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search