In my previous post we did a little refactoring of our class hierarchy and added the required behaviours to our business objects. In this post we will go ahead and hook up a UI to our hierarchy.
In this case we will create a windows forms application only for our project, so add a Windows Forms Application Project (from the eXpressApp Framework projects collection) to the solution. We'll call this project DSM (short for Dental Surgery Manager) and the solution should now look as follows:-

There's a few things we have to do to hook our business objects up to the winforms application, but before we go ahead and do that, there's a small administrative change you have to make if you are using Sql Server Express (as I am). By default the XAF application will persist objects to a database, named the same as the solution, on the local instance Sql Server. If you are running Sql Server Express you have to tell XAF that you want to use this instance for persistence. To do this, build the solution to allow the model designer to work; then, in the DSM.Win project, select WinApplication.cs and select "View Designer" from the context menu. The designer below should now be showing:-

Now select the Sql Connection icon in the top right corner and, in the properties dialog, edit the connection string property so that (local) now reads .\sqlexpress. Whilst we are here in the designer, we'll delete the security icons too, we'll come back and look at security in later posts but, for now, we'll run without it.
Having done this we can now go ahead and prepare our hierarchy of business objects for inclusion in the XAF project. To do that the first thing we have to do is to decorate the Surgery class with the DefaultClassOptions attribute. This will tell XAF that it is required to add the class to the container on the left hand side of the form, add the class to the "New" menu and create CRUD forms for it and its dependant classes.
The next thing we have to do is to make the XAF project aware of our business objects, to do that we add a reference to our business objects project from the DSM.Module and DSM.Win projects. Having done this we now select the Module.cs file from the DSM.Module and select "View Designer" from the context menu. As you can see from the image below, the XAF project is now aware of our business objects:-

Now the last thing we have to do is to tell XAF that we want it to use those objects, we do this be selecting the objects and pressing the SPACE key, the object will embolden to signify that it will be used in the solution, like so:-
Now we can hit F5 and test out our UI:-

Go ahead and play around with the UI, create a Surgery and add Patients and Dentists etc. The layout of the form fields is a little erratic but we'll sort that out in future posts, but for now, satisfy yourself that the UI works as advertised.
That wraps it up for this post where we took an existing business object hierarchy and hooked it up to an XAF winforms application. In the next post we'll look at customising the UI, hope to see you then.
Technorati tags:
DevExpress,
XAF,
XPO