Need example binding UI to BL to DL

F

Frank Romano

Hey, everyone. I have an application that was written in VB6 that I have to
rewrite in VB.NET 2003 and I am completely lost. I have tried finding
answers to my questions in MSDN and the newsgroups, but I'm only finding
bits and pieces that just don't add up for me because I must not be using
the right search words. Anyway here is what I need help with.

The existing app would best be described as being a "customer-orders" type.
It uses classes to represent the various business objects. The main ones
are compound objects, the containing object having details specific to a
single instance (such as a "customer" or an "order"), with embedded "typed
collection" classes that would be like "orders for this customer" or "items
for this order". The UI lets the user specify a particular "Parent ID"
which is passed to the respective collection's "Item" method and gets back
the desired instance of that type. The collection class reads the necessary
details from the database and assigns the values to the instance properties.
Once populated, the UI interacts with the object and the contained objects,
not the database. Conversely, when told to save the changes, the class
reads the values out of the instance and writes them back to the database.
The embedded classes and their data are implemented as typed collections,
there is no data binding being used. The UI isn't binding either. Forms
have methods that assign the values from the instance to the various
controls (text boxes, listviews, etc.) or scrapes changes from the UI back
into a particular object. It works, but it is really cumbersome and
inefficient, particularly since we want to be able to use these business and
data layer objects for both Windows clients and eventually web browser
clients.

What I have to do is rewrite the app so that the UI can bind to the business
objects and the business objects in turn bind to the data layer. I
understand the basics of the vbobjectbinding example, but I am completely
confused about how I can in turn bind the class to its data source without
having to resort to the existing app's approach of manually assigning the
property values to the datarows or query parameters. I guess what I want to
do is something like this:

UI passes a specific ID (i.e., "Customer Number") to the Item property of a
business layer object. That in turn executes a method like
"GetCustomerAndOrders(ByVal CustomerID As Integer)" which runs a parameter
query that populates a typed dataset with the details related to that ID (a
datatable containing just the single Customer record, and another datatable
containing the Orders for that Customer ID. Once the dataset is ready,
instead of doing assignments to properties (ThisCustomer.CoName =
ds.customer.cust_co_name) or walking the Orders table and manually
constructing the collection of order headers (For Each dr in ds.orders.rows
.... ThisCustomer.Orders.Add(New OrderInfo(...)), I want to be able to bind
the properties directly to the underlying datarow. In the case of the
"orders" collection, I want the collection to be complex-bound and serve-up
instances of "OrderInfo". When the user sends changes back, I want to be
able to just execute the Update methods without having to scrape the values
from the instance objects. I imagine this would require storing the dataset
with the parent object, and using references to the corresponding
datatables.

What totally confuses me is what I should be specifying for the Inherits
and/or Implements directives to make this work, and then how to write the
binding routines that will pull this off. I have come across partial
examples that say use IBindingList or ArrayList or a specialized collection,
but these are all focused on the UI binding and don't show anything about
how to propagate binding to a dataset. There are also a number of examples
that touch on this using built-in capabilities of VS2005/ADO.NET 2.0, but
that's of no help to me in the present.

Can someone please point me to a comprehensive example of how create a
Windows Forms application to do this using VB 2003 and ADO.NET 1.1? Thanks.
 
K

Ken Tucker [MVP]

Hi,

Maybe this will help.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/uip.asp

Ken
----------------
Hey, everyone. I have an application that was written in VB6 that I have to
rewrite in VB.NET 2003 and I am completely lost. I have tried finding
answers to my questions in MSDN and the newsgroups, but I'm only finding
bits and pieces that just don't add up for me because I must not be using
the right search words. Anyway here is what I need help with.

The existing app would best be described as being a "customer-orders" type.
It uses classes to represent the various business objects. The main ones
are compound objects, the containing object having details specific to a
single instance (such as a "customer" or an "order"), with embedded "typed
collection" classes that would be like "orders for this customer" or "items
for this order". The UI lets the user specify a particular "Parent ID"
which is passed to the respective collection's "Item" method and gets back
the desired instance of that type. The collection class reads the necessary
details from the database and assigns the values to the instance properties.
Once populated, the UI interacts with the object and the contained objects,
not the database. Conversely, when told to save the changes, the class
reads the values out of the instance and writes them back to the database.
The embedded classes and their data are implemented as typed collections,
there is no data binding being used. The UI isn't binding either. Forms
have methods that assign the values from the instance to the various
controls (text boxes, listviews, etc.) or scrapes changes from the UI back
into a particular object. It works, but it is really cumbersome and
inefficient, particularly since we want to be able to use these business and
data layer objects for both Windows clients and eventually web browser
clients.

What I have to do is rewrite the app so that the UI can bind to the business
objects and the business objects in turn bind to the data layer. I
understand the basics of the vbobjectbinding example, but I am completely
confused about how I can in turn bind the class to its data source without
having to resort to the existing app's approach of manually assigning the
property values to the datarows or query parameters. I guess what I want to
do is something like this:

UI passes a specific ID (i.e., "Customer Number") to the Item property of a
business layer object. That in turn executes a method like
"GetCustomerAndOrders(ByVal CustomerID As Integer)" which runs a parameter
query that populates a typed dataset with the details related to that ID (a
datatable containing just the single Customer record, and another datatable
containing the Orders for that Customer ID. Once the dataset is ready,
instead of doing assignments to properties (ThisCustomer.CoName =
ds.customer.cust_co_name) or walking the Orders table and manually
constructing the collection of order headers (For Each dr in ds.orders.rows
.... ThisCustomer.Orders.Add(New OrderInfo(...)), I want to be able to bind
the properties directly to the underlying datarow. In the case of the
"orders" collection, I want the collection to be complex-bound and serve-up
instances of "OrderInfo". When the user sends changes back, I want to be
able to just execute the Update methods without having to scrape the values
from the instance objects. I imagine this would require storing the dataset
with the parent object, and using references to the corresponding
datatables.

What totally confuses me is what I should be specifying for the Inherits
and/or Implements directives to make this work, and then how to write the
binding routines that will pull this off. I have come across partial
examples that say use IBindingList or ArrayList or a specialized collection,
but these are all focused on the UI binding and don't show anything about
how to propagate binding to a dataset. There are also a number of examples
that touch on this using built-in capabilities of VS2005/ADO.NET 2.0, but
that's of no help to me in the present.

Can someone please point me to a comprehensive example of how create a
Windows Forms application to do this using VB 2003 and ADO.NET 1.1? Thanks.
 
F

Frank Romano

Hi, Ken. Thanks for getting back but this doesn't help. The article you
pointed to is about theory and architecture, not actual implementation.

Any other ideas?

Thanks,
Frank
 
N

Nick Malik [Microsoft]

Actually, Frank, the article he pointed to is about a code block that is
available for download along with a number of samples that show how to use
it. It looks like a reasonable approach to the problem you describe. The
block is a straight-forward implementation of the Model-View-Controller
pattern.

In addition, you can also look at NHibernate.
(http://nhibernate.sourceforge.net/) It may suit your needs a little
better.

Your post describes a great deal of frustration in what is called
Object-Relational mapping or Object-Relational Impedence. The Java world
attacked this problem by creating the Hibernate framework that will take a
config file, along with a module that can examine your code, and the
framework does all the work for you of querying the database, retrieving the
data, moving the data in and out of collections of objects of specific
types, and persisting the data back to the database. The amount of code you
have to write is small. If you use a tool like NHibernate, your data layer
becomes trivial, and you can go ahead and put the logic you want in your
business layer.

The objects you'd create would work well for both windows forms and the web.

HTH,
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top