Reporting: Create a typed dataset from Business Objects that can be bound at design time to reports, etc
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Reporting: Create a typed dataset from...Expand / Collapse
Author
Message
Posted 04/23/2007 9:04:33 AM
StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: Forum Members
Last Login: 05/12/2007 1:48:10 PM
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
Post #8417
Posted 09/19/2007 6:59:51 AM


StrataFrame Beginner

StrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame BeginnerStrataFrame Beginner

Group: StrataFrame Users
Last Login: Yesterday @ 8:21:39 AM
Posts: 46, Visits: 1,201
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
Post #11566
Posted 09/19/2007 11:06:32 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: 2 days ago @ 8:30:35 PM
Posts: 1,164, Visits: 2,903
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

Thanks!
Post #11584
Posted 09/19/2007 12:50:51 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 9:53:39 AM
Posts: 2,654, Visits: 1,869
Yeah, I might need to move this post... just have to remember how to do it.


www.bungie.net
Post #11590
Posted 09/19/2007 12:51:51 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 9:53:39 AM
Posts: 2,654, Visits: 1,869
There, it's now in the samples


www.bungie.net
Post #11591
Posted 09/19/2007 4:30:05 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIP

Group: StrataFrame Users
Last Login: 2 days ago @ 8:30:35 PM
Posts: 1,164, Visits: 2,903
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 )
Post #11607
Posted 11/26/2007 9:45:32 AM


StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame Novice

Group: Forum Members
Last Login: 06/19/2008 11:16:33 AM
Posts: 73, Visits: 12,471
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
Post #12826
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 12:12am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.063. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.