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

Example of how to use an AppointmentComparer

10 Answers 158 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Greg Mercer
Top achievements
Rank 1
Greg Mercer asked on 02 May 2010, 11:50 PM
Hi,

Is there any example code setup to show how to use an AppointmentComparer?

I've tried setting one up, but it never seems to get called.

I'm using a RadScheduler with WebService binding, would that have any impact in why it doesn't seem to be working?

In the Page_Init method I have the following code:

RadScheduler1.AppointmentComparer = new AppointmentComparer(); 

And I have an AppointmentComparer.cs file with the following code:

public class AppointmentComparer : IComparer<Appointment> 
    #region Constructors 
    public AppointmentComparer() 
    { 
    } 
    #endregion 
 
    int System.Collections.Generic.IComparer<Telerik.Web.UI.Appointment>.Compare(Appointment first, Appointment second)  
    { 

But the breakpoint in the Compare method never seems to be reached.

Thanks very much for all your help,
Greg


10 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 05 May 2010, 01:24 PM
Hello Greg,

The appointment sorting is a bit different when using web services. The sorting actually happens on the client, so we need to override the default compare method. This is an instance method and takes the appointment to compare to as an argument.

For example, you can sort appointments alphabetically:

// Place the script block immediately after the ScriptManager on the page
Telerik.Web.UI.SchedulerAppointment.prototype.compare = function(otherAppointment)
{
    var subject = this.get_subject();
    var otherSubject = otherAppointment.get_subject();
  
    if (otherAppointment == null)
        returnValue = 1;
    else if (subject == otherSubject)
        returnValue = 0;
    else if (subject < otherSubject)
        returnValue = -1;
    else
        returnValue = 1;
  
    return returnValue;
}

Our documentation is indeed lacking such example. We'll take care to fix this.

I hope this helps.

All the best,
Tsvetomir Tsonev
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
Allen
Top achievements
Rank 1
answered on 21 May 2012, 03:52 PM
I need to sort by subjects:  Availability on the left and Prefered Availability on the right.  Please refer to the screen shot.
Here is my code:

<%

 

@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!

 

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

 

 

html xmlns="http://www.w3.org/1999/xhtml">

<

 

 

head runat="server">

 

<title></title>

 

<telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />

</

 

 

head>

<

 

 

body>

 

<form id="form1" runat="server">

 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">

 

<Scripts>

<%

 

--Needed for JavaScript IntelliSense in VS2010--%>

<%

 

--For VS2008 replace RadScriptManager with ScriptManager--%>

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />

 

<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />

 

</Scripts>

 

</telerik:RadScriptManager>

 

<script type="text/javascript">

 

//Put your JavaScript code here.

.rsAdvancedEdit

{

top: 10px !important;

left: 10px !important;

width: 30px;

}

Telerik.Web.UI.SchedulerAppointment.prototype.compare =

 

function(otherAppointment)

{

 

var subject = this.get_subject();

 

var otherSubject = otherAppointment.get_subject();

 

if (otherAppointment == null)

returnValue = 1;

 

else if (subject == otherSubject)

returnValue = 0;

 

else if (subject < otherSubject)

returnValue = -1;

 

else

returnValue = 1;

 

return returnValue;

}

 

</script>

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

 

</telerik:RadAjaxManager>

 

<div>

 

</div>

 

<telerik:RadScheduler Height="100%" Width="100%" ID="RadScheduler2"

 

runat="server" DataEndField="END_TIME"

 

DataKeyField="ID" DataSourceID="SqlDataSource1" DataStartField="START_TIME"

 

DataSubjectField="SUBJECT" DayEndTime="23:59:59" RowHeight="16px" SelectedView="WeekView"

 

WorkDayEndTime="8.00:00:00" WorkDayStartTime="00:00:00"

 

AllowDelete="False"

 

NumberOfHoveredRows="1" SelectedDate="2012-05-07"

 

EnableExactTimeRendering="True" DataRecurrenceField="RECURRENCERULE"

 

DataRecurrenceParentKeyField="RECURRENCEPARENTID">

 

<AdvancedForm Width="60%" Modal="True" />

 

<ResourceTypes>

 

<telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="USERID"

 

KeyField="ID" Name="Users" TextField="USERNAME" />

 

</ResourceTypes>

 

<TimelineView UserSelectable="False" />

 

<WeekView DayEndTime="23:59:59" />

 

<MonthView UserSelectable="False" />

 

</telerik:RadScheduler>

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

 

ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

 

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

 

SelectCommand="SELECT &quot;ID&quot;, &quot;SUBJECT&quot;, &quot;START_TIME&quot;, &quot;END_TIME&quot;, &quot;USERID&quot;, &quot;RECURRENCERULE&quot;, &quot;RECURRENCEPARENTID&quot; FROM &quot;AVAILABILITY_TEST&quot;"

 

DeleteCommand="DELETE FROM &quot;AVAILABILITY_TEST&quot; WHERE &quot;ID&quot; = :ID"

 

InsertCommand="INSERT INTO &quot;AVAILABILITY_TEST&quot; (&quot;ID&quot;, &quot;SUBJECT&quot;, &quot;START_TIME&quot;, &quot;END_TIME&quot;, &quot;USERID&quot;, &quot;RECURRENCERULE&quot;, &quot;RECURRENCEPARENTID&quot;) VALUES (:ID, :SUBJECT, :START_TIME, :END_TIME, :USERID, :RECURRENCERULE, :RECURRENCEPARENTID)"

 

UpdateCommand="UPDATE &quot;AVAILABILITY_TEST&quot; SET &quot;SUBJECT&quot; = :SUBJECT, &quot;START_TIME&quot; = :START_TIME, &quot;END_TIME&quot; = :END_TIME, &quot;USERID&quot; = :USERID, &quot;RECURRENCERULE&quot; = :RECURRENCERULE, &quot;RECURRENCEPARENTID&quot; = :RECURRENCEPARENTID WHERE &quot;ID&quot; = :ID">

 

<DeleteParameters>

 

<asp:Parameter Name="ID" Type="Decimal" />

 

</DeleteParameters>

 

<InsertParameters>

 

<asp:Parameter Name="ID" Type="Decimal" />

 

<asp:Parameter Name="SUBJECT" Type="String" />

 

<asp:Parameter Name="START_TIME" Type="DateTime" />

 

<asp:Parameter Name="END_TIME" Type="DateTime" />

 

<asp:Parameter Name="USERID" Type="Decimal" />

 

<asp:Parameter Name="RECURRENCERULE" Type="String" />

 

<asp:Parameter Name="RECURRENCEPARENTID" Type="Decimal" />

 

</InsertParameters>

 

<UpdateParameters>

 

<asp:Parameter Name="SUBJECT" Type="String" />

 

<asp:Parameter Name="START_TIME" Type="DateTime" />

 

<asp:Parameter Name="END_TIME" Type="DateTime" />

 

<asp:Parameter Name="USERID" Type="Decimal" />

 

<asp:Parameter Name="RECURRENCERULE" Type="String" />

 

<asp:Parameter Name="RECURRENCEPARENTID" Type="Decimal" />

 

<asp:Parameter Name="ID" Type="Decimal" />

 

</UpdateParameters>

 

</asp:SqlDataSource>

 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:SqlDataSource

 

ID="SqlDataSource2" runat="server"

 

ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

 

ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"

 

SelectCommand="SELECT &quot;ID&quot;, &quot;USERNAME&quot; FROM &quot;AVAILABILITY_TEST_USERS&quot;">

 

</asp:SqlDataSource>

 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

 

<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

 

<telerik:RadButton ID="save_Rbtn" runat="server" Text="Save"

 

BackColor="#FF3300" CssClass="RadButton" Font-Bold="True" ForeColor="#FF3300">

 

</telerik:RadButton>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

 

<telerik:RadButton ID="cancel_Rbtn" runat="server" Text="Cancel"

 

BackColor="#FF3300" Font-Bold="True" ForeColor="#FF3300">

 

</telerik:RadButton>

 

<br />

 

</form>

</

 

 

body>

</

 

 

html>


0
Peter
Telerik team
answered on 21 May 2012, 04:15 PM
Hi,

To sort appointments by some custom criteria, you should use the AppointmentComparer property of RadScheduler as shown in this forum post:
http://www.telerik.com/community/forums/aspnet-ajax/scheduler/oder-of-entry-in-scheduler.aspx#1155620

For Web Service binding mode, please see this forum post:
http://www.telerik.com/community/forums/aspnet-ajax/scheduler/example-of-how-to-use-an-appointmentcomparer.aspx#1188449

Feel free to contact us if you have further questions.


Regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Allen
Top achievements
Rank 1
answered on 09 Jul 2012, 06:31 PM
The week view look great, but the appointments in month view are not positioed Horizontally.  Please refer to the attached files.
Here is the VB:

Imports

 

 

System.IO

 

Imports

 

 

Microsoft.VisualBasic

 

Imports

 

 

System.Collections.Generic

 

Imports

 

 

System.Web

 

Imports

 

 

System.Web.UI

 

Imports

 

 

System.Web.UI.WebControls

 

Imports

 

 

System.Data

 

Imports

 

 

System.Configuration

 

Imports

 

 

System.Web.Security

 

Imports

 

 

System.Web.UI.WebControls.WebParts

 

Imports

 

 

System.Web.UI.HtmlControls

 

Imports

 

 

Telerik.Web.UI

 

Imports

 

 

System.Drawing

 

 

Public

 

 

Class MyAvailability

 

 

 

Inherits System.Web.UI.Page

 

 

 

Private Class CustomAppointmentComparer

 

 

 

Implements IComparer(Of Appointment)

 

 

 

Public Function Compare(first As Appointment, second As Appointment) As Integer Implements IComparer(Of Telerik.Web.UI.Appointment).Compare

 

 

 

Dim infoStart1 As String = first.Start.ToString

 

 

 

Dim infoend1 As String = first.End.ToString

 

 

 

Dim infoStar2 As String = second.Start.ToString

 

 

 

Dim infoend2 As String = second.End.ToString

 

 

 

If first Is Nothing OrElse second Is Nothing Then

 

 

 

Throw New InvalidOperationException("Can't compare null object(s).")

 

 

 

End If

 

 

 

If [String].Compare(first.Subject.ToString, second.Subject.ToString) < 0 Then

 

 

 

Return -1

 

 

 

End If

 

 

 

 

If [String].Compare(first.Subject.ToString, second.Subject.ToString) > 0 Then

 

 

 

Return 1

 

 

 

End If

 

 

 

Return 0

 

 

 

End Function

 

 

 

End Class

 

 

 

Protected Overrides Sub OnInit(e As EventArgs)

 

 

 

MyBase.OnInit(e)

 

RadScheduler1.Provider =

 

New XmlSchedulerProvider(Server.MapPath("~/App_Data/Appointments.xml"), True)

 

 

 

End Sub

 

 

 

Protected Sub RadScheduler1_AppointmentDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerEventArgs) Handles RadScheduler1.AppointmentDataBound

 

e.Appointment.CssClass =

 

"MyCustomAppointmentStyle"

 

 

 

If e.Appointment.Subject = "Availability" Then

 

e.Appointment.CssClass =

 

"•rsCategoryYellow"

 

 

 

Else

 

e.Appointment.CssClass =

 

"rsCategoryGreen"

 

 

 

End If

 

 

 

''e.Appointment.

 

 

 

End Sub

 

 

 

Protected Sub RadScheduler1_AppointmentCreated(sender As Object, e As AppointmentCreatedEventArgs) Handles RadScheduler1.AppointmentCreated

 

 

 

''If e.Appointment.Subject = "Prefered Availability" Then

 

 

 

If e.Appointment.Subject = "Preference" Then

 

e.Appointment.BackColor = System.Drawing.Color.Green

 

 

End If

 

 

 

If e.Appointment.Subject = "Availability" Then

 

e.Appointment.BackColor = System.Drawing.Color.FromName(

 

"#FEEDA9")

 

 

 

End If

 

 

 

If e.Appointment.Visible AndAlso Not IsAppointmentRegisteredForTooltip(e.Appointment) Then

 

 

 

Dim id As String = e.Appointment.ID.ToString()

 

 

 

For Each domElementID As String In e.Appointment.DomElements

 

RadToolTipManager1.TargetControls.Add(domElementID, id,

 

True)

 

 

 

Next

 

 

 

End If

 

 

 

End Sub

 

 

 

 

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

 

RadToolTipManager1.OnClientRequestStart =

 

"OnClientRequestStart"

 

RadScheduler1.AppointmentComparer =

 

New CustomAppointmentComparer()

 

 

 

Dim appointments As Appointment() = RadScheduler1.Appointments.ToArray()

 

Array.Sort(appointments,

 

New CustomAppointmentComparer())

 

 

 

For Each appointment As Appointment In appointments

 

 

 

Dim appointmentStart As DateTime = RadScheduler1.UtcToDisplay(appointment.Start)

 

 

 

If appointmentStart > RadScheduler1.SelectedDate Then

 

RadScheduler1.SelectedDate = appointmentStart.[Date]

 

 

Exit For

 

 

 

End If

 

 

 

Next

 

 

 

End Sub

 

 

 

Protected Sub RadScheduler1_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles RadScheduler1.DataBound

 

RadToolTipManager1.TargetControls.Clear()

ScriptManager.RegisterStartupScript(

 

Me, GetType(System.Web.UI.Page), "HideToolTip", "hideActiveToolTip();", True)

 

 

 

Dim monthNum As Integer = RadScheduler1.VisibleRangeStart.Month

 

 

 

Dim strDate As New DateTime(1, monthNum, 1)

 

RadScheduler1.Localization.AllDay = strDate.ToString(

 

"MMMMM")

 

 

 

End Sub

 

 

 

Protected Sub MyAvailability1_FormCreated(ByVal sender As Object, ByVal e As SchedulerFormCreatedEventArgs) Handles RadScheduler1.FormCreated

 

 

 

If (e.Container.Mode = SchedulerFormMode.AdvancedEdit) OrElse (e.Container.Mode = SchedulerFormMode.AdvancedInsert) Then

 

 

 

Dim allDayCheckbox As CheckBox = DirectCast(e.Container.FindControl("AllDayEvent"), CheckBox)

 

allDayCheckbox.Style.Add(

 

"visibility", "hidden")

 

 

 

Dim attrAnnotationsTextbox As RadTextBox = DirectCast(e.Container.FindControl("Subject"), RadTextBox)

 

attrAnnotationsTextbox.Label =

 

"Type"

 

attrAnnotationsTextbox.Enabled =

 

False

 

 

 

Dim AppointmentID As Integer = e.Appointment.ID

 

 

 

Dim AppointmentIDPrevious As Integer = e.Appointment.ID - 1

 

 

 

Dim PreviousAppointment As New Appointment

 

 

 

''Dim startPicker As RadTimePicker = DirectCast(e.Container.FindControl("StartTime"), RadTimePicker)

 

 

 

''startPicker.TimeView.StartTime = TimeSpan.FromHours(1.5)

 

 

 

''startPicker.TimeView.EndTime = TimeSpan.FromHours(24)

 

 

 

''startPicker.TimeView.DataList.DataSource = Nothing

 

 

 

''startPicker.TimeView.DataBind()

 

 

 

''Dim endPicker As RadTimePicker = DirectCast(e.Container.FindControl("EndTime"), RadTimePicker)

 

 

 

''endPicker.TimeView.StartTime = TimeSpan.FromHours(8)

 

 

 

''endPicker.TimeView.EndTime = TimeSpan.FromHours(24)

 

 

 

''endPicker.TimeView.DataList.DataSource = Nothing

 

 

 

''endPicker.TimeView.DataBind()

 

 

 

'' Dim StartTimeAppointmentIDPrevious As String = RadScheduler1.Appointments.FindByID(52).Start.ToString

 

 

 

'' Catch ex As Exception

 

 

 

''ex.ToString()

 

 

 

'' End Try

 

 

 

Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)

 

 

 

Dim StartTimeAvail As DateTime

 

 

 

Dim EndTimeAvail As DateTime

 

 

 

If e.Appointment.Subject = "Preference" Then

 

 

 

For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.[End])

 

 

 

If app.Subject = "Availability" Then

 

StartTimeAvail = app.Start.ToShortTimeString

EndTimeAvail = app.End.ToShortTimeString

 

 

Exit For

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

Dim startPicker As RadTimePicker = DirectCast(e.Container.FindControl("StartTime"), RadTimePicker)

 

 

 

Dim endPicker As RadTimePicker = DirectCast(e.Container.FindControl("EndTime"), RadTimePicker)

 

 

 

Dim StartDbleTime As Double = StartTimeAvail.ToOADate() * 24

 

 

 

Dim EndDbleTime As Double = EndTimeAvail.ToOADate() * 24 + 0.5

 

startPicker.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)

 

 

''startPicker.TimeView.EndTime = TimeSpan.FromHours(24)

 

startPicker.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)

endPicker.TimeView.StartTime = TimeSpan.FromHours(StartDbleTime)

endPicker.TimeView.EndTime = TimeSpan.FromHours(EndDbleTime)

startPicker.TimeView.DataList.DataSource =

 

Nothing

 

startPicker.TimeView.DataBind()

endPicker.TimeView.DataList.DataSource =

 

Nothing

 

endPicker.TimeView.DataBind()

 

 

''Dim startTime As RadTimePicker = TryCast(e.Container.FindControl("StartTime"), RadTimePicker)

 

 

 

''Dim DbleTime As Double = ADate.ToOADate() * 24

 

 

 

''startPicker.TimeView.StartTime = TimeSpan.FromHours(DbleTime)

 

 

 

End If

 

 

 

End Sub

 

 

 

Protected Sub MyAvailability1_AppointmentInsert(sender As Object, e As AppointmentInsertEventArgs) Handles RadScheduler1.AppointmentInsert

 

 

 

If e.Appointment.Subject = "Preference" Then

 

 

 

Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)

 

 

 

For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.[End])

 

 

 

If app.Subject = "Availability" Then

 

 

 

If app.Start > e.Appointment.Start OrElse app.[End] <= e.Appointment.[End] Then

 

e.Cancel =

 

True

 

 

 

End If

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

End Sub

 

 

 

Protected Sub MyAvailability1_AppointmentUpdate(sender As Object, e As AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate

 

 

 

Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)

 

 

 

If e.ModifiedAppointment.Subject = "Preference" Then

 

 

 

For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End])

 

 

 

If app.Subject = "Availability" Then

 

 

 

If app.Start > e.ModifiedAppointment.Start OrElse app.[End] < e.ModifiedAppointment.[End] Then

 

e.Cancel =

 

True

 

 

 

End If

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

If e.ModifiedAppointment.Subject = "Availability" Then

 

 

 

For Each app As Appointment In scheduler.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.[End])

 

 

 

If app.Subject = "Preference" Then

 

 

 

If app.Start < e.ModifiedAppointment.Start OrElse app.[End] > e.ModifiedAppointment.[End] Then

 

e.Cancel =

 

True

 

 

 

End If

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

End Sub

 

 

 

Private Function IsAppointmentRegisteredForTooltip(ByVal apt As Appointment) As Boolean

 

 

 

For Each targetControl As ToolTipTargetControl In RadToolTipManager1.TargetControls

 

 

 

If (apt.DomElements.Contains(targetControl.TargetControlID)) Then

 

 

 

Return True

 

 

 

End If

 

 

 

Next

 

 

 

Return False

 

 

 

End Function

 

 

 

Protected Sub RadToolTipManager1_AjaxUpdate(ByVal sender As Object, ByVal e As ToolTipUpdateEventArgs)

 

 

 

Dim aptId As Integer

 

 

 

Dim apt As Appointment

 

 

 

If Not Integer.TryParse(e.Value, aptId) Then

 

 

 

'The appoitnment is occurrence and FindByID expects a string

 

apt = RadScheduler1.Appointments.FindByID(e.Value)

 

 

Else

 

 

 

'The appointment is not occurrence and FindByID expects an int

 

apt = RadScheduler1.Appointments.FindByID(aptId)

 

 

End If

 

 

 

''Dim toolTip As AppointmentToolTip = CType(LoadControl("AppointmentToolTip.ascx"), AppointmentToolTip)

 

 

 

''toolTip.TargetAppointment = apt

 

 

 

''e.UpdatePanel.ContentTemplateContainer.Controls.Add(toolTip)

 

 

 

End Sub

 

 

 

 

Public newStartLabel As String = ""

 

 

 

Public newEndLabel As String = ""

 

 

 

Public dayOfWeek As String = ""

 

 

 

Protected Sub RadScheduler1_AppointmentUpdate(sender As Object, e As AppointmentUpdateEventArgs)

 

 

 

If e.ModifiedAppointment.Subject = "Availability" Then

 

newStartLabel = e.ModifiedAppointment.Start.ToString()

newEndLabel = e.ModifiedAppointment.[End].ToString()

dayOfWeek = e.ModifiedAppointment.Start.DayOfWeek.ToString()

 

 

End If

 

 

 

End Sub

 

 

 

Protected Sub RadScheduler1_TimeSlotCreated(sender As Object, e As TimeSlotCreatedEventArgs) Handles RadScheduler1.TimeSlotCreated

 

 

 

Dim scheduler As RadScheduler = DirectCast(sender, RadScheduler)

 

 

 

''If scheduler.SelectedView = SchedulerViewType.WeekView AndAlso e.TimeSlot.Duration = TimeSpan.FromDays(1) Then

 

 

 

If e.TimeSlot.Duration = TimeSpan.FromDays(1) Then

 

 

 

Dim startLabel As New Label()

 

 

 

Dim startLabelPref As New Label()

 

startLabel.ID =

 

"startLabel" + e.TimeSlot.Start.DayOfWeek.ToString + CType(e.TimeSlot.Start.Day, String)

 

startLabelPref.ID =

 

"startLabelPref" + e.TimeSlot.Start.DayOfWeek.ToString + CType(e.TimeSlot.Start.Day, String)

 

startLabel.Font.Size = 7

startLabel.Font.Bold =

 

True

 

startLabelPref.Font.Size = 7

startLabelPref.Font.Bold =

 

True

 

 

 

If newStartLabel <> "" AndAlso dayOfWeek = e.TimeSlot.Start.DayOfWeek.ToString() Then

 

startLabel.Text = newStartLabel

 

 

Else

 

 

 

For Each app As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.TimeSlot.Start, e.TimeSlot.[End])

 

 

 

If app.Subject = "Availability" Then

 

 

 

Dim TimeFormat As String

 

TimeFormat = Trim(app.Start.ToShortTimeString)

 

 

''TimeFormat.Replace(" AM", "a")

 

 

 

If TimeFormat.Contains("AM") Then

 

startLabel.Text =

 

" " + TimeFormat.Replace(" AM", "a")

 

 

 

Else

 

startLabel.Text =

 

" " + app.Start.ToShortTimeString.Replace(" PM", "p")

 

 

 

End If

 

startLabel.BackColor = System.Drawing.Color.FromName(

 

"#FEEDA9")

 

 

 

End If

 

 

 

If app.Subject = "Preference" Then

 

 

 

Dim TimeFormat As String

 

TimeFormat = Trim(app.Start.ToShortTimeString)

 

 

''TimeFormat.Replace(" AM", "a")

 

 

 

If TimeFormat.Contains("AM") Then

 

startLabelPref.Text = TimeFormat.Replace(

 

" AM", "a")

 

 

 

Else

 

startLabelPref.Text = app.Start.ToShortTimeString.Replace(

 

" PM", "p")

 

 

 

End If

 

startLabelPref.BackColor = System.Drawing.Color.FromName(

 

"#D0ECBB")

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

Dim endLabel As New Label()

 

 

 

Dim endLabelPref As New Label()

 

 

 

''startLabel.ID = "endLabel" + e.TimeSlot.Start.DayOfWeek.ToString

 

endLabel.ID =

 

"endLabel" + e.TimeSlot.End.DayOfWeek.ToString + CType(e.TimeSlot.End.Day, String)

 

 

 

''startLabelPref.ID = "endLabelPref" + e.TimeSlot.Start.DayOfWeek.ToString

 

endLabelPref.ID =

 

"endLabelPref" + e.TimeSlot.End.DayOfWeek.ToString + CType(e.TimeSlot.End.Day, String)

 

endLabel.Font.Size = 7

endLabel.Font.Bold =

 

True

 

endLabelPref.Font.Size = 7

endLabelPref.Font.Bold =

 

True

 

 

 

''If newStartLabel <> "" AndAlso dayOfWeek = e.TimeSlot.Start.DayOfWeek.ToString() Then

 

 

 

If newEndLabel <> "" AndAlso dayOfWeek = e.TimeSlot.End.DayOfWeek.ToString() Then

 

endLabel.Text =

 

"-" + newEndLabel

 

 

 

Else

 

 

 

For Each app As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.TimeSlot.Start, e.TimeSlot.[End])

 

 

 

If app.Subject = "Availability" Then

 

 

 

Dim TimeFormat2 As String

 

TimeFormat2 = Trim(

 

"-" + app.[End].ToShortTimeString)

 

endLabel.Text = TimeFormat2.Replace(

 

" AM", "a")

 

endLabel.Text =

 

"-" + app.[End].ToShortTimeString.Replace(" PM", "p")

 

endLabel.BackColor = System.Drawing.Color.FromName(

 

"#FEEDA9")

 

 

 

End If

 

 

 

If app.Subject = "Preference" Then

 

 

 

Dim TimeFormat2 As String

 

TimeFormat2 = Trim(

 

"-" + app.[End].ToShortTimeString)

 

endLabelPref.Text = TimeFormat2.Replace(

 

" AM", "a")

 

endLabelPref.Text =

 

"-" + app.[End].ToShortTimeString.Replace(" PM", "p")

 

endLabelPref.BackColor = System.Drawing.Color.FromName(

 

"#D0ECBB")

 

 

 

End If

 

 

 

Next

 

 

 

End If

 

 

 

Dim divisionLabel As New Label()

 

divisionLabel.Text =

 

" | "

 

divisionLabel.BackColor = Color.Transparent

e.TimeSlot.Control.Controls.Add(startLabel)

e.TimeSlot.Control.Controls.Add(endLabel)

e.TimeSlot.Control.Controls.Add(divisionLabel)

e.TimeSlot.Control.Controls.Add(startLabelPref)

e.TimeSlot.Control.Controls.Add(endLabelPref)

 

 

''e.Appointment.Attributes.Add("onclick", "javascript:ViewLeave('" & DataRowView.Item("LeaveID").ToString() & "');")

 

startLabel.Attributes.Add(

 

"onclick", "TimeRangeOnclick")

 

 

 

End If

 

 

 

''End If

 

 

 

End Sub

 

0
Peter
Telerik team
answered on 11 Jul 2012, 12:58 PM
Hi Allen,

The ordering of appointments in month view which you require is not supported by RadScheduler. Please, accept our apology for this limitation of the control.

Regards,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Allen
Top achievements
Rank 1
answered on 11 Jul 2012, 01:09 PM
Is there any workaround?  programmatically assign position for the appointments?
0
Peter
Telerik team
answered on 11 Jul 2012, 01:13 PM
Hi Allen,

There isn't a workaround, since the rendering of RadScheduler needs to be changed for this requirement to be fulfilled.

All the best,
Peter
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rick
Top achievements
Rank 1
answered on 29 Aug 2012, 02:04 PM
What is needed to sort the appointments by  the datasubjectfield?  In my case, all of these are "All Day" appointments.

I added the code specified above to this, but nothing happens.  Maybe it post left something out assuming the end user knows what should be done...

Basically, my datasubjectfield is an employee's name.  I want this to sort alphabetically, but is not sorted in any way at all.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebPlayGround.WebForm1" %>
 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"></telerik:RadScriptManager>
            <script type="text/javascript">
                Telerik.Web.UI.SchedulerAppointment.prototype.compare =
         
                function(otherAppointment)
                    {
                        var subject = this.get_subject();
                        var otherSubject = otherAppointment.get_subject();
   
                        if (otherAppointment == null)
                            returnValue = 1;
                        else if (subject == otherSubject)
                            returnValue = 0;
                        else if (subject < otherSubject)
                            returnValue = -1;
                        else
                            returnValue = 1;
   
                        return returnValue;
                    }
            </script>
            <telerik:RadScheduler
                runat="server"
                ID="RadScheduler1"
                SelectedView="WeekView"
                OverflowBehavior="Expand"
                DataSourceID="AccessDataSource1"
                DataKeyField="AutoNumber"
                DataStartField="StartDate"
                DataEndField="EndDate"
                DataSubjectField="EmployeeName"
                AllowDelete="False"
                AllowEdit="False"
                AllowInsert="False"
                Skin="Web20"
                RowHeight="34px" ReadOnly="True">
          
                <AdvancedForm Modal="true" />
                <Reminders Enabled="true" />
                <TimeSlotContextMenuSettings EnableDefault="True" />
                <AppointmentContextMenuSettings EnableDefault="True" />
                <AdvancedForm Modal="True"></AdvancedForm>
                <WeekView WorkDayEndTime="18:00:00" />
                <DayView WorkDayEndTime="18:00:00" />
                <MultiDayView WorkDayEndTime="18:00:00" />
                <MonthView VisibleAppointmentsPerDay="4" />
                <AppointmentContextMenuSettings EnableDefault="True"></AppointmentContextMenuSettings>
                <TimeSlotContextMenuSettings EnableDefault="True"></TimeSlotContextMenuSettings>
            </telerik:RadScheduler>
     
            <asp:AccessDataSource ID="AccessDataSource1" runat="server"
                DataFile="\\w-fs\vol2\DLBApps\VacSched\VacSched.mdb"
                SelectCommand="SELECT VacationBTBL.AutoNumber, IIf([Hours]=8,[Date],DateAdd("h",-[Hours],CDate([Date] & " 17:00"))) AS StartDate, IIf([Hours]=8,[EmailDisplayName],[EmailDisplayName] & " (" & [Hours] & ")") AS EmployeeName, IIf([Hours]=8,[Date]+1,CDate([Date] & " 17:00")) AS EndDate
                    FROM VacationBTBL INNER JOIN EMPLOYEE ON VacationBTBL.EMP = EMPLOYEE.EMP
                    WHERE (((IIf([Hours]=8,[Date],DateAdd("h",-[Hours],CDate([Date] & " 17:00"))))>Date()-32) AND ((EMPLOYEE.EMP_STATUS)="Active"))
                    ORDER BY IIf([Hours]=8,[EmailDisplayName],[EmailDisplayName] & " (" & [Hours] & ")");" >
            </asp:AccessDataSource>
  
        </form>
    </body>
</html>
0
Rick
Top achievements
Rank 1
answered on 30 Aug 2012, 02:43 PM
Still actively searching for a solution.

I do find it odd that it would not automatically sort by the subject field where the times and duration are equal.  
0
Rick
Top achievements
Rank 1
answered on 30 Aug 2012, 07:25 PM
Resolved.  Added the code below.  The Telerik Code Converter failed me.  First, the code samples provided above was missing a closing bracket.  Second, the converter failed to fully convert "Public Function Compare" code.  The bold text was missing.

Public Function Compare(first As Appointment, second As Appointment) As Integer _
Implements IComparer(Of Telerik.Web.UI.Appointment).Compare
 


Imports Telerik.Web.UI
 
 
Public Class WebForm1
    Inherits System.Web.UI.Page
 
    Private Sub Page_Init1(sender As Object, e As System.EventArgs) Handles Me.Init
        RadScheduler1.AppointmentComparer = New CustomAppointmentComparer()
    End Sub
End Class
 
Class CustomAppointmentComparer
    Implements IComparer(Of Appointment)
    Public Function Compare(first As Appointment, second As Appointment) As Integer Implements IComparer(Of Telerik.Web.UI.Appointment).Compare
        If first Is Nothing OrElse second Is Nothing Then
            Throw New InvalidOperationException("Can't compare null object(s).")
        End If
 
        If [String].Compare(first.Subject, second.Subject) < 0 Then
            Return -1
        End If
 
        If [String].Compare(first.Subject, second.Subject) > 0 Then
            Return 1
        End If
 
        Return 0
    End Function
End Class
Tags
Scheduler
Asked by
Greg Mercer
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Allen
Top achievements
Rank 1
Peter
Telerik team
Rick
Top achievements
Rank 1
Share this question
or