XtraScheduler 以编程方式创建约会

发布于 2024-10-06 11:34:12 字数 1942 浏览 3 评论 0原文

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

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

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

I am (trying) to use the DevExpress XtraScheduler to - (don't ask why) to create an appointment without actually using the scheduler control in the form
i have attempted to do that like this...

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

this is working fine - ie. it returns me the appointments between the dates.. great..
but what i am actually trying to do is query all the appointments so that i can work out if a new one can be added at a particular datetime.

id like to be able to do

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

and then do

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

but it appears that the store - even though I have set up the mappings etc and the adapter refuses to actually add the new appointment.
I imagine I am just doing something wrong, buit maybe I cannot do it this way?
just to confirm, I don't actually have a scheduler control in the form, and dont want one.

I am just trying to give the user a list of possible appointments for a particular resource/daterange and then once the user has picked one, actually save the picked appointment away.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烏雲後面有陽光 2024-10-13 11:34:12

我建议您订阅 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();
  }

I suggest that you subscribe to the AppointmentsChanged, AppointmentsInserted and AppointmentsDeleted events of the SchedulerStorage, implement a single handler for all these events and finally call the dataAdapter's Update method in this event handler:

void schedulerStorage_AppointmentsChanged(object sender, DevExpress.XtraScheduler.PersistentObjectsEventArgs e) {
            // the code below to apply changes.
            myTableAdapter.Update(this.myDBDataSet);
            myDBDataSet.AcceptChanges();
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文