Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hya. I am trying to bind an XtraReport label to a BO field. Does our BO implements the IList, ITypedList or IBindingList interface? That's what the XtraReport asks me in the help file. I get an error after I set the report DataSource to the BO : Private Sub RelEmpresasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RelEmpresasToolStripMenuItem.ClickDim Report As New rptEmpresas()Dim loEmpresas As New ProFilmeNET_BOL.boEmpresas()loEmpresas.FillDataTable( "Select * from Empresas")Report.DataSource = loEmpresas Report.lblNome.DataBindings.Add( "Text", loEmpresas, "emp_Descr")Report.ShowPreviewDialog() End SubAny word of advice to direct me in the right direction will be appreciated. Thanks in advance.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
That is what the BusinessBindingSource control does for you. If you drop (or create a variable) on you form, you can the set the BusinessObject property to any business object. This basically wraps the BO and provides the IBindingList interface as well.
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Thanks Trent. I'm in a client right now, I will try it later.
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
I know it sounds stupid. But I'm extremely happy I put a simple report to work! Thanks a lot Trent.
|
|
|
StrataFrame Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
Glad you got it working, Ivan
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
Ivan, I was able to trick the Xtra Report into allowing you to drop a BusBinding Source and Bus object onto it. first create a base class report that implements IContainer. I still need to figure a few things out to make it better but below is what I have so far and seems to work. The Preview won't work but you can bind all the fields etc. But to be honest i am wondering if I even wnat to use BO's for the reports as it seems like most reports i have are base on query's with joins. But here is what I did maybe it will be helpful Public Class XtraReportBase Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl 'Add This Line Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call.End SubPublic Sub AddBusinessObject(ByVal BusinessObject As MicroFour.StrataFrame.Business.BusinessLayerBase) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddBusinessObject End Sub Public Sub AddObjectToInitOnLoad(ByVal ObjectToInit As MicroFour.StrataFrame.UI.IInitOnFormLoad) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToInitOnLoadEnd SubPublic Sub AddObjectToPreInitOnLoad(ByVal ObjectToPreInit As MicroFour.StrataFrame.UI.IPreInitOnFormLoad) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToPreInitOnLoadEnd SubPublic Sub RemoveBusinessObject(ByVal BusinessObject As MicroFour.StrataFrame.Business.BusinessLayerBase) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.RemoveBusinessObjectEnd SubEnd ClassNow go into the designer.vb file of the base report and change Friend WithEvents Detail As DevExpress.XtraReports.UI.DetailBandFriend WithEvents PageHeader As DevExpress.XtraReports.UI.PageHeaderBandFriend WithEvents PageFooter As DevExpress.XtraReports.UI.PageFooterBandto Protected WithEvents Detail As DevExpress.XtraReports.UI.DetailBandProtected WithEvents PageHeader As DevExpress.XtraReports.UI.PageHeaderBandProtected WithEvents PageFooter As DevExpress.XtraReports.UI.PageFooterBand Next create a new class that looks like below Public Class InheritedReport Inherits ReportBase.XtraReportBase ' The base class from above Public Sub New()InitializeComponent() End SubPrivate Sub InitializeComponent()End SubEnd ClassRebuild and you should be able to get into the designer of your new subclassd report Drop a business binding source and bus object on the form set the data source of the report to be the business binding source. The type editor of the business binding source will not work so you need to set it manually in the init component. Maybe this can figured out Public Class InheritedReportInherits ReportBase.XtraReportBaseFriend WithEvents XrLabel1 As DevExpress.XtraReports.UI.XRLabelFriend WithEvents BusinessBindingSource1 As MicroFour.StrataFrame.Business.BusinessBindingSourceFriend WithEvents BusinessObject11 As TEstBO.BusinessObject1Private components As System.ComponentModel.IContainerPublic Sub New(Lcname as String)InitializeComponent() I also added the fill method here ? works Me.BusinessObject11.FillByName(LcName)End Sub Private Sub InitializeComponent()Me.components = New System.ComponentModel.ContainerMe.XrLabel1 = New DevExpress.XtraReports.UI.XRLabelMe.BusinessBindingSource1 = New MicroFour.StrataFrame.Business.BusinessBindingSource(Me.components)Me.BusinessObject11 = New TEstBO.BusinessObject1(Me.components)CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()''Detail'Me.Detail.Controls.AddRange(New DevExpress.XtraReports.UI.XRControl() {Me.XrLabel1})''XrLabel1'Me.XrLabel1.Location = New System.Drawing.Point(33, 8)Me.XrLabel1.Name = "XrLabel1"Me.XrLabel1.Padding = New DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100.0!)Me.XrLabel1.Size = New System.Drawing.Size(100, 25)Me.XrLabel1.Text = "XrLabel1"''BusinessBindingSource1'Me.BusinessBindingSource1.ParentForm = Nothing'Manually add Line BelowMe.BusinessBindingSource1.BusinessObject = Me.BusinessObject11''BusinessObject11'Me.BusinessObject11.ParentContainer = MeMe.BusinessObject11.SynchronizingObject = NothingCType(Me, System.ComponentModel.ISupportInitialize).EndInit()End SubEnd Class Now to call the report... Dim rpt As New TestAppReports.InheritedReport("TEST")rpt.ShowPreview()
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hi Paul. Thanks for your help! I will study your code. I have created an XtraReport abstract class, and in the inherited ones I've being writing code to bind the controls at runtime. I've been able to run the reports using the BOs, but I've been creating them at runtime. I'm not binding the report controls at design time. So, I use the BOs to populate the information I need, then add them to a DataSet, working with the results there. So far, I haven't created very complex reports, yesterday I managed to make a Master-Detail report to work using the BOs in this way. But you are right, I wonder what the best practice will be when a more complex situation arrives. As usual, I think I will let Trent, Ben and Steve worry for me.  I bet they are gonna jump in and say something.
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
Ivan, I have been struggling with the concept of how I want to deal with Reports and Data Access for the last few days and I can't seem to decide how best to implement it. I guess it would be nicer to have all the data access come from a bus object library. But at the same time with joined queries for reporting it makes it a bit trickier. I guess you would have to create a view and base a bo off the view. At the same time it is simple enough to create the typed DS right in the report. but you need watch connection strings etc. I guess it really doesnt matter.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 7K
|
Well if it were me I would not venture too far from the business objects. You can create any type of JOIN query from within a BO to return any fields that you want. You can create a view, as you mentioned, to pull back all of the fields you want in a flat format. If you need to create custom fields or a BO that supports a special DDT layout and then your FillDataTable(...) method pulls data using the inner join, you can. When you start dealing with typed data sets you are heading for frustrations the first time you want to make a change. There are a lot of different ways to "skin the cat" so to speak...but you also want to make sure that you are not painting yourself into a corner down the road. Any of these options, including the typed data set, will work. But when you start pulling connection strings and talking directly to the data you are breaking encapsulation so if some day you want to change your back end...including the Middle Tier Enterprise Server, your reports will break. If you work inside the confines of the business object you can change your backend database or connect to the Enterprise Server interchangeably without having to change this code. Note: Any custom connection you make outside of the logic of the framework will prevent the data access layer from being interchangable without having dramatic side-effects within your application...this includes the Middle Tier Enterprise Server that will be released by the end of the year.
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hi guys. Trent L. Taylor (10/13/2006) Well if it were me I would not venture too far from the business objects. This is exactly what I keep in mind. I realize there's a whole attention built inside the BOs, and for a start I want to take advantage of not having to worry about it. And then, there's the back end, and the Middle Tier. I will stick to the BOs. You can create any type of JOIN query from within a BO to return any fields that you want. You can create a view, as you mentioned, to pull back all of the fields you want in a flat format. If you need to create custom fields or a BO that supports a special DDT layout and then your FillDataTable(...) method pulls data using the inner join, you can. This is where I need to get proficiency at. But seeing you say it is possible, is already a good incentive. So, Paul, I think we will be safer under the wings of the BOs. Guess we just have to find our way in it.
|
|
|