1

我正在(尝试)使用 DevExpress XtraScheduler 来 - (不要问为什么)在没有实际使用调度程序控件的情况下创建约会,我试图这样做......

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);

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

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

4

1 回答 1

2

我建议您订阅 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();
  }
于 2010-12-16T19:10:31.387 回答