XtraScheduler以编程方式创建约会 [英] XtraScheduler create appointment programmatically
问题描述
我(正在尝试)使用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);
但是似乎商店-即使我已经设置了映射等并且适配器拒绝实际添加新约会. 我想我只是做错了什么,可能我不能这样做? 只是为了确认,我实际上没有表单中的调度程序控件,也不想要一个.
我只是想为用户提供特定资源/日期范围的可能约会的列表,然后一旦用户选择了一个约会,实际上就将选择的约会保存了.
我建议您订阅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 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.
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();
}
这篇关于XtraScheduler以编程方式创建约会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!