473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

User Control Design

Dan
All,

I have a windows form application. The form will host various user controls
that will implement an interface so that was new controls can be added later
without recompiling the hosting program.

The various controls will be displaying data that is stored in a SQL database.

My question is what is the prefered way of having the controls access the
business layer that will in turn access the data layer? Does the control
access the business layer directly or does the control get access via the
hosting form? Any insight or reasons as to why one way is prefered would be
great.
Thanks for the help!

Dan
Nov 16 '05 #1
2 1912

Hi Dan,

Generally you will want to have a data access / business layer that is
distinct from the user interface. It makes the code cleaner and more
maintainable.

For example, consider the quintessential invoice entry application.
You have a form with a table that lists all of the items on the invoice
and some things to add items to the invoice.

With that in mind, you could have a business tier that looks something
like this:

namespace MyBusiness {

class Item {
private string partNumber;
public string PartNumber { get { return partNumber; } set { partNumber
= value; } }

public Item[] GetAllAvailableItems()
{
/* database stuff */
}

}

class Invoice {

private ArrayList items;

public void AddItem( Item _item );

public void Save()
{
/* do database stuff here */
}

public static Invoice Load( string _invoiceNumber )
{
/* do database stuff here */
}

public static Invoice CreateNew( )
{
/* do database stuff here */
}

public static string[] GetInvoiceNumberList()
{
/* do database stuff here */
}

}

This is a very small off the top of my head example, but clearly,
unencumbered by ui considerations, you can think about where your data
is going. In your form you could have a combo box that gets populated
by a call to GetInvoiceNumberList() to select invoices. Then you could
call create new Item objects and Add them to your invoice list.

The nice thing about this approach is that down the road you can move
your "middle tier" to be a physical middle tier, so all you'd have to
deploy is the client and it in turn would talk via .NET remoting to
your server. This would allow you manage your database connections
more readily, for example, and provide an additional layer of security.

Conversely, if you embedded all of your database statements into your
forms, you will find them getting very difficult to maintain. You will
find it more difficult to figure out bugs and such.
In any case, good luck!

Nov 16 '05 #2
There are many ways you can get the user controls to access the business
layer. It's up to you to see what fits best your needs.

1. From the host form, you can set a reference to the business object to
each user control.

2. The host form can hold the business object and implement an interface to
return that business object. The user control can then get the host's
business object from the common interface.
ex: public interface IBusinessHost { public BusinessBase
tBusiness(); }

3. Each user control could initiate it's own Business object.
I have a few very complex forms that I divided into user controls. In the
host form's load event, I call a method called Bind on each user control. As
a parameter, I pass necessary references such as the business object.
Does the control access the business layer directly or does the control
get access via the hosting form? Would it be usefull at all to get the user control communicate only with the
host form? If a user control have to work with data, it should communicate
with the object managing data; that is, the business object.

Etienne

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com... All,

I have a windows form application. The form will host various user
controls
that will implement an interface so that was new controls can be added
later
without recompiling the hosting program.

The various controls will be displaying data that is stored in a SQL
database.

My question is what is the prefered way of having the controls access the
business layer that will in turn access the data layer? Does the control
access the business layer directly or does the control get access via the
hosting form? Any insight or reasons as to why one way is prefered would
be
great.
Thanks for the help!

Dan

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project...
0
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
5
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something...
8
by: mark.norgate | last post by:
I've run into a few problems trying to use generics for user controls (classes derived from UserControl). I'm using the Web Application model rather than the Web Site model. The first problem...
4
by: Mihai | last post by:
Hi ! I use VB.Net 2005. I created an inherited user control based on a previosly created user control.Everything is Ok . I can run this control with f5, everything is fine. When I close Visual...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.