Free!  FoxPro to WPF screen converter
   Almost free!  One day of FREE VFP to WPF evaluation of your FoxPro app ONSITE
   Free!  Read the foreword to Les' new book (available here)...
Skip Navigation Links

StrataFrame simplifies WinForms database application development

Download and try this tool; it''ll pay for itself the first day you use it.


Les Pinter

Login or register to download source code

I've recently discovered StrataFrame from MicroFour Systems, and it's made my life a lot easier. Let's see if it can do the same for you.

You can download the IDE at StrataFrame.NET (not .com). The web page will take your information and send you a registration code that you can use to activate the product for 60 days. That should be enough; I can show you why you need it in 60 minutes.

The StrataFrame Philosophy

Trent Taylor, Chief Architect of StrataFrame, comes from the FoxPro world, a development tradition that made data access simple. StrataFrame evolved from his desire to make .NET just as easy, and it shows.

The result is that you spend very little time setting up data access, and almost none binding the data. Let's look at a sample Add/Edit/Delete screen to see why. (I don't call them CRUD screens because I looked the word up in the Dictionary of NonStandard English. Go ahead; it might surprise you.) To this end, all of the StrataFrame forms and controls contain code to detect and interact with business objects, which means "table classes".

A business object has one property for each column. Once the class is instantiated and loaded with data, Customer.Address means the value store in the Address column of the current record. (More on what constitutes the current record later.)

<RANT>Why are they called Business Objects? They're not objects, and they don't represent businesses. They should be called Table Classes, not Business Objects! But everyone now uses this silly terminology, so I suppose it has currency. Who gets to make these terms up and condemn us to using them for the rest of our careers?)</RANT>

In each form in your application, you'll call a method on the main business object for that form to load data from the appropriate table or tables. Each business object will have a method to load its data, and properties to expose the columns in each record. You can add calculated columns as new properties without adding them to database tables. Your textboxes and other controls are bound to the business object instances (not to databindings as you often see in .NET tutorials), and the binding is accomplished by simply entering the name of the column (property) of the business object to bind to. Easy enough? Onward through the fog...

Building your first application

After you install StrataFrame, you'll see that a StrataFrame menu pad has been added to your VS2008 IDE (Fig. 1):

StrataFrame menu pad
Fig. 1 - The StrataFrame menu pad

Start by creating a new project; you'll notice that StrataFrame Windows Application is now one of your selections (Fig. 2); select it and let it do its magic, which is mainly to add three references to the project and to create a main program called program.cs (appMain.vb if you use Visual Basic). I've chosen C#, but you can also choose Visual Basic. I put mine in a C:\StrataFrame directory and named it SFTest01:

The StrataFrame Project
Fig. 2 - The StrataFrame Project

Adding a Maintenance Form

StrataFrame has a template for the typical Add/Edit/Delete "Maintenance" form, so we'll add one. Right-click on the project and select Add, New Item, then select StrataFrame Maintenance Form from the list of available items, naming it frmCustomers before clicking the Add button (Fig. 3):

Adding a Maintenance form
Fig. 3 - Selecting the Maintenance form template

The resulting form has a toolbar built in to perform the principal functions (Fig. 4). You might want to set the strings assigned to the Title and DetailText properties of the form's GradientFormHeader1 object to "Customers" and "Customer Table Maintenance", respectively.:

StrataFrame maintenance form
Fig. 4 - The StrataFrame maintenance form

We also have to make a small change in program.cs (appMain.vb in Visual Basic) in order to display frmCustomers when you run the app. This startup program is automatically generated to run "Form1", the default form that was created when we created the StrataFrame project. To change it to run frmCustomers at startup, open program.cs and change line 132, the first executable line in the InitApplication method from

   e.Forms.Add(typeof(SFTest01.Form1));
to
   e.Forms.Add(typeof(SFTest01.frmCustomers));

Adding a Business Object

Next we'll need a table class (I mean a business object) to hold records from the Customers table. Right click on your project, select Add Item, and select StrataFrame Business Object (SF Business Object) from the StrataFrame components listed, naming it CustomerBO in the process (Fig. 5):

Creating a Business Object
Fig. 5 - Creating a business object

The CustomersBO Business Object is a class that's written by StrataFrame components. If you make changes, it gets rewritten. The initial version doesn't have much of anything in it, because we haven't yet told StrataFrame what table it comes from.

Configuring the business object

One of StrataFrame's most important tools is the Business Object Mapper, which generates the class code that makes dealing with table data easy. Click on the StrataFrame menu pad and select the first menu bar, Business Object Mapper (Fig. 6). The dialog shown in Fig. 7 will appear:

Selecting the Business Object Mapper
Fig. 6 - Selecting the Business Object Mapper


The Business Object Mapper
Fig. 7 - The Business Object Mapper

The Wizard will ask you where to store the MetaData - the table of table names and the names and properties of columns in the tables. You could store the metadata in SQL Server, but a physically separate store is more portable. Anyway, it has nothing to do with where you store your actual data - this is just StrataFrame information about your data and your application.

The choices are shown in Fig. 8, and the usual selection is the first one, Database Deployment Toolkit. You can also fill in your default connection string, the one that will be used to access the tables used by your business objects. Since we're using SQL Server, I've added the string here. If you don't supply a default here, it will simply ask you at run time. Actually, it will ask you anyway, but it gives it a head start.

Where to store the metadata
Fig. 8 - Where to store the metadata

The next step in the Wizard asks which database to use, and which table (Fig. 9). This is where you tell it that the data's coming from the Customers table in MS SQL Server. If you filled in the Default Connection String in the previous Wizard screen, it already knows where to find it; otherwise, it will ask here. The table's structure appears during the selection process (Fig. 10):

Selecting the database
Fig. 9 - Selecting the database


Selecting a table for the business object
Fig. 10 - Selecting a table for the business object

Once you've generated your business objects, you enter and write one little tiny data retrieval routine for each type of data that you need from that table. For example, my Customer table maintenance form will need records from the CUSTOMERS table, so I'll open CustomersBO.cs and add the following three lines of code in the #Region in the CustomersBO class code with the title "Data Retrieval Methods":

    public void FillCustomerTable()
    {
      FillDataTable("SELECT * FROM CUSTOMERS");
    }

Adding the business object to the form

After you build your project, press Ctrl+Alt+X to display the ToolBox. You'll see CustomersBO at the very top of the toolbox. Drag it and drop it on the frmCustomers form. It will join MaintenanceFormToolstrip1 in the tray below the form: (Fig. 11)

Dropping the Business Object on the form
Fig. 11 - Dropping the Business Object on the form

The only thing left to do is to call the FillCustomerTable() method; there are several places that this could go, but right after the InitializeComponent() call in the frmCustomers constructor is as good as any:

    public frmCustomers() {
     InitializeComponent();
     customersBO1.FillCustomerTable();
    }

Recompile the project, then reopen frmCustomers and add 9 labels and 11 textboxes from the StrataFrame Controls & Components toolbox, laying them out as is shown in Fig. 12, below. You'll notice that the BusinessObject for each textbox is automatically set to CustomersBO1. (This happens because you added an instance of CustomersBO to the form above, as was shown in Fig. 6.)

Adding label and textbox controls to the form
Fig. 12 - Adding label and textbox controls to the form

Almost done; next, open the Property Sheet by pressing F4, then for each TextBox, select the name of the BindingField from the dropdown list of the columns in the CustomersBO1 business object (Fig. 13). Note that the Business Object name CustomersBO1 is automatically supplied as you drop TextBoxes onto the form. I set the CustomerID textbox to ReadOnly as well. (The use of strings for the primary key of the Customers table in the NorthWind database was an unfortunate mistake that has poisoned the brains of countless novice developers; there's a better way - actually, two better ways - and you should NEVER do this. But this is a simple demo, so let it go...)

Setting the BindingField for each of the textbox controls
Fig. 13 - Setting the BindingField for each of the textbox controls

Running the form

Now, press F5 to run the form. Since it's the first time to run the app, StrataFrame walks you through the Database Connection Wizard, a set of three screens used to verify that the Default Connection String that you specified in the MetaData setup step at the very beginning is indeed the desired source of the data, as shown in Figures 14 - 16, below:

Verifying the data source
Fig. 14 - Verifying the data source


Selecting the Database
Fig. 15 - Selecting the Database


Saving your settings
Fig. 16 - Saving your settings

Finally, your Customers Maintenance Form will appear (Fig. 17). Try the various buttons: You'll notice that Delete throws an error; that's because all of the customers have orders, and the Northwind Database has a trigger prohibiting deleting a customer with outstanding orders. That's a job for the next article. But if you use one of your own tables, as I encourage you to do forthwith just to see that this actually is as easy as I say it is, you should be able to add, edit and delete records, as advertised.

The Customers maintenance form
Fig. 17 - The Customers maintenance form

That's all there is to it! It actually took me perhaps 10 minutes to build this form. I'd be happy to hear your experiences with one of your own tables. And there's a lot more that StrataFrame can help with, as we hope to demonstrate in the coming weeks and months.


Conclusion

StrataFrame isn't the only tool of this type: IdeaBlade DevForce and GenexUs also permit rapid application development and do a lot of the work for you. But GeneXus doesn't use a pure .NET code approach, and IdeaBlade is heavily invested in Entity-Framework, which is another level of complexity that you might want to avoid if you can do so. So for quick, simple, solid WinForms development for .NET, I like StrataFrame. Give it a try; you'll like it, too.

qqq


Copyright(C) Pinter Consulting, 2012Tel: +1 (650) 464-6924
Automated conversion between C# and VB by Visible C#/Visible VB from Tangible Software Solutions