Author: Iqbal Khan
TierDeveloper is an object relational mapping code generator for .NET. It lets you map business and data objects to your relational tables, embed SQL and stored procedure calls in them, and generate fully working code in C# or VB.NET. This lets you achieve in days what would otherwise take you weeks and months. And, it also improves your code quality by generating standardized code for the entire application and even across projects.
Traditionally, TierDeveloper has focused on generating business and data objects for your application and you have had to develop GUI by hand and call the objects from it. The reason was that GUI by nature is very customized and therefore not a good candidate for simple code generation. However, .NET 2.0 now provides a Custom Controls Framework that makes it practical for rapid GUI development. TierDeveloper uses this framework to let you quickly design and develop your GUI and connect it with the generated business and data objects.
TierDeveloper has developed powerful "GUI designers" to cover different areas of your application's GUI. They are:
Each designer allows you to design and develop different parts of your application and together they allow you to develop your application in record time. All the designers are available for ASP.NET and Windows Forms applications.
In addition to the designers, TierDeveloper also contains an App GUI Wizard that lets you quickly specify different forms, list pages, ad hoc search pages, and app menu structure. It then generates GUI code based on the Custom Control Framework so you can easily customize this GUI from the different designers provided by TierDeveloper inside Visual Studio 2005.
In this article, I am going to describe how to use the most important designer, namely the Forms Designer. You'll see how easy it is to develop a real life Form for your application and have it automatically call all the appropriate business and data objects.
We will use Northwind
database in our example to develop an Employees Form. This form is used to load, edit, and save an employee. You can develop both ASP.NET and Windows based forms with this Forms Designer. Below is a picture:
Please note the following special things in the form above:
Below is the same Employees Form for an ASP.NET application.
For the Form displayed above, three business and data objects are used. They are Employees
, EmployeesFactory
, and TDBindingList<Employees>
. They are described below:
[Serializable]
public class Employees {
// Some of the private data members
// ...
public Employees () { }
// Properties for Employee object
public String EmployeeId { get; set; }
public String FirstName { get; set; }
public int LastName { get; set; } //... rest of data member properties
// relationship properties
public Employees Supervisor { get; set; }
public TDBindingList<Employees> Subordinates { get; set; }
}
public class EmployeesFactory {
public EmployeesFactory () { }
// Methods for EmployeeFactory object
public void Load (ref Employees emp, int depth) { /* ... */ }
public void Insert (ref Employees emp, int depth) { /* ... */ }
public void Update (ref Employees emp, int depth) { /* ... */ }
public void Delete (ref Employees emp, int depth) { /* ... */ }
// n-1 relationship methods
public void LoadSupervisor (ref Employees emp, int depth) { /* ... */ }
public void LoadSubordinates (ref Employees emp, int depth) { /* ... */ }
}
The above code includes a domain object called Employees
that keeps all the data of an Employee and also its related Employees (supervisor and subordinates). The second object is a persistence class called EmployeesFactory
that contains all the code related to the database access. The third class TDBindingList<Employees>
is a Generic class provided by TierDeveloper Framework and therefore not described further here.
The above classes need to be called from the GUI in order to implement the functionality.
Now that you know what your form should look like and how does the underlying business and data objects look, you're ready to actually design this form. You'll see how easy it is to design this form. Here is step by step instructions on how to go about this.
Open Visual Studio 2005 and create a new Windows Application using 'New Project Wizard'.
Before we start working with Forms Designer, we need to add Domain and Persistence objects assembly references to the project. Code in these assemblies is generated by TierDeveloper. To add references, do the following:
Northwind.Businsess.Domain.dll
, Northwind.Data.Persistence.dll
and EnterpriseNonServicedLibEval.dll
, which you will find in the said folder. Also, browse to the folder where TierDeveloper 6.0 or later is installed and go to bin folder, add reference to TierDeveloper form designer assembly which would be TierDeveloper.Windows.Forms.dll
for Windows Forms applications and TierDeveloper.Web.dll
for Web/ASP.NET applications.EnterpriseNonServicedLibEval.dll.config
and Northwind.Data.Persistence.dll.config
file into your application's output directory. These files contain configuration information that will be used by application to accomplish certain tasks. For example, Northwind.Data.Persistence.dll.config
file holds information of databases used in the Persistence layer. Keeping database information in a config file makes our application more flexible. In case of change of database server, we will not have to modify and re-compile the code. Application will work fine with mere modification in the config file.Follow these steps to design a form:
When you do the above, an 'Object Selection Wizard' will appear. 'Object Selection Wizard' helps in selecting domain and persistence objects for the form. Select Employees
object from Northwind.Business.Domain
namespace and EmployeesFactory
object from Northwind.Data.Persistence
namespace through the wizard. Now select the fields, which you want to map against UI controls, from the 'Available Fields'. Click 'Add' button to add the selected fields to the 'Mapped fields'. Select appropriate UI controls for the mapped fields.
Next, add the commands by pressing 'Add' button on 'Commands tab' as shown below. Specify the 'Control Type', 'Target' and 'Dependent' for the command. Here is a brief description of these options.
Press OK to close this dialog. Now Forms Designer creates all the controls which we have mapped in Fields and Commands tab in a top to bottom sequence. Rearrange the controls to make Form more attractive. Note that don't rename any control's id created by Forms Designer otherwise you will loose its binding.
Forms Designer also exposes some events that allow you to integrate your own custom code. In this example, we have implemented two events. One is OnExceptionOccured
, which is used to show any raised exception. Another is OnCommandExecuted
that notifies the user about completion of a particular command.
Once your Employees Form is created with Forms Designer, its code is based on the standard .NET 2.0 Custom Controls Framework. TierDeveloper provides various Custom Controls of its own based on this framework and they are shown below.
As you have seen, TierDeveloper makes it very simple to quickly design and develop rich GUI and connect the underlying business and data objects to it. This is yet another step toward simplifying and speeding up your development time and improving your code quality. Remember, the less code you have to write by hand, the faster your projects are completed and the better is your code quality.
Author: Iqbal Khan works for Alachisoft, a leading software company providing .NET and Java distributed caching, O/R Mapping and SharePoint Storage Optimization solutions. You can reach him at iqbal@alachisoft.com.
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.