问题的提出
无意中,看了看甘特图的绘制。
在示例中,我们看到一些其它的类型中,没有的信息:
见上图,
普通的Scheduler Control 中,只是一个简单的二维图形。
但甘特图,相对而言,多出了一些信息。
那么这些信息,在哪里,是我们首先需要关心的问题。
双击一个Appointment ,看到弹出的框中,也多出一条信息:
那么,这条信息来自于哪里呢?
经过前面的总结,我们发现,SchedulerControl 的重点是其绑定的schedulerStorage控件。
this.schedulerStorage1.AppointmentDependencies.DataSource = this.taskDependenciesBindingSource;
甘特图由几部分信息构成:
1. 资源resource。这是甘特图的基础。资源有几种可能。一般我们在Project上看到的,是工作任务。用来描述工作任务的前后衔接关系。
前提这,这些任务所需要的资源,有依赖性。如人员的工作时间。
2. 任务:Appointment
注意,我们看到,比其它的相对简单的任务设置,多出了两个字段,特别是,PercentComplete,这个项,与Appointment的编辑对话框里的信息,是对应的。
3.任务的 依赖关系的描述。devExprss中,采用的是自相关表。
好了,现在来看,信息,已经足够了。
我们来分析,如何组合这些信息,使界面能够正确显示。
具体过程
this.schedulerStorage1.AppointmentDependencies.Mappings.DependentId = "Dependent";
this.schedulerStorage1.AppointmentDependencies.Mappings.ParentId = "Parent";
this.schedulerStorage1.AppointmentDependencies.Mappings.Type = "Type";
this.schedulerStorage1.Appointments.CommitIdToDataSource = false;//为了解决更新时,ID的问题。
this.schedulerStorage1.Appointments.DataSource = this.tasksBindingSource;
this.schedulerStorage1.Appointments.Mappings.AllDay = "AllDay";
this.schedulerStorage1.Appointments.Mappings.AppointmentId = "Id";
this.schedulerStorage1.Appointments.Mappings.Description = "Description";
this.schedulerStorage1.Appointments.Mappings.End = "EndTime";
this.schedulerStorage1.Appointments.Mappings.Label = "Label";
this.schedulerStorage1.Appointments.Mappings.Location = "Location";
this.schedulerStorage1.Appointments.Mappings.PercentComplete = "PercentComplete"; //普通的甘特图中,没有此项。
this.schedulerStorage1.Appointments.Mappings.RecurrenceInfo = "RecurrenceInfo";
this.schedulerStorage1.Appointments.Mappings.ReminderInfo = "ReminderInfo";
this.schedulerStorage1.Appointments.Mappings.ResourceId = "ResourceId";
this.schedulerStorage1.Appointments.Mappings.Start = "StartTime";
this.schedulerStorage1.Appointments.Mappings.Subject = "Subject";
this.schedulerStorage1.Appointments.Mappings.Type = "EventType";
this.schedulerStorage1.Resources.CustomFieldMappings.Add(new DevExpress.XtraScheduler.ResourceCustomFieldMapping("DaysPlanned", "DaysPlanned"));
this.schedulerStorage1.Resources.DataSource = this.resourcesBindingSource;
this.schedulerStorage1.Resources.Mappings.Caption = "Description";
this.schedulerStorage1.Resources.Mappings.Id = "Id";
this.schedulerStorage1.Resources.Mappings.ParentId = "ParentId";
this.schedulerStorage1.AppointmentsInserted += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentsInserted);
this.schedulerStorage1.AppointmentsChanged += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentsChanged);
this.schedulerStorage1.AppointmentsDeleted += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentsDeleted);
this.schedulerStorage1.AppointmentDependenciesInserted += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentDependenciesInserted);
this.schedulerStorage1.AppointmentDependenciesChanged += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentDependenciesChanged);
this.schedulerStorage1.AppointmentDependenciesDeleted += new DevExpress.XtraScheduler.PersistentObjectsEventHandler(this.schedulerStorage1_AppointmentDependenciesDeleted);
//
this.tasksTableAdapter.Adapter.RowUpdated += new System.Data.OleDb.OleDbRowUpdatedEventHandler(tasksTableAdapter_RowUpdated);
this.taskDependenciesTableAdapter.Adapter.RowUpdated += new System.Data.OleDb.OleDbRowUpdatedEventHandler(taskDependenciesTableAdapter_RowUpdated);
this.resourcesTableAdapter.Adapter.RowUpdated += new System.Data.OleDb.OleDbRowUpdatedEventHandler(resourcesTableAdapter_RowUpdated);
private void tasksTableAdapter_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e) {
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
id = 0;
using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", tasksTableAdapter.Connection)) {
id = (int)cmd.ExecuteScalar();
}
e.Row["Id"] = id;
}
}
int id2 = 0;
private void taskDependenciesTableAdapter_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e) {
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
id2 = 0;
using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", taskDependenciesTableAdapter.Connection)) {
id2 = (int)cmd.ExecuteScalar();
}
e.Row["Id"] = id2;
}
}
int id3 = 0;
private void resourcesTableAdapter_RowUpdated(object sender, System.Data.OleDb.OleDbRowUpdatedEventArgs e) {
if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
id3 = 0;
using (OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", resourcesTableAdapter.Connection)) {
id3 = (int)cmd.ExecuteScalar();
}
e.Row["Id"] = id3;
}
}