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

how block out work hours for INDIVIDUAL RESOURCES

7 Answers 119 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 23 Jun 2008, 01:21 PM
I'm asking about the "resource view" of the calendar ("groupby").

Let's say Dr Jones is the 1st column, Dr Smith the 2nd and Dr Leroy the 3rd.  If Dr Jones only works from 3pm to 5pm how do I gray out the "off-times" for HIM ONLY (his column only)?

I store all the work hours for the people in a seperate table.

Also, how do I customize the TITLE of the column?  For example change "Dr Jones" to "Dr Jones MD"?

7 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 24 Jun 2008, 03:25 PM
Hello Robert,

We have replied in the support ticket which you started about this case, but we will post the answer here in case someone else needs this functionality.

You can handle the AppointmentInsert and AppointmentUpdate events to check for the current resource and if the appointment overlaps a specified time. If both conditions are met, the event is cancelled. You can use Custom Attributes to hold the information on which date and time that person is unavailable. Please, consider the following example:

Protected Sub RadScheduler1_AppointmentInsert(ByVal sender As ObjectByVal e As Telerik.Web.UI.SchedulerCancelEventArgs)  
    If e.Appointment.Resources.GetResourceByType("Person").Text = "Dr Jones" Then 
        Dim dt1 As DateTime = DateTime.Parse("2008/06/23 10:00")  
        Dim dt2 As DateTime = DateTime.Parse("2008/06/23 16:00")  
        If DoDateRangesOverlap(e.Appointment.Start, e.Appointment.[End], dt1, dt2) Then 
            Response.Write("That person is unavailable on June 23, 2008 from 10 am to 4 pm.")  
            e.Cancel = True 
        End If 
    End If 
End Sub 
 
Protected Sub RadScheduler1_AppointmentUpdate(ByVal sender As ObjectByVal e As Telerik.Web.UI.AppointmentUpdateEventArgs)  
    If e.ModifiedAppointment.Resources.GetResourceByType("Person").Text = "Dr Jones" Then 
        Dim dt1 As DateTime = DateTime.Parse("2008/06/23 10:00")  
        Dim dt2 As DateTime = DateTime.Parse("2008/06/23 16:00")  
        If DoDateRangesOverlap(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End], dt1, dt2) Then 
            Response.Write("That person is unavailable on June 23, 2008 from 10 am to 4 pm.")  
            e.Cancel = True 
        End If 
    End If 
End Sub 
Private Function DoDateRangesOverlap(ByVal startDateRange1 As DateTime, ByVal endDateRange1 As DateTime, ByVal startDateRange2 As DateTime, ByVal endDateRange2 As DateTime) As Boolean 
    If ((startDateRange1 < endDateRange2) AndAlso (startDateRange1 >= startDateRange2)) OrElse ((endDateRange1 <= endDateRange2) AndAlso (endDateRange1 > startDateRange2)) Then 
        Return True 
    Else 
        Return False 
    End If 
End Function 
 

The strings: "2008/06/23 10:00" and "2008/06/23 16:00" can be fetched from custom attributes fields. 

In case you need to gray out certain time frame for a specific resource, you can use the following:
handle the TimeSlotCreate event and find the resource for each TimeSlot by index. Here is a code sample:
Protected Sub RadScheduler1_TimeSlotCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.TimeSlotCreatedEventArgs)  
    Dim indexParts As String() = e.TimeSlot.Index.Split(":"C)  
    Dim resourceIndex As Integer = Integer.Parse(indexParts(0))  
    Dim resources As New List(Of Resource)(RadScheduler1.Resources.GetResourcesByType("Room"))  
    Dim res As Resource = resources(resourceIndex)  
 
    Dim dt1 As DateTime = DateTime.Parse("2008/06/23 10:00")  
    Dim dt2 As DateTime = DateTime.Parse("2008/06/23 16:00")  
    If res.Text = "Dr Jones" Then 
        If DoDateRangesOverlap(e.TimeSlot.Start, e.TimeSlot.[End], dt1, dt2) Then 
            e.TimeSlot.CssClass = "UnavailableCssStyle" 
        End If 
    End If 
End Sub 
Private Function DoDateRangesOverlap(ByVal startDateRange1 As DateTime, ByVal endDateRange1 As DateTime, ByVal startDateRange2 As DateTime, ByVal endDateRange2 As DateTime) As Boolean 
    If ((startDateRange1 < endDateRange2) AndAlso (startDateRange1 >= startDateRange2)) OrElse ((endDateRange1 <= endDateRange2) AndAlso (endDateRange1 > startDateRange2)) Then 
        Return True 
    Else 
        Return False 
    End If 
End Function 
 
 

<head runat="server">  
    <title>Untitled Page</title> 
    <style type="text/css">  
        .UnavailableCssStyle  
        {  
            background: gray !important;  
        }  
    </style> 
</head> 



Cheers,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Philip
Top achievements
Rank 1
answered on 27 Mar 2016, 10:59 AM
Can this code be converted to c# for me this is exaclty what I need to be able to do as well thakns
0
Nencho
Telerik team
answered on 30 Mar 2016, 02:58 PM
Hello Philip,

I would advise you to use the Telerik Code Converted:

http://converter.telerik.com/

Regards,
Nencho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Philip
Top achievements
Rank 1
answered on 31 Mar 2016, 09:50 AM
I did so but for some reason its applying the style to every resource not just the one resource.
0
Nencho
Telerik team
answered on 05 Apr 2016, 06:25 AM
Hello Philip,

Probably this behavior is related with the Start and End date ranges fir the appointments in question in your custom implementation, because, as I can see the application of the custom CssClass  for the coloring responsibleis base on the Dates' ranges.

if (DoDateRangesOverlap(e.TimeSlot.Start, e.TimeSlot.End, dt1, dt2))
            {
                e.TimeSlot.CssClass = "UnavailableCssStyle";
            }

I would suggest you to place a breakpoint in the TimeSlotCreated method and pin down the reason for the experienced behavior.

Regards,
Nencho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Philip
Top achievements
Rank 1
answered on 11 Apr 2016, 10:40 AM

To anyone else strugling with this secneraio this is how I done it. Probally a neater way but by far the best and easiest way i have managed it.

 

01..Disabled {
02.          background: silver !important;
03.          cursor: not-allowed;
04.      }
05. 
06.      .UnavailableCssStyle {
07.          background-color: orange !important;
08.          cursor: not-allowed;
09.      }
10. 
11.      .HolidayCssStyle {
12.          background-color: white !important;
13.          color: black;
14.          cursor: not-allowed;
15.      }
16. 
17.      .SickDayStyle {
18.          background-color: rebeccapurple !important;
19.          cursor: not-allowed;
20.      }
21. 
22.      .DayOfCssStyle {
23.          background-color: white !important;
24.          color: black;
25.          cursor: not-allowed;
26.      }

01.protected void apertureAppointments_TimeSlotCreated(object sender, TimeSlotCreatedEventArgs e)
02.      {
03.          int i = 0;
04.          bool isFound = false;
05.          List<tblApertureNetShiftPattern> _list = new List<tblApertureNetShiftPattern>();
06.          _list = _dal.getHolidays();
07.          List<Resource> resources = new List<Resource>(apertureAppointments.Resources.GetResourcesByType("Managers"));
08.          Resource res = resources[5];
09. 
10.          foreach (tblApertureNetShiftPattern sp in _list)
11.          {
12.              if (_list.Count > 1)
13.                  i++;
14.              else
15.                  i = 0;
16. 
17.              DateTime? dt1 = _list[i].startdate;
18.              DateTime? dt2 = _list[i].endDate;
19.              if (res.Text == "Adam Adair" && e.TimeSlot.Start == dt1 && e.TimeSlot.Resource.Text == "Adam Adair")
20.              {
21.                  isFound = true;
22.                  if (DoDateRangesOverlap(e.TimeSlot.Start, e.TimeSlot.End, dt1, dt2) && isFound == true)
23.                  {
24.                      Label temperatureLabel = new Label();
25. 
26.                      if (sp.appointmentType == Constants.shiftDayoff)
27.                      {
28.                          e.TimeSlot.CssClass = "DayOfCssStyle";
29. 
30.                          temperatureLabel.CssClass = "DayOfCssStyle";
31.                      }
32.                      else if (sp.appointmentType == Constants.shiftHoliday)
33.                      {
34.                          e.TimeSlot.CssClass = "HolidayCssStyle";
35.                          temperatureLabel.CssClass = "HolidayCssStyle";
36.                      }
37.                      else if (sp.appointmentType == Constants.shiftStat)
38.                      {
39.                          e.TimeSlot.CssClass = "statCssStyle";
40.                          temperatureLabel.CssClass = "statCssStyle";
41.                      }
42.                      else if (sp.appointmentType == Constants.shiftsickDay)
43.                      {
44.                          e.TimeSlot.CssClass = "SickDayStyle";
45.                          temperatureLabel.CssClass = "SickDayStyle";
46.                      }
47.                      temperatureLabel.Text = sp.Description;
48. 
49.                      Image imageControl = new Image();
50. 
51.                      imageControl.ImageUrl = @"~\images\aperturenet\Calendar\resources\holidays.png";
52. 
53.                      temperatureLabel.BackColor = System.Drawing.Color.Orange;
54. 
55.                      dt1 = null;
56.                      dt2 = null;
57.                      isFound = false;
58.                      e.TimeSlot.Control.Controls.AddAt(1, temperatureLabel);
59.                      e.TimeSlot.Control.Controls.AddAt(2, imageControl);
60.                  }
61.              }
62.          }
63.      }

The key part I have been racking my brians over the last week or so is this little gem

 

& e.TimeSlot.Resource.Text == "Adam Adair"

Unless you have that in your if statement it would do it for all resources !.

0
Nencho
Telerik team
answered on 14 Apr 2016, 06:45 AM
Hello Philip,

Thank you for sharing your implementation with the community!

Regards,
Nencho
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Scheduler
Asked by
Robert
Top achievements
Rank 1
Answers by
Peter
Telerik team
Philip
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or