Bound Mode
- 5 minutes to read
This topic describes how to persist data in Bound Mode – in this mode the data is stored in a database.
To enable the scheduler to work in Bound Mode, bind the TcxSchedulerDBStorage component to the scheduler control using the TcxScheduler.Storage property.
Examples in this topic are based on the ExpressScheduler DBDemo that ships with this product. The tables that are used in this topic were created with the BDE toolset in the Paradox® format. Using resources, as shown in the examples, is optional. To learn how to persist data in a file system, refer to the Unbound Mode topic.
Binding a data source
Before you start to configure a connection to the data store, make sure that you’ve created the cxSchedulerTable.db and cxSchedulerResourcesTable.db tables using the following structure:
cxSchedulerTable.db
Field Name | Type | Size | Value Restriction Rule | |
---|---|---|---|---|
1 | ||||
2 | ||||
3 | 255 | NULL must be allowed | ||
4 | ||||
5 | ||||
6 |
or GUID | NULL must be allowed | ||
7 |
(Autoincrement) or GUID | |||
8 | NULL must be allowed | |||
9 | 255 | NULL must be allowed | ||
10 | 255 | NULL must be allowed | ||
11 | NULL must be allowed | |||
12 |
or GUID | |||
13 | ||||
14 | ||||
15 | NULL must be allowed | |||
16 | NULL must be allowed | |||
17 | NULL must be allowed | |||
18 |
or TBlobField | |||
19 | ||||
20 | NULL must be allowed | |||
21 | ||||
22 | ||||
23 | ||||
24 |
Note
The ID, GroupID and ParentID are related fields and must be of the same type. The ParentID field will only contain a value, if the current record represents an occurrence of the etCustom or etException type (see the TcxSchedulerEvent.EventType property) of the recurring user event.
Value restriction rule: since some fields can also store a custom occurrence’s value (the TcxSchedulerEvent.EventType is etCustom), these fields must be specified as nulls allowed.
By default, if a different value is not specified for a custom occurrence, the occurrence uses a value of its pattern. In this case, the NULL value is stored in the field.
cxSchedulerResourcesTable.db
Note the following:
If a user event will be shared between different resources then the ResourceID field’s type (the cxSchedulerTable dataset) should be TBlobField.
Grouping user events by resources in the Reminders window is only enabled (see the TcxSchedulerReminders.ReminderByResource property), if the user event’s ReminderResourcesData field is bound to the dataset field.
Using the Database Desktop utility, populate the cxSchedulerResourcesTable.db table with the records, as shown in the image below (in the example only the ResourceID and ResourceName fields are used):
Note
it is better to use the TcxSchedulerStorageResourceItems collection to work with resources because this collection allows read-write operations on the resources. Refer to the Unbound Mode topic to learn how to use the TcxSchedulerStorageResourceItems collection. When working with the resources table (as the cxSchedulerResourcesTable.db) the scheduler control’s interface only allows read operations on the resources. To perform write operations on the resources, use the resources dataset directly.
To set up a connection, do the following:
1.Drop two DataSource controls (located on the Data Access page) and two Table controls (located on the BDE page) onto a form from the Component Palette.
2.Using the Object Inspector, name one Table control as EventsTable and specify in the TTable.TableName property the path to the folder where the cxSchedulerTable.db table is stored. In this case, the path specified is a path relative to the working folder (where the current project is located). Select another Table control, name it ResourcesTable and specify the path to the cxSchedulerResourcesTable.db table.
3.Using the Object Inspector, name one DataSource control as Events and bind the EventsTable dataset to the Events data source via the TDataSource.DataSet property. Select another DataSource control, name it Resources and bind the ResourcesTable dataset to the Resources data source via the TDataSource.DataSet property.
4.Now, assign the Events data source to the TcxSchedulerDBStorage.DataSource property and the Resources data source to the TcxSchedulerDBStorageResources.DataSource property as shown in the image:
5.Bind the EventsTable dataset fields to the corresponding TcxSchedulerEvent‘s properties via the TcxSchedulerDBStorageFieldNames‘s properties:
Note
At least five fields are required to be defined and bound to the TcxSchedulerEvent‘s properties via the TcxSchedulerDBStorageFieldNames properties: TcxSchedulerDBStorageFieldNames.ID, TcxSchedulerDBStorageFieldNames.Start, TcxSchedulerDBStorageFieldNames.Finish, TcxSchedulerDBStorageFieldNames.EventType and TcxSchedulerDBStorageFieldNames.Options. Mapping requirements for other fields are domain dependent.
Do the same for the ResourcesTable dataset fields using the TcxSchedulerDBStorageResources.ResourceID and TcxSchedulerDBStorageResources.ResourceName properties (in this example only two fields are used):
Now the application is ready to run. An end-user can create any user events they want which will then be stored in the data store.
The cxSchedulerTable.db table is populated with the user events scheduled by the end-user:
The following example shows how to schedule the user event, which will be stored in the data store, programmatically:
// ...
with SchedulerDBStorage.CreateEvent do
begin
ResourceID := 1; // assign the newly created user event to the Lesli Gritts resource
Caption := 'Birthday'; // specify the subject
AllDayEvent := True; // this is the all-day event
Post; // synchronize with storage
end;
The image below shows an all-day event created under the Lesli Gritts resource when the code is being executed:
Note
the example shown assumes that the ID field in the data store is automatically incremented. If the type of the ID field is defined as GUID (for example, in a MS SQL Server database), then set the TcxSchedulerDBStorage.GenerateGUIDForID property to True to generate the user event‘s unique identifier (see the TcxSchedulerEvent.ID property) as GUID.