Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's Tips
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Summary
Great tips for .NET developers
Description

Smart Client Architecture
A lot of the reading I've done in the past concerning Smart Client applications is a bit daunting. Most of the articles looked too complicated and it's easy to miss the underlying concept. Basically, all you need to do is simply use the Assembly.LoadFrom method from the System.Reflection class to load your DLLs. It's as simple as that.

Ideally, you should architect your application so that there is a small, lightweight executable installed on the client machine. This executable need not contain much in the way of core logic. Ideally, it just references the DLLs it needs, which reside out on a remote Web server and which supply all of the necessary application logic. We use an Outlook-style sidebar in our application to launch all our modules and they are all loaded through Reflection. The DLLs will only be downloaded from the server if they are newer versions, otherwise the version already on the client will be the one loaded.

If you haven't architected your application that way to begin with, you could add something to your app to do it after the fact (how you implement this is up to you ... you could have a special form that requires the user to start the download process, or you could do it automatically every time you start the app (which could take awhile, depending on how many DLLs you have). But, anyway, here's basically all you need to get you thinking:
// First, an ArrayList containing the filename of all your DLLs. 
// This can be a class, as shown below, or simply a property
public class AssembliesList : ArrayList
{
	public AssembliesList()
	{
		this.Add("MyMainControl.DLL");
		this.Add("MyBusiness.DLL");
		this.Add("SomeOtherOnes.DLL");
	}
}

// Next, the method that actually does the work:
private void DownloadAssemblies()
{
	string URL = GetTheURLWhereYourAssembliesAreLocated();
	string DLL;
	AssembliesList oList = new AssembliesList();

	for (int i = 0; i < oList.Count; i++)
	{
		DLL = oList[i].ToString().Trim();
		try
		{
			System.Reflection.Assembly o =
				System.Reflection.Assembly.LoadFrom(URL + DLL);
		}
		catch (System.Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}
}

from a solution provided by Bonnie Berent in Message #1069797

SELECT DISTINCT
Finally, .NET 2.0 contains a new method to simulate SELECT DISTINCT functionality. It's the new .ToTable() method of a DataView.

Example: Say you have data that contains names and addresses of your customers. You'd like to have a DataTable that you can use for a DataSource for a City ComboBox, but you obviously don't want to display duplicate city names.
DataTable dtUniqueCities = MyDataSet.Tables["Customers"].DefaultView.ToTable(true, "City"); 
That will create a datatable with 1 column (City), and a unique list of the cities.

If you need to use more than one column to determine uniqueness (say, City and Zip), you'd do it like this:
DataTable dtUniqueCities = MyDataSet.Tables["Customers"].DefaultView.ToTable(true, _
 new string[] {"City", "Zipcode"}); 

from a solution provided by Kevin Goff in Message #1144433

Validating Web Form data
Validation Controls on a web form can be used to validate user input (for example, that a correct date format was input), but what if you need more complicated validation ... for example, to validate that user input against something in the backend database?
// Since the _TextChanged() method does not return true or false 
// and it does not stop the process of the page, 
// one needs to create a property to set On/Off. 

private bool EquipmentVerified
{
   get
   {
      object o = ViewState["EquipmentVerified"];
      if ( o == null )
         return false;
      return ( bool ) o;
   }
   set { ViewState["EquipmentVerified"] = value; }
}

// In the TextChanged event set this bool.

txtEquipment_TextChanged
{
   EquipmentVerified = //whether or not it is verified.
}

// In the button click, check this bool

btnSubmit_Click
if ( EquipmentVerified )
{
   //the value is valid.
   //run insert or whatever.
}

from a solution provided by Dmitry Litvak in Message #1035690

Stop TextBox Validation
There are many ways to handle validation in a TextBox and one of them is to put code in the Validating event handler of the TextBox. However, you may notice that if you have, say, a Cancel button on your Form and the user clicks on it, the Validating event still fires, requiring valid input into that TextBox even though the user wishes to cancel his edits.

What to do? Simple ... set the CausesValidation property on the Cancel button to false.

from a solution provided by Gary Wynne in Message #1094666

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers