Desktop Application Generator - Features Walkthrough

It is difficult to describe all the features of the Application Generator in one page, so we have created a small walk-through. On every page you will be able to see the various features explained in detail.

Database Schema

The Application Generator uses the structure of your database to generate the code. There are some conventions to be followed though:

  • Table names must begin with prefix tbl_ (this can be changed to use custom prefix or none at all)
  • All tables must have primary key column (only one column per table) of type GUID

Once database schema has been created and normalised to your linking, code can be generated.

Following schema is used by GS SalesManager:

GS SalesManager Database Schema

Generate Code

The code generator has been developed as a command line tool to make automation of task of the task easier.

The command line used to generate the initial code is as following:

C:\Dev\000-DevTools\CastleARCodeGen.exe -s:.\SQLEXPRESS -d:GSSalesManager -n:GSSalesManager -t:csproj -o:c:\dev\GSSalesManager -custommap:CustomMap.xml

You will get complete details of all the parameters in the help file accompanying the product. One parameter "-custommap" is a very useful feature which is described here.

The code generated is saved in the folder "c:\dev\GSSalesManager" (defined by -o parameter).

The generated code is a complete .Net WinForms application which can be compiled and used right-away for basic data entry. The application allows you to use Firebird or MS-SQL back-end right away. The "Select Configuration" dialog box allows you to have multiple databases / backends for the same application to work with.

Select Configuration

This comes in handy where same application may be used to deal with databases. For example, an accountant may want to have separate database for each client. This feature is not compulsory, you may change this behaviour so that application will always use one backend/database always.

Any number of configurations can be added.

Select Configuration

Following is the screenshot of the main screen of the application. You can see the ribbon menu with buttons. Each button opens up the module for the underlying table. You may add/remove buttons to this ribbon as required.

Main Screen

Sample Application In Action

As mentioned earlier, the sample application is ready for basic data entry.

Also please note that the layout of the screens will need some work to suit individual requirements.

In the example, we clicked on "City" button to invoke the data entry form for tbl_city. The search dialog is shown where you may search for existing city (more on customising search later), or add a new one. In this example, we clicked in "Add".

Data Entry Form For City

Please note that the screen already shows some data entry related messages. These are based on "not null" settings for the respective columns.

Two controls worth noting here are

  • Lookup control for many-to-one relation - County
  • Grid control for one-to-many relation - Addresses etc

The lookup control allows you to search for existing County or invoke data entry module for County to add a new one!

Data Entry Form For County

There is a lookup control for Country in this screen to allow searching / adding Country.

The grid control allows you to add rows for one-to-many related tables.

For example in the above data entry form for county, clicking on "Add" button for cities grid would invoke data entry form for City and user could add as many cities as needed.

The generated screens allow any depth of addition of records by invoking suitable data entry screens.

Business Rules

After generating the code, the application is in state to add / edit / delete records in the database. But this is not enough in most of the cases. The application may require more business rules to be implemented to make the application suitable for the customer.

It is as simple as overriding a method in the data objects and providing the requuired logic.

protected override void SetupValidationRules()
AddValidationRule(EntityProperties.InvoiceDetails, a => a.InvoiceDetails.Count != 0, "No invoice details provided.");
AddValidationRule(EntityProperties.DeliveryAddress, a =>
var res = a.invoiceTypeHelper.SaleInvoice.Equals(a.InvoiceType) && a.DeliveryAddress != null;
return res;
}, "Delivery address must be provided for Sale Invoice");

In the above code we have two rules

  • Invoice Details must be provided. An invoice cannot be saved unless there is atleast one invoice detail added to it.
  • If Invoice is a Sale Invoice, Delivery Address must be provided.

If user clicks on "Save" button, following message box is shown.

Invoice Header Business Rule Violation Message Box

The message about "Account not selected" was because underlying column (account_id in tbl_invoice_header) was marked as "not null".


Most of the times applications need some sort of security to restrict access to various aspects of the data. This feature is integral part of the framework.

In GS Sales Manager, following rules were required:

  • Manager role can access all invoices and edit any historical invoice
  • Receptionist role can create invoices but can edit invoices from only last 'n' days. The number 'n' is configurable (by Admin / Manager only). Any older invoices will be shown in read-only mode.

In following screen-shot, you can see that the user is given a read-only view of the invoice.

Invoice Header Read Only

Backup / Restore

All the applications created with GillSoft Desktop Application Generator are capable of creating backups and restoring it. This comes in handy in following scenarios:

  • Recovery from hardware failure
  • Migration from one database backend to another.


Finally, for easy and professional deployment, the Code Generator creates Wix files also to allow deployment of the application. All the files required for basic deployment are included in the MSI file. You can add any number of extra files too if needed.

Actually there are two MSI's created whenever you create installer. One is for 32 bit deployment and other for 64 bit. This is partuclarly required for Firebird which has separate drivers for 32 bit abd 64 bit platforms.

Licensing of Deployed Applications

Like all the commercial applications require protection from piracy, the applications created using the Code Generator has supports licensing mechanism too. This prevents applications from getting copied and used illegally.

The licenses created allow following restrictions:

  • Demo License: A time limited license which allows full access to all features. The user gets warning about expiry well before it actually happens.
  • Time Restricted License: The user does not see the "Demo" message but remaining behaviour is like Demo License.
  • Unrestricted License: A full license with no restrictions at all.

Every application can use any of the following methods to get license:

  • Online: This is handy when the user internet connectivity. We have web-service created on our site for this purpose.
  • Copy file from mail / storage media: If the user does not have internet connectivity, this is another method provided.

Supported Databases

The applications created with Code Generator can use following databases. We can modify the framework to add support for other major databases also.
List of supported databases is:

  • MS-SQL Server: Industry standard RDBMS. The applications are created and tested using MS-SQL Server Express (Provided free by Microsoft). This can come in handy where multiple copies of the application have to use same database.
  • MySQL: A free database provided my Oracle. It runs on variety of platforms like Windows and Linux.
  • Firebird: We test applications with Embedded version. This database is great tool when it comes to deploying applications that do not require full installation of SQL Server/MySQL but still want to enjoy benefits of an RDBMS.

Custom Map

In some cases if a column needs to be mapped to a "C# enum", custom map file can be used to control how some code is generated for the Data Access Layer.

See Sample Custom Map file.

Custom map file tells the code generator to create enums with values taken from the custom map file. This way your code becomes more readable and you do not have to deal with integer values for columns like status etc.

The following code was generated using the information from the sample custom map file for GS SalesManager

public enum InvoiceStatusEnum{[Description("None")]None,[Description("Paid (All payments received)")]Paid,[Description("Part Paid")]PartPaid,[Description("Outstanding")]Outstanding,[Description("Written-off")]WrittenOff,[Description("Marked As Paid")]MarkedAsPaid}

The custom map file is not limited to enums only. You can also use it to map some columns to your custom NHibernate IUserType implementations!

Other features

There are a few more features that are not big enough to require individual pages. Following is the list of those features along with their descriptions:

  • Auto-scaling of UI: The applications created by Code Generator have same size for the forms on every machine.
  • Auto-lockout: To improve security, if user leaves the application unattended, it locks out and can unlocked by implementing your custom logic.
  • Caching: To improve performance, we use caching. This reduces the hard-disk access. All the writes go to database immediately though, so that there is no loss of data.