Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic moving appointments (Read 5116 times)
thierry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 3rd, 2010
moving appointments
Jun 3rd, 2010 at 3:38pm
Print Post  
Hi,

I am a new user of the Scheduling Library.

I use the library as a ResourceView and when I move an appointment I wish that this one moves on a particular segment of hour (between the 10 am and the 2 pm for example).
I do it with no problem at all on a resizeStart or ResizeEnd in ItemModifying but not when the appointment is entirely moved (Drag and Drop).

I have tried alot of the setting and searched the forum but I could not get any solution.

Best Regards,
Thierry
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: moving appointments
Reply #1 - Jun 3rd, 2010 at 4:08pm
Print Post  
Hi,

Can you post the code of your ItemModifying event handler?

Regards,
Meppy
  
Back to top
 
IP Logged
 
thierry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 3rd, 2010
Re: moving appointments
Reply #2 - Jun 3rd, 2010 at 4:27pm
Print Post  
Hi,

This is the code.

void calendar1_ItemModifying(object sender, ItemModifyConfirmEventArgs e) {
TimeSpan _hourbegin = new TimeSpan(14, 0, 0);
TimeSpan _hourend = new TimeSpan(10, 00, 00);
// this one is good !
if (e.ResizeStart) {
if (e.Item.StartTime.Date < e.NewStartTime.Date) {
TimeSpan substractValue = TimeSpan.FromHours(e.NewStartTime.Hour) + TimeSpan.FromMinutes(e.NewStartTime.Minute) + TimeSpan.FromSeconds(e.NewStartTime.Second);
DateTime newDate = e.NewStartTime.Subtract(substractValue);
e.NewStartTime = newDate + _hourbegin;
}
if (e.Item.StartTime.Date > e.NewStartTime.Date) {
e.NewStartTime = e.NewStartTime + _hourbegin;
}
}

// this one is not !
if (!e.ResizeStart && !e.ResizeEnd) {
if (e.Item.StartTime.Date < e.NewStartTime.Date) {
TimeSpan itemDuration = e.Item.EndTime - e.Item.StartTime;
e.NewStartTime = e.NewStartTime + _hourbegin;
e.NewEndTime = e.NewStartTime + itemDuration;
}
}
}

Best Regards,
Thierry
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: moving appointments
Reply #3 - Jun 4th, 2010 at 6:20am
Print Post  
Hi,

Can you try the following code and see if it suits your needs:

Code
Select All
TimeSpan start = new TimeSpan(10, 00, 00);
TimeSpan end = new TimeSpan(14, 0, 0);

if (!e.ResizeEnd)
{
      // Moving or resizing start
      e.Confirm = (e.NewStartTime.TimeOfDay >= start && e.NewStartTime.TimeOfDay <= end);
}
else
{
      // Resizing end
      e.Confirm = (e.NewEndTime.TimeOfDay >= start && e.NewEndTime.TimeOfDay <= end);
} 



The code checks if the start and end time of the item are in the valid range and if not - rejects the current operation.

Regards,
Meppy
  
Back to top
 
IP Logged
 
thierry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 3rd, 2010
Re: moving appointments
Reply #4 - Jun 4th, 2010 at 7:47am
Print Post  
Hi,

Thanks for the response, I think your code is a part of what I am searching for.

Unfortunately as the resourceview is parametrized on:

[code]

calendar1.ResourceViewSettings.BottomTimelineSettings.Unit = TimeUnit.Day;
calendar1.ResourceViewSettings.BottomTimelineSettings.UnitCount = 1;
[/code]

When I move an item this one is moved systematically on midnight and so your code is always at false.

How could I solve this problem.

Best regards,
Thierry
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: moving appointments
Reply #5 - Jun 4th, 2010 at 8:23am
Print Post  
Yes, items snap to days by default. In order to disable day snapping, use the following line:

Code
Select All
calendar1.ResourceViewSettings.SnapUnit = TimeUnit.Second; 


Let me know if this works.

Regards,
Meppy
  
Back to top
 
IP Logged
 
thierry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 3rd, 2010
Re: moving appointments
Reply #6 - Jun 4th, 2010 at 11:09am
Print Post  
Thanks for the response,

A last point, how could I magnetize the movement of an appointment, when it goes into an interval of + or - three hours of the hour which it have to stick (as you make it with calendar1. ResourceViewSettings. SnapUnit = TimeUnit. Day when you come to place the appointment at midnight on a drag and drop operation).

Best regards,
Thierry
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: moving appointments
Reply #7 - Jun 4th, 2010 at 12:00pm
Print Post  
I managed to achieve the desired custom snapping but the implementation turned out rather long.

Code
Select All
private void calendar1_ItemModifying(object sender, ItemModifyConfirmEventArgs e)
{
	bool moving = !e.ResizeStart && !e.ResizeEnd;

	if (!modifying)
	{
		initialItemStartTime = e.Item.StartTime;
		initialItemEndTime = e.Item.EndTime;
		offset = TimeSpan.Zero;

		previousStartTime = e.Item.StartTime;
		previousEndTime = e.Item.EndTime;
	}

	if (moving)
		previousStartTime = e.Item.StartTime;

	if (e.ResizeStart || moving)
		offset += e.NewStartTime - previousStartTime;
	else
		offset += e.NewEndTime - previousEndTime;
	previousStartTime = e.NewStartTime;
	previousEndTime = e.NewEndTime;

	TimeSpan snapAt = new TimeSpan(12, 0, 0); // Snap at 12:00
	TimeSpan snapTollerance = new TimeSpan(3, 0, 0); // Snap when the items are within 3 hours of the snap time

	TimeSpan displace = TimeSpan.Zero;
	if (e.ResizeStart || moving)
	{
		DateTime expectedStartTime = initialItemStartTime + offset;

		// Align the time
		if (expectedStartTime.TimeOfDay >= snapAt - snapTollerance &&
			expectedStartTime.TimeOfDay <= snapAt + snapTollerance)
		{
			displace = expectedStartTime.Date + snapAt - expectedStartTime;
			expectedStartTime = expectedStartTime.Date + snapAt;
		}

		e.NewStartTime = expectedStartTime;
	}

	if (moving)
	{
		DateTime expectedEndTime = initialItemEndTime + offset + displace;
		e.NewEndTime = expectedEndTime;
	}

	if (e.ResizeEnd)
	{
		DateTime expectedEndTime = initialItemEndTime + offset;

		// Align the time
		if (expectedEndTime.TimeOfDay >= snapAt - snapTollerance &&
			expectedEndTime.TimeOfDay <= snapAt + snapTollerance)
			expectedEndTime = expectedEndTime.Date + snapAt;

		e.NewEndTime = expectedEndTime;
	}

	modifying = true;
}

private void calendar1_ItemModified(object sender, ItemModifiedEventArgs e)
{
	modifying = false;
}

private bool modifying = false;
private DateTime initialItemStartTime;
private DateTime initialItemEndTime;
private DateTime previousStartTime;
private DateTime previousEndTime;
private TimeSpan offset; 


Note, that now we are also handling the ItemModified event as well and have declared several member variables.

Let me know if this works.

Regards,
Meppy
  
Back to top
 
IP Logged
 
thierry
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 11
Joined: Jun 3rd, 2010
Re: moving appointments
Reply #8 - Jun 4th, 2010 at 12:29pm
Print Post  
Thanks for your response.

That's exactly what I want.
I really appreciate your support and time spent to help me.

Best regards,
Thierry
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint