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.
The Application Generator uses the structure of your database to generate the code. There are some conventions to be followed though:
Once database schema has been created and normalised to your linking, code can be generated.
Following schema is used by GS SalesManager:
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.
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.
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.
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".
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
The lookup control allows you to search for existing County or invoke data entry module for County to add a new one!
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.
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()
{
base.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
If user clicks on "Save" button, following message box is shown.
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:
In following screen-shot, you can see that the user is given a read-only view of the invoice.
All the applications created with GillSoft Desktop Application Generator are capable of creating backups and restoring it. This comes in handy in following scenarios:
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.
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:
Every application can use any of the following methods to get license:
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:
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!
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: