At DevExpress, we believe 3rd party tools and components should help developers become more productive, and our goal is to enable developers to get their projects’ up and running as quickly as possible. We are committed to our customers, as demonstrated by our free online support, and we partner with our users to build the stunning, quality software they envision. To that end, in our latest release DXperience 12.1, we have created a series of project templates that automatically deliver a visually appealing starter application that can then be expanded into a full application to meet your specific business needs. This white paper will discuss the basic principles needed in order to take the starter project template to a fully working application.
Any application deals primarily with the following notions dealing with data:
1. Presentation – how to display data
2. Persistence and Shaping – how to manipulate and save data
Applications generally take persisted data, run business rules, and ultimately present information to end users. This obviously runs in reverse as well: users change information, the system runs business rules, and the data is persisted. While the provided project templates lean more to the Data Presentation side of your application, we also have some exciting tooling to assist in the persistence and shaping categories as well. Let’s use the Windows Forms Outlook Inspired Application Template as an example.
DevExpress is in the business of building tools that help our users create stunning applications for presenting data. In our latest efforts to simplify the process we have created specialized templates that showcase some common application scenarios. A recurring application requirement is the concept of scheduling. Our Outlook Inspired Application Template tackles that exact scenario. Most modern applications include the concept of
scheduling. Examples range from CRM applications used to manage sales leads to scheduling appointments at a doctor’s office. This particular project template will provide the necessary guidance to get this portion of your larger application up and running. Running the Outlook Inspired application after creating the project yields a ready-made application that simply needs the data layers in order to be a complete application. Notice that we have enabled (at the UI level) the common functionality required for a fully-functioning scheduling type application.
In this example we will be creating a task management system that uses the scheduler control to manage tasks. The process of hooking these tools to a database has been greatly improved in our DXperience 12.1. Additionally, the controls themselves have a number of built-in wizards and dialog boxes designed to assist in the binding process. With the scheduler control there are two key elements to consider: Appointments and Resources. The concept of appointments in our scenario will be mapped to Tasks. This is a natural way of thinking about tasks since they have both a scheduled time and duration. The
Resources being scheduled are, in fact, the persons carrying out the tasks. Additionally, people will have a set of tasks they actually manage. This relationship is easy to visualize in a relational database:
Assuming we have these tables ready in advance, it is time to work directly with the data.
Persistence and Shaping
Mapping to a database has been greatly simplified in DXperience 12.1 with the addition of our new ORM Data Model Wizard. This wizard is easily instantiated by adding a new ORM Data Model Wizard component into the project by selecting Project and Add New Item.
This tool will walk us through the necessary steps to create the appropriate model based upon our existing database. The wizard will ask a series of intuitive questions that will culminate in a software mapping to the database using our proven XPO database mapping technology. XPO automatically deals with the hassle of persisting data to the database. In addition to simplified persistence, the new XPO designer enables you to quickly and easily shape data as well. The first example of this is in the concept of Value Converter’s. A great example of this is the way images are stored in a database. Images generally are persisted as a series of bits in a table column. Unfortunately a byte array is not entirely useful in the actual application. A value converter, in this instance, takes the corresponding bits and converts them in to an Image object. Using a value converter is as simple as selecting the corresponding field and selecting the ImageValueConverter from the drop down box. If there are special conversions needed, you as the developer can write a custom converter and use it as well.
The second example of data shaping can be found in aliased fields. Sometimes the application needs to treat a set of columns as a single field. This is especially true when one considers binding scenarios. In this case, it would be more useful to create a full name caption rather than having both the First Name and the Last Name. All you need to do in order to enable this scenario is right click on the corresponding entity (Person in this case) and add a Persistent Alias. Doing so allows the invocation of our powerful Expression Editor. This Editor is easily accessible through the properties window of the newly created Persistent Alias. This tool allows for the creation of new fields based off of the combination of any field, function, operation, and constant. Indeed this is data shaping at its best.
Tying it all Together
Now that data persistence and shaping has been handled, it’s time to bind everything together. There is a special collection control called XPCollection that is found in the DevExpress Data section in the control toolbox. Dropping this onto the form allows the developer to select the XPO entity which was defined earlier in the Data Wizard. In this case we will need two – one for the Task Entity and the other for the Person entity. Once these collections are dropped onto the form, the developer can choose the corresponding entity by setting the ObjectClassInfo property from the drop down box. Additionally, the developer can instruct the collection object regarding its behavior during certain events. One event in particular that needs to be handled (at least for the Tasks collection) is how to behave when a Task is removed from the collection. In our case we will have the Task deleted from the database as soon as it is removed from the collection. This can be accomplished by setting the DeleteObjectOnRemove property to true in the properties window of the XPCollection control. Once these two collections have been placed on the form and appropriately set up, the developer can use the smart tag on the scheduler control to set the Appointments and Resources binding to map the corresponding collections as the main bindings. As soon as this is set, a dialog box will appear to further assist in mapping the entity properties to the scheduler properties. This dialog box is again a commentary on how focused we are in assisting each developer use our tools effectively. In other words, we have taken great care in guiding each user through the process of mapping to data quickly and effectively. Once these bindings and mappings are all set up the application is pretty much done. We now have a fully working application that displays, manages, and persists data.
Now you have seen how easy it is to get started building frequently requested applications using our tooling. This paper demonstrates how the new project templates in DXperience 12.1simplifythe most important aspects of development: namely data presentation, shaping, and persistence. Additionally our dialogs and wizards are designed to streamline the experience when it comes to gluing these all important aspects of software development.