Filling a BO from a BBS
 
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 )
      



Filling a BO from a BBSExpand / Collapse
Author
Message
Posted 05/05/2008 2:44:28 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 3:00:39 PM
Posts: 244, Visits: 816
I have created several custom BBS's for use in my DX report.  So far, all is going quite well.  One thing that would make my life a lot easier is being able to access my custom fill methods from the BO.  Here is an example of my code to fill a BO which fills the BBS which provides data for my report:

public partial class PackingListDS : BusinessBindingSource
{
   
public PackingListDS()
    {
        InitializeComponent();
       
BusinessObject = new PackingListBO();
    }

   
public PackingListDS(IContainer container)
    {
        container.Add(
this);
        InitializeComponent();
       
BusinessObject = new PackingListBO();
    }

   
public void Fill(int pPLIndex)
    {
       
BusinessObject.FillByPrimaryKey(pPLIndex);
    }
}

This works great!  But, what if I want to fill the BO with a different method than the base methods (MyBO.FillWithMyReallyCoolMethod())?  If I could somehow cast the BBSs BO as the BO of choice, then I could get to them.  How do I do this?

Thanks,
Bill
Post #16155
Posted 05/05/2008 4:38:29 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 3:24:00 PM
Posts: 3,733, Visits: 3,926
Really, the best way would be to create your ReportBaseBBS class as a generic class that must be inherited and accepts the BOs that it will represent as generic inheritance definitions.  This would allow you to talk straight to the business objects in strong-typed code without having to CType the object.  Here is what the report BBS base class would look like:

Step 1 - Base Report BBS Class
This clas is the abstract class that all other report BBS classes would inherit from.  You'll see that the definition requires a primary business object to be specified (you can add all of the required BOs that you want to, but this is not necessary as other BBS classes could be exposed on the actual classes [i.e. MyCustomersBBS, MyOrdersBBS, etc.]).  But we know that we are going to need at least one business object for each BBS.  So you can see that the class defined a generic parm called TPrimaryBO (you can call this whatever you want).  This will require a BusinessLayer class with a constructor (that is what the new() is doing).

/// <summary>
/// Create the base class of the reporting engine
/// </summary>
/// <remarks></remarks>
public abstract class ReportBaseBBS<TPrimaryBO> : MicroFour.StrataFrame.Business.BusinessBindingSource where TPrimaryBO : BusinessLayer, new()
{

#region  Constructors

/// <summary>
/// Default Constructor
/// </summary>
/// <remarks></remarks>
public ReportBaseBBS()
{
    //-- Create a new instance of the primary business object that this class wraps
    this.BusinessObject = _PrimaryBO;
}

#endregion

#region  Declare Privates

private TPrimaryBO _PrimaryBO = new TPrimaryBO();

#endregion

#region  Public Properties

/// <summary>
/// Exposes the primary business object so that you can reference it in code
/// </summary>
/// <value></value>
/// <returns></returns>
/// <remarks></remarks>
public TPrimaryBO PrimaryBO
{
    get
    {
        return _PrimaryBO;
    }
}

#endregion

}

Step 2 - Creating a Customers BBS Class
The next step would be creating the custom class that inherits the ReportBaseBBS and specifies which business object to wrap.  In the below example, you can see that we are inheriting the ReportBaseBBS class and supplying the business object type that will be the primary BO in this class (TPrimaryBO).

/// <summary>
/// This class is a BBS wrapper for the customers business object type
/// </summary>
/// <remarks></remarks>
public class CustomersReportBBS : ReportBaseBBS<CustomersBO>
{

}

Step 3 - Now you can directly access anything on the Primary BO
You will see in the below code sample, that once the CustomersReportBBS class is created, you can directly access the wrapped BO now through the property that was created in the ReportBaseBBS class (PrimaryBO).

public class TestCode
{

/// <summary>
/// Just shows how to use the code
/// </summary>
/// <remarks></remarks>
public TestCode()
{
    CustomersReportBBS cust = new CustomersReportBBS();

    //-- You can now access every method, etc. strong-typed through code since it is exposed
    //   through the PrimaryBO property using the typed generic.
    cust.PrimaryBO.FillWithMyCoolMethod();
}

}

This would be the cleanest way to achieve what you are trying to do.  For those VB.NET developers, here is the VB code:

VB.NET - Step 1

''' <summary>
''' Create the base class of the reporting engine
''' </summary>
''' <remarks></remarks>
Public MustInherit Class ReportBaseBBS(Of TPrimaryBO As {BusinessLayer, New})
    Inherits MicroFour.StrataFrame.Business.BusinessBindingSource

#Region " Constructors "

    ''' <summary>
    ''' Default Constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        '-- Create a new instance of the primary business object that this class wraps
        Me.BusinessObject = _PrimaryBO
    End Sub

#End Region

#Region " Declare Privates "

    Private _PrimaryBO As New TPrimaryBO()

#End Region

#Region " Public Properties "

    ''' <summary>
    ''' Exposes the primary business object so that you can reference it in code
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property PrimaryBO() As TPrimaryBO
        Get
            Return _PrimaryBO
        End Get
    End Property

#End Region

End Class

VB.NET - Step 2

''' <summary>
''' This class is a BBS wrapper for the customers business object type
''' </summary>
''' <remarks></remarks>
Public Class CustomersReportBBS
    Inherits ReportBaseBBS(Of CustomersBO)

End Class

VB.NET - Step 3

Public Class TestCode

''' <summary>
''' Just shows how to use the code
''' </summary>
''' <remarks></remarks>
Public Sub New()
Dim cust As New CustomersReportBBS()

'-- You can now access every method, etc. strong-typed through code since it is exposed
'   through the PrimaryBO property using the typed generic.
cust.PrimaryBO.FillWithMyCoolMethod()
End Sub

End Class

Post #16157
Posted 05/05/2008 6:19:50 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Yesterday @ 3:00:39 PM
Posts: 244, Visits: 816
Totally Awesome!

(bows)

Post #16162
Posted 05/05/2008 6:32:56 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 3:24:00 PM
Posts: 3,733, Visits: 3,926
LOL...thanks...hope it helps
Post #16164
« 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 2:00am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 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.