473,796 Members | 2,520 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1935

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[] GetAllAvailable Items()
{
/* 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[] GetInvoiceNumbe rList()
{
/* 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 GetInvoiceNumbe rList() 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*@discussion s.microsoft.com > wrote in message
news:F9******** *************** ***********@mic rosoft.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
1947
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 that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
0
3939
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 like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
5
1999
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 like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
8
3191
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 I'm having is that the partial class signature in my projectDetails.ascx.cs file looks like this: public partial class ProjectDetailsControl<TEntryServiceProvider: UserControl, INamingContainer where TEntryServiceProvider : IEntryServiceProvider...
4
2002
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 Studio and a open it again and load my project I have the error: One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.