[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.
Steps for Creating Employees
Form with Forms Designer
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.
Step 1: Create Application
Open Visual Studio 2005 and
create a new Windows Application
using ‘New Project Wizard’.
Step 2: Add References
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:
-
Open Solution Explorer and
right-click on ‘References’
tree node, an ‘Add
Reference’ dialog box will
appear.
-
Go to the ‘Browse’ tab and
browse to the folder
Northwind\Data\Persistence\bin,
where Northwind is the root
folder name of the generated
code.
-
Add references of 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.
-
Copy
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.
Step 3: Design Employees Form
Follow these steps to design a
form:
-
Open Windows Form ‘Form1’,
which will be generated with
the creation of new
application in Step 1 above.
-
Go to the toolbox, expand
TierDeveloper Win tab and
drag ‘EditFormManager’
control on the Form.
-
Rename ‘EditFormManager’ to
‘EmployeeEditFormManager’.
-
Click on the arrow appearing
on the top right corner of ‘EmployeeEditFormManager’.
A menu will appear
containing some tasks.
-
Click on ‘Configure Binding’
as shown in the figure
below.

Figure 3: Open Forms Designer
Menu Configuration
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.

Figure 4: Forms Designer Field
Binding Wizard
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.
-
Command Control Type:
Type of control you want to
create for your command.
-
Command Target: Three
types of targets are
supported in Forms Designer.
-
<Persistence Object>:
calls a method residing
in Persistence layer.
You will also have to
specify the method type,
name and parameters by
clicking the button
right next to ‘Target’
dropdown for this
option.
-
Form: Opens another Form
available in the
Application. We can also
pass parameters to this
Form by clicking the
button right next to
‘Target’ dropdown.
-
Clear Form Command:
Resets all the controls
available on the Form
-
Dependent Commands:
This option is used when you
want to trigger another
command(s) explicitly after
execution of this command.

Figure 5: Forms Designer with
Command and Link Binding
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.
Step 4: Form Designer
Event Handlers
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.
Employees Form GUI Code
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.

Figure 6: Code for Employees
Form created by the Forms
Designer
Conclusion
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.