开发者

XtraScheduler create appointment programmatically

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.Ad开发者_开发知识库dWithValue("@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();
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜