This is a migrated thread and some comments may be shown as answers.

Auto-disabling Past Time Slots

6 Answers 259 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Jeremy Murtishaw
Top achievements
Rank 1
Jeremy Murtishaw asked on 26 Apr 2010, 12:30 AM
Hello,

Is there a way to automatically disable any past days and time slots in the RadScheduler? I have a function that does the calculation, but it seems unreliable. Sometimes if the user performs certain actions, the past time slots will become active again. I'll post my code below.

if (this.radScheduler.SchedulerElement.ViewElement is SchedulerDayViewElement) 
            { 
                SchedulerDayViewElement dayView = this.radScheduler.SchedulerElement.ViewElement as SchedulerDayViewElement; 
 
                if (dayView != null
                { 
                    foreach (RadElement element in dayView.DataAreaElement.Table.Children) 
                    { 
 
                        SchedulerCellElement cell = element as SchedulerCellElement; 
                        if (cell != null
                        { 
                            if (cell.Date <= DateTime.Now) 
                            { 
                                cell.Enabled = false
                                cell.CanFocus = false
                            } 
                            else 
                            { 
                                cell.Enabled = true
                                cell.CanFocus = true
                            } 
                        } 
                    } 
                } 
            } 
            else if (this.radScheduler.SchedulerElement.ViewElement is SchedulerMonthViewElement) 
            { 
                SchedulerMonthViewElement monthView = this.radScheduler.SchedulerElement.ViewElement as SchedulerMonthViewElement; 
                foreach (RadElement element in monthView.MonthViewAreaElement.Children) 
                { 
                    if (element is MonthCellElement) 
                    { 
 
                        MonthCellElement e = element as MonthCellElement; 
                        if (e.Date < DateTime.Now.Date) 
                        { 
                            element.Enabled = false
                        } 
                    } 
                } 
            } 


Thanks!
Jeremy

6 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 29 Apr 2010, 10:14 AM
Hi Jeremy Murtishaw,

Thank you for contacting us.

Disabling cells is not supported in RadScheduler for WinForms, because we need to recreate the view when a specific property is changed. For example when you change the range factor of the ruler, the view needs to be recreated, because the timeslot count would be different.

We would like to get more details on your scenario, if possible, in order to see whether this is a good feature to have. What is the purpose of disabling the old scheduler cells? Do you need to cancel the selection of these cells or create a new appointment for a past time slot?

Looking forward to your reply.
 
Sincerely yours,
Boyko Markov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jeremy Murtishaw
Top achievements
Rank 1
answered on 29 Apr 2010, 06:42 PM
Hi Boyko,

The purpose of this functionality is to paint the past time-slots gray and make them un-selectable for the creation of appointments. I think this makes the tool more intuitive for the user since they can see the current time where the grayed-out cells meet the colored ones.

Colin
0
Boyko Markov
Telerik team
answered on 30 Apr 2010, 05:49 PM
Hello Jeremy Murtishaw,

I agree that this would be a great feature to be built in RadScheduler, something like locked cells or locked  dates. Unfortunately, we cannot implement this feature as a workaround. As I see from your previous post, you get the cells collection depending on the scheduler's current view. You can also do this by using the GetCells method of the SchedulerUIHelper:

List<SchedulerCellElement> cells = SchedulerUIHelper.GetCells(this.radScheduler);

If you want to cancel the creation of an Appointment for a previous date, you can do the following:

1. Subscribe to the AppointmentEditDialogShowing event of RadScheduler.
2. In the event handler, set the AppointmentEditDialog property to null in case you need to cancel showing the default dialog that allows you to create a new appointment or edit an existing one.

void radScheduler_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
 {
     List<SchedulerCellElement> cells = SchedulerUIHelper.GetSelectedCells(this.radScheduler);
     if (cells.Count > 0)
     {
         if (cells[0].Date < DateTime.Now)
         {
             e.AppointmentEditDialog = null;
             return;
         }
         else
         {
             e.AppointmentEditDialog = new EditAppointmentDialog(e.Appointment, this.radScheduler);
             return;
         }
     }
     else
     {
         e.AppointmentEditDialog = new EditAppointmentDialog(e.Appointment, this.radScheduler);
     }
 }

I hope this helps.



Regards,
Boyko Markov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Erdem
Top achievements
Rank 1
answered on 25 Apr 2012, 01:56 AM
How can we do this ? where we can add this code ? I want to auto-disable past day please help :)
0
Ivan Todorov
Telerik team
answered on 27 Apr 2012, 12:44 PM
Hi Erdem,

Thank you for writing.

Before answering your question, I would like to mention that I noticed that you have only downloaded the Telerik ASP.NET AJAX suite. Please note that this forum concerns the WinForms version of RadScheduler. If your question is about the ASP.NET AJAX version of RadScheduler, please ask it in the corresponding forums.

If your question concerns the WinForms version of RadScheduler, then you can use the following code to achieve the scenario discussed in this thread:
public Form1()
{
    InitializeComponent();
    this.radScheduler1.CellFormatting += new EventHandler<Telerik.WinControls.UI.SchedulerCellEventArgs>(radScheduler1_CellFormatting);
    this.radScheduler1.AppointmentDropping += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentDropping);
    this.radScheduler1.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentMoving);
    this.radScheduler1.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(radScheduler1_AppointmentResizing);
    this.radScheduler1.Appointments.CollectionChanging += new Telerik.WinControls.Data.NotifyCollectionChangingEventHandler(Appointments_CollectionChanging);
    this.radScheduler1.ActiveView = new SchedulerDayView(DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1));
}
 
void radScheduler1_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
{
    if (e.NewStartDate < DateTime.Today)
    {
        e.Cancel = true;
    }
}
 
void Appointments_CollectionChanging(object sender, Telerik.WinControls.Data.NotifyCollectionChangingEventArgs e)
{
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add &&
        ((Appointment)e.NewItems[0]).Start < DateTime.Today)
    {
        e.Cancel = true;
    }
}
 
void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
{
    if (e.NewDate < DateTime.Today)
    {
        e.Cancel = true;
    }
}
 
void radScheduler1_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
{
    if (e.NewDate < DateTime.Today)
    {
        e.Cancel = true;
    }
}
 
void radScheduler1_CellFormatting(object sender, Telerik.WinControls.UI.SchedulerCellEventArgs e)
{
    if (e.CellElement.Date < DateTime.Today)
    {
        e.CellElement.Enabled = false;
    }
}

The above code is the full code behind of a form with a RadScheduler instance added in the designer, so you should be able to easily incorporate it in your project.

I hope this will help you. Feel free to ask if you have any additional questions.

All the best,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Erdem
Top achievements
Rank 1
answered on 28 Apr 2012, 10:42 AM
Thank you very much for your reply and thank you very much telerik team ...
Tags
Scheduler and Reminder
Asked by
Jeremy Murtishaw
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Jeremy Murtishaw
Top achievements
Rank 1
Erdem
Top achievements
Rank 1
Ivan Todorov
Telerik team
Share this question
or