StrataFrame Forum

Binding BOs to EnhancedList with Parent-Child relationship.

http://forum.strataframe.net/Topic28318.aspx

By Lukasz Kustusz - 9/10/2010

Hello,

I'm quite new to Strataframe Framework. I installed the trial version just yesterday. I'm working on a log viewer project that would represent log records from the DB using the DevExpress gridview (which is the EnhancedList wrapper from the SF). 

The way my DB tables are structured are quite simple. I have three different logs that I'd like to represent in my grid. I have a MasterTable with PK = Rec_ID and LogType_ID, and I have 6 other tables, one for each log type. The MasterTable contains fields common to all logs, like time, user, etc. Each log table also has a Rec_ID, and LogType_ID. I also have a LogTypeDescription table with two fields (LogType_ID, LogDescription) with 6 records in it, each describing different log type.

I've created my BOs, one for each of the tables defined above, and I defined relationdhips between them using ParentRelationship property. Relationships are simple: MasterTable is the parent to all other tables, linking on the Rec_ID, LogType_ID.

I'd like to be able to see those relationships represented in the grid using its Master-detail view, where master records would be expandable showing a different view depending on the type of log.

I was able to bind my MasterTable to the grid (Using BusinessBindingSource bound to the Mastertable), but the relationships are not detected. I've already done something similar using embedded ADO.NET dataset, and it works fine, but I'd like to se if strataframe can do similar tricks. Form the DevExpress documentation I know that in order for the Master-Detail view to work I have to Master-Detail: DataTable specific names for the TableAdapters, ie. AdapterTable1, AdapterTable2 etc (This is in Windows Forms Components > Products > XtraGrid > Concepts > Master-Detail Overview > Binding to Data Specifics > Master-Detail: DataTable Use of the DevExpress documentation)

-> How can I do this with EnhancedList and BOs?

-> Do I have to use BusinessBindingSource, and if not how should I set up the binding?

-> How can I specify that the LogType_ID from every BO be "replaced by" LogDescription from the LogTypeDescription BO? 

-> Is there a way for a BO to  represent a join of two tables?

Thanks,

Lukasz
By Ivan George Borges - 9/11/2010

Hi Lukasz.

Take a look at the posts from here, they can help you:

http://forum.strataframe.net/FindPost27721.aspx

Also, the BOs can represent a view. So if you build a view wich represents your join, you can just create a BO and map it to the view.
By Lukasz Kustusz - 9/13/2010

Thank you for your answer. Unfortunatelly I don't see how this applies to EnhancedList. It is not groupped the same way as XtraReport is. Instead it uses relationships to set-up the GridView structure at design-time. One way suggested was to use DataSets extracted from BOs to do the binding. If I do that, why use strataframe at all? Using views, is also quite combersome, as it forces me to set up all the GridViews at runtime, as opposed to using the extensive features of the EnhancedList's Designer tool. Also I need my application to be able to add/update rows, which is risky using views.



Here's the form as designed with ADO.NET (RunTime)http://forum.strataframe.net/Uploads/Images/bb35ecb3-72bc-43f0-a3bb-912b.png:

And Here's how it looks like at RunTime. Notice the ADO.NET adapters and the View structure in the Designer.

http://forum.strataframe.net/Uploads/Images/96845432-9991-4fa5-acc2-80d2.png

Am I the first to use EnhancedList to represent parent-detail structure? Can it be done with StrataFrame at design time, as it is using ADO.NET DataSets?
By Trent L. Taylor - 9/14/2010

Thanks for your interest in StrataFrame.  As you well know, there are a lot of philosophies in application development, and many times there is more than one way to skin the proverbial cat.  First of all, you would bind using a BusinessBindingSource to the grid.  This provides direct multi-row .NET data binding and is the most appropriate tool for binding to a grid.  Ultimately you would be able to manage your complex configuration.

As for the purpose of StrataFrame, I am almost not sure the best way to answer.  StrataFrame has so much depth and performs so many tasks that purchasing StrataFrame just for the purpose of binding to a grid is kind of like buying a 747 for the peanuts BigGrin.

StrataFrame handles everything from the UI all the way back through to the DAL (Data Access Layer).  It also manages your relationships from an object model perspective and will even propagate this back to the database for you.  By defining your parent-child relationships, the BOs will automatically handle foreign key values and make sure that they are persisted.  So that is one of many benefits that would pertain to your current situation.

StrataFrame is designed to work with 3rd party tools, such as DevExpress, though when working with these tools and understanding the logic behind the 3rd party aspect, you will have to get support from the said 3rd party as StrataFrame users use so many different tools that it is not possible for us to be a support expert in each tool.

As I previously mentioned, there are a lot of philosophies in development, and one is...no offense here...not to be so grid complex.  We have some tools that make short work of parent-child UI.  To begin, our ListView in conjunction with a ChildFormDialog.  This is a quick and simple way to manage child tables with RAD functionality and is generally more user friendly in the end.  StrataFrame was created from our need to produce an extremely massive medical application.  We do use some grids now and then, but we have learned that leaning too heavily on grids can become an end-user issue but also a development issue.  In short, you can do just what you are trying with StrataFrame, but I would recommend taking a look at some other ways to tackle this problem as I think that you will have more positive results all the way around.

Again...this is just my opinion, but that is one great thing about this forum, we all share our experiences and opinions and come out the better for it...as does StrataFrame as we really try to listen!!!
By Lukasz Kustusz - 9/14/2010

Thank you, Trent. I do see your point, to avoid grid-central design, but in this case I'm convinced that this is the way to go due to the built in, drag-and-drop grouping and sorting functionality, filters, etc. The application that I'm trying to develop is just a small module of a future redesign of our LMS software. If I'm successful in implementing this with SFBOs I'd go on to use SF platform for all our future development. So I'll need all of the 747, peanuts included BigGrin

Now, as I wrote initially, I do use BusinessBindingSource, but it seems that the relationships between my BOs are not detected, because the EnhancedList displays only the Parent object. 

I do seem to understand the logic behind the grid, because I use it successfully with ADO.NET datasets in this capacity, as depicted on the screenshots.



Anyway, if you thinks SF BOs can do what  I need them to do, I'd appreciate some specific help. Otherwise, thanks for sharing.
By Ivan George Borges - 9/14/2010

Hi Lukasz.

I went ahead and downloaded DevEx to create a quick sample on how to use the BusinessBindingSource to accomplish a Parent-Child grid situation. You might find the name of my BBSs strange, since I used a sample I had written before on how to accomplish this on a report, and that's why I directed you to those posts when you had the impression that they had nothing to do with what you were asking for. Anyway, this sample has the same principles and uses a DevEx Grid, which is the control that the EnhancedList inherits from, so if you tweak the grid you will probably get the results you want. Here is the link:

http://forum.strataframe.net/FindPost28370.aspx

Hope it helps in some way.

Cheers.
By Lukasz Kustusz - 9/15/2010

Thank you very much for the sample, I'm eager to try it out. I imagine it uses some sample database to which your BOs are mapped. Could you tell me where I can get a copy of this sample DB?
By Ivan George Borges - 9/15/2010

It uses the StrataFrame Sample database that is installed with the SF framework. So you should already have it on your SQL Server.
By Lukasz Kustusz - 9/16/2010

Thank you again for all your support. I've rebuilt my project according to the structure in your sample and it does work. Interestingly it only works with the original DevExpress DataGrid. When I tried to use the SF EnhancedList instead, the entire grid was not visible (of course, the Visible property was true).

Now, there's another question that I'd asked initially, that I'm trying to solve:

-> How can I specify that the LogType_ID from every BO be "replaced by" LogDescription from the LogTypeDescription BO?

In your example this would be equivalent to having a Customer Type where each rec in Customer table would have something like CustomerType_ID, and there would be another table, CUstomerTypeTable, with two fields (CustomerType_ID ,CustomerTypeDescription). 

What I need is to show the CustomerTypeDescription instead of CustomerType_ID in my grid.
By Ivan George Borges - 9/16/2010

You are welcome, Lukasz.

To accomplish what you asked, I would add an unbound column to the grid, if DevEx lets you do it. I use Infragistics, and in situations like that this is what I do. After adding the unbound columns into the grid, I use its InitializeRow event, for example, to set the column value for that current row. It would look something like this:

Private Sub myGrid_InitializeRow( _
    ByVal sender As System.Object, _
    ByVal e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) _
    Handles myGrid.InitializeRow

        '-- check if there are rows to be initialized
        If Me.myGrid.Rows.Count() = 0 Then
            Exit Sub
        End If

        '-- move record point to current row
        MyGridBO1.SeekToPrimaryKey(e.Row.Cells("my_pk").Value)

        '-- get information from foreign table
        LogTypeDescriptionBO1.FillByPrimaryKey(MyGridBO1.LogType_ID)
  
        '-- if found, set caption
        If LogTypeDescriptionBO1.CurrentRowIndex < 0 Then
            e.Row.Cells("unboundcontro_CustomerTypeDescription").Value = RetrieveTextValue("MyLocalizationKey - NotFound")
        Else
            e.Row.Cells("unboundcontro_CustomerTypeDescription").Value = LogTypeDescriptionBO1.CustomerTypeDescription
        End If

End Sub
By Lukasz Kustusz - 9/17/2010

Thank you for your comment. I tried it but it doesn't work exactly as expected. I added an unbound column to the parent view and populate it in the CustomColumnDisplayText like so:


Private Sub GridView2_CustomColumnDisplayText(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs) Handles GridView2.CustomColumnDisplayText
        If GridView2.RowCount = 0 Then
            Exit Sub
        End If
 
        If e.Column.FieldName = "Type" Then
            BoMasterLogType1.SeekToPrimaryKey(e.Value)
        End If

        If BoMasterLogType1.CurrentRowIndex >= 0 AndAlso e.Column.FieldName = "colTypeDescription" Then
            e.DisplayText = BoMasterLogType1.Type_Description
        End If
End Sub



I call the FillAll method of BoMasterLogType1 in Form_Load.

It seems to work as far as the display is concerned, ie every row now has the correct LogDescription in the custom column. But it's not working when I drag the LogDescription column to the Group by section. It only shows one log type at a time - the one that's in the curernt row. Grouping by any of the bound columns works fine, ie. all possible values are shown.

Forgive my ignorance, but shouldn't this linking be done in the Buisness or even Data tier? Is it not possible to link two BOs to produce this effect (like a BO join)? If I wanted to replace grid by a form with text boxes, and I wanted to show the description field instead of ID for any given type or category of a BO, do I have to handle it in the interface like this every time?
By Lukasz Kustusz - 9/17/2010

   See previous post
By Ivan George Borges - 9/20/2010

That is the way I usually go. On the grid, you probably need an event for the Row Initialization.
By Lukasz Kustusz - 9/20/2010

Thanks Ivan, I finally solved the issue with some support from the DevXpress. The problem was with the test for rowcount=0 at the begining of the above procedure: Here's the full description of my solution: http://www.devexpress.com/Support/Center/p/Q275267.aspx

I still think that this type of join should be handled at the business layer, though. In SF forums I found some posts where this is mentioned:

http://forum.strataframe.net/Topic25388.aspx
http://forum.strataframe.net/Topic3321.aspx
http://forum.strataframe.net/Topic5719.aspx

There seems to be several ways, like using DB Views, or dummy ddt profiles, or updating custom fields in the interface (my case). They all seem to have some drawbacks, especially when BOs must be updatable. In contrast, using ADO.NET, while being a more manual approach, does provide a possibility to construct DataSets from joins, with custom UPDATE, DELETE, and INSERT statements if necessary.

 My situation is special in that I'm just testing the StrataSphere out (using the trial version for almost a week) to see if it can give us an advantage over using other frameworks (I'm also evaluating MereMortals, DevExpress) or just sticking to self-developed n-tier approach with ADO.NET in all our future developments. 

At the moment I'm undecided. Let me ask you this:

Is there a plan to support BO joins in the near future?
By Ivan George Borges - 9/20/2010

As Trent has written to you before, StrataFrame covers many different tasks and this might be the diferential to help you make your decision.

About the future plans and features, I wouldn't be able to tell you about your specific question at the moment, but will try and find out with the developers.

Anyway, I am glad you got your problem solved. Wink