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

Limit the number of concurrent appointments just for a single resource

7 Answers 77 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Martin Gartmann
Top achievements
Rank 2
Martin Gartmann asked on 14 Jun 2011, 02:33 PM
Hi All,

1.) i want to implement a simlar function like this one shown by Telerik in the past for the asp.net ajax scheduler to my winform application. I use it on a webform solutions and it is working great.

http://www.telerik.com/support/kb/aspnet-ajax/scheduler/limit-the-number-of-concurrent-appointments-just-for-a-single-resource.aspx

Is there a sample around how to do the same in winforms.

2.) in my winform application the times in the scheduler is 24h format and language is set to german, but when i enter  edit mode AM/PM Times are shown in the time pickers. any suggestions what might be wrong.

Kind regards

Martin Gartmann

7 Answers, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 15 Jun 2011, 01:31 PM
Hello Martin,

The first of your requirements can be achieved by subscribing to the CollectionChanging event of the Appointments collection of RadScheduler and canceling the process of adding an appointment as needed. This is shown in the next code snippet:
private const int MaxConcurentAppointments = 1;
 
private int GetConcurentAppointments(Appointment newAppointment)
{
    int count = 1;
    foreach (Appointment app in this.radScheduler1.Appointments)
    {
        if (app.ResourceId == newAppointment.ResourceId &&
            app.Start < newAppointment.End &&
            app.End > newAppointment.Start)
        {
            count++;
        }
    }
 
    return count;
}
 
void Appointments_CollectionChanging(object sender, Telerik.WinControls.Data.NotifyCollectionChangingEventArgs e)
{
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add)
    {
        foreach (Appointment app in e.NewItems)
        {
            if (GetConcurentAppointments(app) > MaxConcurentAppointments)
            {
                e.Cancel = true;
                break;
            }
        }
    }
}

The second of your requirements could be achieved by inheriting from the AppointmentEditDialog class and changing the format of the time pickers:
public class CustomEditAppointmentDialog : EditAppointmentDialog
{
    public CustomEditAppointmentDialog() : base()
    {
        InitializeComponent();
        this.timeStart.CustomFormat = "HH:mm:ss";
        this.timeEnd.CustomFormat = "HH:mm:ss";
    }
}

and replacing the standard dialog by handling the AppointmentEditDialogShowing event:
void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
{
    e.AppointmentEditDialog = new CustomEditAppointmentDialog();
}

I hope you find this useful. Feel free to ask if you have any further questions.

All the best,
Ivan Todorov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Martin Gartmann
Top achievements
Rank 2
answered on 17 Jun 2011, 08:10 AM
Dear Ivan,
the 2nd solutions is working like expected, but after converting your code to vb.net i will se an error.

Private Function GetConcurentAppointments(ByVal newAppointment As Appointment) As Integer
    Dim count As Integer = 1
    For Each app As Appointment In Me.rsMain.Appointments
        If ((app.ResourceId = newAppointment.ResourceId) _
                    AndAlso ((app.Start < newAppointment.End) _
                    AndAlso (app.End > newAppointment.Start))) Then
            count = (count + 1)
        End If
    Next
    Return count
End Function

at  app.ResourceId = newAppointment.ResourceId there is an error code: 

The =-Operator is not declared for the type "Telerik.WinControls.UI.EventId"
and "Telerik.WinControls.UI.EventId"

I have an extended appointment class like this


Imports Telerik.WinControls.UI
 
Public Class AppointmentWithKPP
 
    Inherits Appointment
    Public Sub New()
        MyBase.New()
    End Sub
 
    Private _KundenId As Integer
    Private _Preis As String = String.Empty
    Private _Personen As String = String.Empty
 
    Public Property KundenId() As Integer
        Get
            Return Me._KundenId
        End Get
        Set(ByVal value As Integer)
            If Me._KundenId <> value Then
                Me._KundenId = value
                Me.OnPropertyChanged("KundenId")
            End If
        End Set
    End Property
 
    Public Property Preis() As String
        Get
            Return Me._Preis
        End Get
        Set(ByVal value As String)
            If Me._Preis <> value Then
                Me._Preis = value
                Me.OnPropertyChanged("Preis")
            End If
        End Set
    End Property
 
 
    Public Property Personen() As String
        Get
            Return Me._Personen
        End Get
        Set(ByVal value As String)
            If Me._Personen <> value Then
                Me._Personen = value
                Me.OnPropertyChanged("Personen")
            End If
        End Set
    End Property
 
 
End Class

Any suggestions what's the reason ?

Kind regards

Martin
0
Ivan Todorov
Telerik team
answered on 22 Jun 2011, 07:17 PM
Hi Martin Gartmann,

It looks like the equality check has not converted correctly. Please replace the following line:

If ((app.ResourceId = newAppointment.ResourceId) _
with this one:
If (Object.Equals(app.ResourceId, newAppointment.ResourceId) _

Hope this helps. Should you have any additional questions, do not hesitate to ask.

Kind regards,
Ivan Todorov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Martin Gartmann
Top achievements
Rank 2
answered on 27 Jun 2011, 03:43 PM
Dear Ivan,
Your suggestion solved this issue.
I have used

AddHandler Me.rsMain.Appointments.CollectionChanging, AddressOf Appointments_CollectionChanging

to subscribe to the CollectionChanging and it is working like expected when i add a new appoitment.

Private Sub Appointments_CollectionChanging(ByVal sender As Object, ByVal e As Telerik.WinControls.Data.NotifyCollectionChangingEventArgs)
      If (e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.Add) Then
          For Each app As Appointment In e.NewItems
              If (GetConcurentAppointments(app) > MaxConcurentAppointments) Then
                  e.Cancel = True
                  MsgBox("Der Zeitraum ist bereits belegt!" + vbCrLf + vbCrLf + "Mehrfachbelegung ist nicht erlaubt!")
                  Exit For
              End If
          Next
      End If
  End Sub

When i Drag&Drop or Resize an appoinment in the scheduler a collectioinchanging seems not to be fired.

Add and remove will fire it.

As far as i understood this should also be also the case when a change an appointment.

Finally: What i want is to block overlapping by dragging and dropping (moving) or resizing an appointment.

Can this be done also just by Appointments_CollectionChanging ?

or must i use DragDropBehavior.AppointmentMoving or another type of event.

Kind regards

Martin Gartmann





0
Ivan Todorov
Telerik team
answered on 30 Jun 2011, 12:39 PM
Hi Martin,

CollectionChanging event will not fire in your case, because the Appointment class does not implement INotifyPropertyChanging, hence the collection is not notified for such event. You should use DragDropBehavior.AppointmentDropping and ResizeBehavior.AppointmentResizing events.
Private Sub ResizeBehavior_AppointmentResizing(sender As Object, e As AppointmentResizingEventArgs)
    If Not IsResizeValid(e.Appointment, Control.MousePosition) Then
        e.Cancel = True
    End If
End Sub
 
Private Sub DragDropBehavior_AppointmentDropping(sender As Object, e As AppointmentMovingEventArgs)
    If GetConcurrentAppointments(e.Appointment) > 1 Then
        e.Cancel = True
    End If
End Sub
 
Private Function GetConcurrentAppointments(newAppointment As IEvent) As Integer
    Dim count As Integer = 1
    For Each app As Appointment In Me.radScheduler1.Appointments
        If Object.Equals(app.ResourceId, newAppointment.ResourceId) AndAlso app.Start < newAppointment.[End] AndAlso app.[End] > newAppointment.Start AndAlso app <> Me.radScheduler1.SchedulerElement.DragDropBehavior.ActiveFeedback.AssociatedAppointment Then
            count += 1
        End If
    Next
    Return count
End Function
 
Private Function IsResizeValid(resizedApp As IEvent, mousePos As Point) As Boolean
 
    Dim clientPoint As Point = Me.radScheduler1.PointToClient(mousePos)
 
    Dim appElement As AppointmentElement = Me.radScheduler1.SchedulerElement.ResizeBehavior.ActiveAppointment
 
    If appElement Is Nothing Then
        Return True
    End If
 
    Dim isUpResize As Boolean = Math.Abs(clientPoint.Y - appElement.ControlBoundingRectangle.Top) < Math.Abs(clientPoint.Y - appElement.ControlBoundingRectangle.Bottom)
 
    For Each app As Appointment In Me.radScheduler1.Appointments
        If Not Object.Equals(app, resizedApp) Then
            If app.[End] = resizedApp.Start AndAlso isUpResize Then
                Return False
            End If
            If app.Start = resizedApp.[End] AndAlso Not isUpResize Then
                Return False
            End If
        End If
    Next
    Return True
End Function

Please note that this will only work when grouping by resource is disabled. There are some known limitations when grouping by resource is turned on (for example: one is not able to cancel the dropping of an appointment) which we plan to address in one of the future releases.

I hope this helps. Do not hesitate to contact me if you have any additional questions.

Regards,
Ivan Todorov
the Telerik team
Registration for Q2 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting July 18th and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Martin Gartmann
Top achievements
Rank 2
answered on 30 Jun 2011, 02:52 PM
Dear Ivan,

Thanks for helping with this issue. After adding:

AddHandler Me.rsMain.SchedulerElement.ResizeBehavior.AppointmentResizing, AddressOf ResizeBehavior_AppointmentResizing
AddHandler Me.rsMain.SchedulerElement.DragDropBehavior.AppointmentDropping, AddressOf DragDropBehavior_AppointmentDropping

in my form_load without grouping active it is working like expected. Is there a detail timetable when this option will be also avaible when grouping is switched on, because i plan to use it.

My application will be just used for training/demo purpose in the next weeks and during this time this feature is not really needed.

It should go to in production beginning of 2012, so if this option will be avaible until 2011 Q3 i would implement this later while working on other features.

So information about the timetable would be helpfull

Kind regards

Martin

P.S.: I will submit my code as an example in the support resources when ready, because i guess this might be helpfull for other users running into near by questions.
0
Ivan Todorov
Telerik team
answered on 05 Jul 2011, 08:28 AM
Hi Martin,

Currently, we have not specified any time frame for this issue. The issue is logged in PITS, so you can subscribe and vote for it. Here is the link to the PITS item. If more people vote for it, we will consider addressing it with higher priority.

I hope this helps. Feel free to ask if you have any further questions.

All the best,
Ivan Todorov
the Telerik team
Registration for Q2 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting July 18th and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Scheduler and Reminder
Asked by
Martin Gartmann
Top achievements
Rank 2
Answers by
Ivan Todorov
Telerik team
Martin Gartmann
Top achievements
Rank 2
Share this question
or