TX Quote Gemerator - An Advanced Example

This sample progam shows how to use Text Control in office applications. The main task of an office application typically is to create documents from information taken from a set of databases. For instance, a quote is generated from a record in an address database and one or more records in an article database.

The program is built up in two steps, starting very simple with only a single address database, and adding more features later on.

The source code for this example is contained in the subfolders Step1 and Step2 of the following directories:

Used TX Text Control controls:

chap_desc>Relevant API links:

Step 1: Creating a Quote from a Database

When the program is started, it displays an address database in a data grid control.

The database is a simple XML file, which is displayed with just a few lines of ADO code:

[C#]
DataSet dsAddress = new DataSet ("address");
dsAddress.ReadXml("..\\..\\address.xml");
gridAddress.DataSource = dsAddress;
gridAddress.DataMember = "address_record";
[Visual Basic]
Dim DsAddress As New DataSet("address")
DsAddress.ReadXml("..\address.xml")
GridAddress.DataSource = DsAddress
GridAddress.DataMember = "address_record"
[Delphi]
dsAddress.ReadXml('address.xml');
gridAddress.DataSource := dsAddress;
gridAddress.DataMember := 'address_record';

Selecting the File/New Quote menu item takes the current record from the database and creates a document from it. This is done in the following way:

A form containing a Text Control is opened, and a stylesheet is loaded. A stylesheet is a file that serves as a template for the final document. It contains all text parts which are equal to all documents, for instance a phrase like "In reply to your inquiry and according to our general terms of business we are pleased to..", and placeholders for information that is to be inserted from a database, like Address, Date, and so forth. It also defines the font, font size, company logo, and layout, so that all files will have the same look.

Once the stylesheet has been loaded, the placeholders are updated from the database, so that they now contain the real address, name, customer number, and date.

The stylesheet can be edited with the Advanced menu.

Step 2: Adding Articles with a Table

Before you read everything about how it is programmed, you may want to run it and see what it does, so here is a short user's guide first.

The first thing we need to do in order to add article descriptions and pricing to our quotes from Step 1 is to add another database. We call it the article database, and display it on the main form beside the address database.

That's it for the main form. On the editor form, we now add a menu item which lets us insert items from the article data into a quote.

A list of articles is best displayed in a table, and Text Control offers all required table functions to let us insert product IDs, descriptions, and prices into the respective cells, as well as to perform calculations. We therefore add a table to the style sheet and adjust its column widths, text distances, and caption text so that later only the plain text needs to be filled in.

This is what the style sheet now looks like:

A new menu item has been added to the Advanced menu, which allows to insert a table. Also, a Format/Table menu item has been created which calls Text Control's table attribute dialog box, so that we can adjust the table grid lines and background shading. The table's column widths and tabs are adjusted in the ruler bar. Note that the 2 rightmost columns have decimal tabs, so that the currency values they will contain will be properly aligned at the decimal sign.

We are now ready to fill in text from the article database into the table. Have a look at the sample program's ArticleTable class, which shows how to use the various table, row, columns and cell collections and objects.

After the user has selected a product in the article database, the program performs these steps:

<< Previous