http://www.evget.com/article/2012/12/17/18282.html
运用DXperience12.2创建甘特图日程管理应用
其它 | 作者:慧都控件网 | 2012-12-17 14:25:51 | 阅读 533次 评论 0
概述:本文介绍运用DXperience 12.2创建甘特图视图的日程管理应用程序。提供DXperience12.2更新信息和免费下载。
- 运用DXperience 12.2轻松创建Win8风格的Office应用
- 运用DXperience12.2创建甘特图日程管理应用
最新发布的DXperience 12.2提供了更加完整的用户界面控件。在上一篇中,我们创建了一个Win8界面风格的日程管理应用,今天我将为大家展示日程管理(Schedule)控件的甘特图视图(Gantt View)功能。
分层资源
Gantt View有一个支持分层资源的功能。为此,DXperience 12.2将Resources Tree 控件用分层的形式显示日程管理资源。在Visual Studio中打开设计器,新建Form1,选择XtraNavBar,并在工具栏中将它替换为ResourcesTree。
如图所示,点击Resources Tree的智能标签,就会看到它已经自动绑定到Scheduler Control表单中:
Resources Tree建在Tree List顶端时,支持多列。要定义这个属性,点击Smart Tag并运行设计器。
接下来需要一个 XtraTreeList集合的引用,右键单击Solution Explorer的项目然后点击Add Reference。
单击Start查看效果,如图所示,资源在左边以树形结构显示:
规定依赖关系
接下来在每个资源下创建一些命令:
然后右键单击其中一个:
我们看到,Create Dependency选项是灰色的。要启用它,我们需要传递命令ID,最简单的方式之一是从数据适配器中获取DB ID。由于我们的主关键字用的是 identity (auto-inc)列,所以可以用以下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
private
void
Form1_Load(object sender, EventArgs e) {
...
// Get the auto-inc value from SQL Server
appointmentsTableAdapter.Adapter.RowUpdated += appointmentsTableAdapter_RowUpdated;
}
private
int
insertedId;
private
void
appointmentsTableAdapter_RowUpdated(object sender, SqlRowUpdatedEventArgs e)
{
if
(e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert)
{
// Store the inserted ID so we can update the underlying appointment
// in schedulerStorage_AppointmentsInserted
insertedId = (
int
)e.Row[
"UniqueId"
];
}
}
Now assign the
new
id to the appointment object:
private
void
schedulerStorage_AppointmentsInserted(object sender, PersistentObjectsEventArgs e)
{
CommitTask();
// Set the auto-inc value from SQL Server within the XtraScheduler appointment
// this is needed, for instance, to create dependencies for newly inserted appointments
// othrwise the option will be disabled
schedulerStorage.SetAppointmentId((Appointment)e.Objects[0], insertedId);
}
|
在做了上述这些操作后,我们就可以创建新命令的依赖项了:
将依赖项与数据绑定
将命令和Resource绑定到数据源,现在我们需要绑定依赖项数据源。在设计器的Form1.cs,打开schedulerStorage的智能标签,从我们的数据集中对它进行分配:
验证字段映射:
保存更改
最后确保依赖项已经保存到数据库中,为此,我们将处理以下事件:AppointmentDependenciesChanged, AppointmentDependentciesDeleted 和 AppointmentDependenciesInserted。
以上三个事件都可以用下面的代码进行处理:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
private
void
schedulerStorage_AppointmentDependenciesChanged(object sender, PersistentObjectsEventArgs e)
{
CommitTaskDependency();
}
private
void
schedulerStorage_AppointmentDependenciesDeleted(object sender, PersistentObjectsEventArgs e)
{
CommitTaskDependency();
}
private
void
schedulerStorage_AppointmentDependenciesInserted(object sender, PersistentObjectsEventArgs e)
{
CommitTaskDependency();
}
private
void
CommitTaskDependency()
{
taskDependenciesTableAdapter.Update(dXProjectManagerDataSet);
}
|
最后,一个甘特图视图的日程管理应用就建好了: