XtraScheduler以编程方式创建约会

时间:2010-12-09 11:37:31

标签: c# .net devexpress appointment

我(尝试)使用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);

这很好 - 即。它给我回复了约会之间的约会..很棒..  但我实际上要做的是查询所有约会,以便我可以解决是否可以在特定日期时间添加新约会。

id喜欢能够做到

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

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

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

1 个答案:

答案 0 :(得分: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();
  }
相关问题