search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Split/Linked Events

Asked by Phil Stratford
13 years ago.
Hi there, I'm sure what I need to do is possible with the current feature set of DayPilot Calendar but I can't quite figure it out and if anyone can offer any advice it'd be great. What I need is EITHER a way of having multiple events which are linked, so that moving one event in time moves them all, but each individual event can be moved between resources (columns) independently. OR a way of splitting an event so that within the event are sub-events which occur at different times and have different durations. For example, in a hospital scenario: There might be a main event from 9am to 3pm, with a title of 'Mr Smith - Appendectomy'. Sub events might be: 9am-9:30am 'Registration' - Reception 9:30am-10:30am 'Pre-exam' - Ward 3 10:30am-11am 'Anaesthesia' - Pre-Med Room 11am-1pm 'Surgery' - Theatre 3 1pm - 2pm 'Recovery' - Ward 2 2pm - 3pm 'Discharge' - Reception While the times of the events would all move together, obviously any sub-event could have its location changed without affecting the others. And ideally you could drag a sub-event to extend it or shorten it and the linked events would move to accommodate this so that they were always contiguous. I've already created a 'Parent Event ID' field in my table to be used for linking events using a common ID, but implementing this in DayPilot is tough! Thanks, Phil
Comment posted by Random Dude with a Big Red Nose and a Tophat. (now with rubber gloves)
13 years ago.
I hear ya dude, I have to do exactly the same thing in a factory-context. But i'm using a lot of code behind and I'm getting where i wanna go!
You can do it too mate!

Random Dude with a Big Red Nose and a Tophat. (now with rubber gloves)
Comment posted by Random Dude that now loves Chicken
13 years ago.
Nevermind, I have to do it using the Scheduler so it's slightly different.
Random Dude that now loves Chicken
Comment posted by Dan Letecky
13 years ago.

You could use a set of events linked using a special DB field, e.g. "master_id".

Whenever an event is moved, you will have to find the other events using the master_id and move all of them by the same offset.

This doesn't provide 100% feedback during drag&drop (it will outline just one event) but the result should be fine.



EventMove event handler:

DayPilotCalendar1_EventMove(object sender, EventMoveEventArgs e) {
 string master = e.Tag["master_id"];
 TimeSpan offset = e.NewStart - e.OldStart;
  // "SELECT * FROM [events] WHERE [master_id] = @master"
 DataTable dt = findEventsByMasterId(master);

  foreach (DataRow dr in dt.Rows) {
    string id = (string) dr["id"];
    DateTime start = (DateTime) dr["start"];
    DateTime end = (DateTime) dr["end"];

    // "UPDATE [events] SET [start] = @start, [end] = @end WHERE [id] = @id"
    moveEvent(id, start.Add(offset), end.Add(offset));

Comment posted by Phil Stratford
13 years ago.
Thanks very much for the feedback. I achieved this basically using your suggestion, Dan. In the database every event now has a 'Parent Event ID' field. If the value is 0 then the even is a Parent. Otherwise this value is the ID of the parent event. I then added a couple of lines to the 'event move' event code so that when a parent event is moved not only is its start and end time updated in the database, but so are the start and end times of any events where the 'Parent Event ID' field is equal to the event id of the parent. If that makes sense! Thanks again.
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.