XtraScheduler以编程方式创建约会

我(尝试)使用DevExpress XtraScheduler – (不要问为什么)创建约会而不实际使用我试图这样做的forms的调度程序控件…

conn = new SqlConnection("connectionstring"); conn.Open(); int ResourceId = 18; AppointmentsAdapter = new SqlDataAdapter(); AppointmentsAdapter.SelectCommand = new SqlCommand("spGetAppointmentsForResourceById", conn); AppointmentsAdapter.SelectCommand.CommandType = CommandType.StoredProcedure; AppointmentsAdapter.SelectCommand.Parameters.AddWithValue("@ResourceID", ResourceID); DataSet ds = new DataSet(); AppointmentsAdapter.Fill(ds); SchedulerStorage store = new SchedulerStorage(); store.Appointments.DataSource = ds.Tables[0]; store.Appointments.Mappings.Start = "StartDate"; store.Appointments.Mappings.End = "EndDate"; //etc etc store.Appointments.CustomFieldMappings.Add(new AppointmentCustomFieldMapping("fkcase", "fkcase")); //.. etc etc AppointmentBaseCollection appts = store.GetAppointments(dateFrom, dateTo); 

这工作正常 – 即。 它返回日期之间的约会..很棒..但我实际上要做的是查询所有约会,以便我可以解决如果可以在特定日期时间添加新的约会。

我希望能做到

 AppointmentsAdapter.InsertCommand = new SqlCommand("spInsertAppointment", conn); AppointmentsAdapter.InsertCommand.Parameters.Add("@Type", SqlDbType.Int); AppointmentsAdapter.InsertCommand.Parameters.Add("@StartDate", SqlDbType.DateTime); AppointmentsAdapter.InsertCommand.Parameters.Add("@EndDate", SqlDbType.DateTime); //...etc etc 

然后呢

  Appointment apt = store.CreateAppointment(DevExpress.XtraScheduler.AppointmentType.Normal); apt.Start = DateTime.Today.AddHours(8); apt.Duration = TimeSpan.FromHours(1); apt.Subject = "Subject"; apt.Description = "Description"; store.Appointments.Add(apt); 

但它似乎是商店 – 即使我已经设置了映射等,并且适配器拒绝实际添加新约会。 我想我只是做错了什么,但也许我不能这样做? 只是为了确认,我实际上并没有表单中的调度程序控件,也不想要一个。

我只是试图给用户一个特定资源/日期范围的可能约会列表,然后一旦用户选择了一个,实际上保存所选择的约会。

我建议你订阅SchedulerStorage的AppointmentsChanged,AppointmentsInserted和AppointmentsDeleted事件,为所有这些事件实现一个处理程序,最后在这个事件处理程序中调用dataAdapter的Update方法:

 void schedulerStorage_AppointmentsChanged(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e) { // the code below to apply changes. myTableAdapter.Update(this.myDBDataSet); myDBDataSet.AcceptChanges(); }