Hi,
Just a little Issue than i am trying to fix with my proyect. The Issue is the next i want to limit the number of simultaneous appointments so that only one appointment is allowed per time I have this code, but the events: RadScheduler1_AppointmentInsert and RadScheduler1_AppointmentUpdate do not execute when i insert or update an appointment, and i don't know why:
Protected Sub RadScheduler1_FormCreating(sender As Object, e As SchedulerFormCreatingEventArgs) Handles RadScheduler1.FormCreating
'RadSchedulerRecurrenceEditor1.ResetLayout()
If (txtContacto.Text = String.Empty) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Debe Ingresar un Contacto');",
True)
e.Cancel = True
Else
If e.Mode = SchedulerFormMode.Insert OrElse e.Mode = SchedulerFormMode.Edit Then
EditedAppointment = e.Appointment
e.Cancel = True
End If
Dim appointmentToEdit = RadScheduler1.PrepareToEdit(e.Appointment, RadScheduler1.EditingRecurringSeries)
ScriptManager.RegisterStartupScript(Page, [GetType](), "formScript", "Sys.Application.add_load(openForm);", True)
PopulateEditForm(appointmentToEdit)
End If
End Sub
''' <summary>
''' Funcion setear Actividad en fila AllDay
''' </summary>
''' <param name="appointment"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function IsAllDayAppointment(appointment As Appointment) As Boolean
Dim displayStart As DateTime = RadScheduler1.UtcToDisplay(appointment.Start)
Dim displayEnd As DateTime = RadScheduler1.UtcToDisplay(appointment.[End])
Return displayStart.CompareTo(displayStart.[Date]) = 0 AndAlso displayEnd.CompareTo(displayEnd.[Date]) = 0 AndAlso displayStart.CompareTo(displayEnd) <> 0
End Function
''' <summary>
''' Inicializar Valores en Form Editable
''' </summary>
''' <param name="editedAppointment"></param>
''' <remarks></remarks>
Private Sub PopulateEditForm(editedAppointment As Appointment)
Dim appointmentToEdit As Appointment = RadScheduler1.PrepareToEdit(editedAppointment, RadScheduler1.EditingRecurringSeries)
TxtDescripcion.Text = appointmentToEdit.Subject
dtpHoraInicio.SelectedDate = RadScheduler1.UtcToDisplay(appointmentToEdit.Start)
dtpHoraFinal.SelectedDate = RadScheduler1.UtcToDisplay(appointmentToEdit.[End])
Dim complejidad As Resource = appointmentToEdit.Resources.GetResourceByType("ID_COMPLEJIDAD")
If complejidad IsNot Nothing Then
ddlComplejidad.SelectedValue = complejidad.Key.ToString()
End If
Dim id_task As Resource = appointmentToEdit.Resources.GetResourceByType("ID_TASK")
If id_task IsNot Nothing Then
TxtIdTask.Text = id_task.Key.ToString()
End If
RadSchedulerRecurrenceEditor1.StartDate = appointmentToEdit.Start
RadSchedulerRecurrenceEditor1.EndDate = appointmentToEdit.[End]
RecurrenceRuleText = appointmentToEdit.RecurrenceRule
End Sub
''' <summary>
''' Agregar Actividad a Calendario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
If (ValidarFecha()) Then
If EditedAppointment Is Nothing Then
' Insert Appointment
Dim aptToInsert As Appointment = PopulateBasicAppointmentPropertiesFromForm()
InsertarRegistro()
RadScheduler1.InsertAppointment(aptToInsert)
Else
If Not RadScheduler1.EditingRecurringSeries AndAlso (EditedAppointmentParent IsNot Nothing OrElse EditedAppointment.RecurrenceState = RecurrenceState.Master) Then
' Create Exception Appointment
Dim aptOccurence = EditedAppointment
Dim aptException = PopulateBasicAppointmentPropertiesFromForm(RadScheduler1.PrepareToEdit(aptOccurence, RadScheduler1.EditingRecurringSeries))
RadScheduler1.UpdateAppointment(aptException)
Else
' Update Appointment
Dim aptOriginal As Appointment = EditedAppointment
If RadScheduler1.EditingRecurringSeries AndAlso (aptOriginal.RecurrenceState = RecurrenceState.Occurrence OrElse aptOriginal.RecurrenceState = RecurrenceState.Exception) Then
aptOriginal = EditedAppointmentParent
End If
Dim aptToUpdate As Appointment = PopulateBasicAppointmentPropertiesFromForm(aptOriginal.Clone())
ActualizarRegistro(aptToUpdate.ID)
RadScheduler1.UpdateAppointment(aptToUpdate, aptOriginal)
End If
End If
EditedAppointmentID = ""
EditedAppointmentParentID = ""
RadDock1.Closed = True
Else
RadDock1.Closed = False
RadDock1.Visible = True
End If
End Sub
Private Function PopulateBasicAppointmentPropertiesFromForm() As Appointment
Return PopulateBasicAppointmentPropertiesFromForm(Nothing)
End Function
''' <summary>
''' Setear Valores Necesarios dentro de Actividad en el Calendario
''' </summary>
''' <param name="apt"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function PopulateBasicAppointmentPropertiesFromForm(apt As Appointment) As Appointment
If apt Is Nothing Then
apt = New Appointment()
End If
Dim ID_TASK As New Resource("ID_TASK", Integer.Parse(TxtIdTask.Text), TxtIdTask.Text)
Dim complejidad As New Resource("ID_COMPLEJIDAD", Integer.Parse(ddlComplejidad.SelectedValue), ddlComplejidad.SelectedItem.Text)
Dim start As DateTime = RadScheduler1.DisplayToUtc(dtpHoraInicio.SelectedDate.Value)
Dim [end] As DateTime = RadScheduler1.DisplayToUtc(dtpHoraFinal.SelectedDate.Value)
apt.Subject = TxtDescripcion.Text
apt.Start = start
apt.[End] = [end]
apt.RecurrenceRule = RecurrenceRuleText
Dim existingComplejidad As Resource = apt.Resources.GetResourceByType("ID_COMPLEJIDAD")
If existingComplejidad IsNot Nothing Then
apt.Resources.Remove(existingComplejidad)
End If
apt.Resources.Add(complejidad)
Return apt
End Function
Protected Sub RadAjaxManager1_AjaxRequest(sender As Object, e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
RadScheduler1.Rebind()
End Sub
''' <summary>
''' Evento validar si ya existe una actividad en el mismo horario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Public Sub RadScheduler1_AppointmentInsert(sender As Object, e As AppointmentInsertEventArgs) Handles RadScheduler1.AppointmentInsert
If (RadScheduler1.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.End).Count > 0) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Ya existe una actividad asignada a esta hora');",
True)
e.Cancel = True
End If
End Sub
''' <summary>
''' Evento validar si ya existe una actividad en el mismo horario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Public Sub RadScheduler1_AppointmentUpdate(sender As Object, e As AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate
If (RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End)).Count > 0 Then
For Each apt As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End)
If (apt.ID <> e.Appointment.ID) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Ya existe una actividad asignada a esta hora');",
True)
e.Cancel = True
End If
Next
End If
End Sub
Just a little Issue than i am trying to fix with my proyect. The Issue is the next i want to limit the number of simultaneous appointments so that only one appointment is allowed per time I have this code, but the events: RadScheduler1_AppointmentInsert and RadScheduler1_AppointmentUpdate do not execute when i insert or update an appointment, and i don't know why:
Protected Sub RadScheduler1_FormCreating(sender As Object, e As SchedulerFormCreatingEventArgs) Handles RadScheduler1.FormCreating
'RadSchedulerRecurrenceEditor1.ResetLayout()
If (txtContacto.Text = String.Empty) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Debe Ingresar un Contacto');",
True)
e.Cancel = True
Else
If e.Mode = SchedulerFormMode.Insert OrElse e.Mode = SchedulerFormMode.Edit Then
EditedAppointment = e.Appointment
e.Cancel = True
End If
Dim appointmentToEdit = RadScheduler1.PrepareToEdit(e.Appointment, RadScheduler1.EditingRecurringSeries)
ScriptManager.RegisterStartupScript(Page, [GetType](), "formScript", "Sys.Application.add_load(openForm);", True)
PopulateEditForm(appointmentToEdit)
End If
End Sub
''' <summary>
''' Funcion setear Actividad en fila AllDay
''' </summary>
''' <param name="appointment"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function IsAllDayAppointment(appointment As Appointment) As Boolean
Dim displayStart As DateTime = RadScheduler1.UtcToDisplay(appointment.Start)
Dim displayEnd As DateTime = RadScheduler1.UtcToDisplay(appointment.[End])
Return displayStart.CompareTo(displayStart.[Date]) = 0 AndAlso displayEnd.CompareTo(displayEnd.[Date]) = 0 AndAlso displayStart.CompareTo(displayEnd) <> 0
End Function
''' <summary>
''' Inicializar Valores en Form Editable
''' </summary>
''' <param name="editedAppointment"></param>
''' <remarks></remarks>
Private Sub PopulateEditForm(editedAppointment As Appointment)
Dim appointmentToEdit As Appointment = RadScheduler1.PrepareToEdit(editedAppointment, RadScheduler1.EditingRecurringSeries)
TxtDescripcion.Text = appointmentToEdit.Subject
dtpHoraInicio.SelectedDate = RadScheduler1.UtcToDisplay(appointmentToEdit.Start)
dtpHoraFinal.SelectedDate = RadScheduler1.UtcToDisplay(appointmentToEdit.[End])
Dim complejidad As Resource = appointmentToEdit.Resources.GetResourceByType("ID_COMPLEJIDAD")
If complejidad IsNot Nothing Then
ddlComplejidad.SelectedValue = complejidad.Key.ToString()
End If
Dim id_task As Resource = appointmentToEdit.Resources.GetResourceByType("ID_TASK")
If id_task IsNot Nothing Then
TxtIdTask.Text = id_task.Key.ToString()
End If
RadSchedulerRecurrenceEditor1.StartDate = appointmentToEdit.Start
RadSchedulerRecurrenceEditor1.EndDate = appointmentToEdit.[End]
RecurrenceRuleText = appointmentToEdit.RecurrenceRule
End Sub
''' <summary>
''' Agregar Actividad a Calendario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Sub BtnGuardar_Click(sender As Object, e As EventArgs) Handles BtnGuardar.Click
If (ValidarFecha()) Then
If EditedAppointment Is Nothing Then
' Insert Appointment
Dim aptToInsert As Appointment = PopulateBasicAppointmentPropertiesFromForm()
InsertarRegistro()
RadScheduler1.InsertAppointment(aptToInsert)
Else
If Not RadScheduler1.EditingRecurringSeries AndAlso (EditedAppointmentParent IsNot Nothing OrElse EditedAppointment.RecurrenceState = RecurrenceState.Master) Then
' Create Exception Appointment
Dim aptOccurence = EditedAppointment
Dim aptException = PopulateBasicAppointmentPropertiesFromForm(RadScheduler1.PrepareToEdit(aptOccurence, RadScheduler1.EditingRecurringSeries))
RadScheduler1.UpdateAppointment(aptException)
Else
' Update Appointment
Dim aptOriginal As Appointment = EditedAppointment
If RadScheduler1.EditingRecurringSeries AndAlso (aptOriginal.RecurrenceState = RecurrenceState.Occurrence OrElse aptOriginal.RecurrenceState = RecurrenceState.Exception) Then
aptOriginal = EditedAppointmentParent
End If
Dim aptToUpdate As Appointment = PopulateBasicAppointmentPropertiesFromForm(aptOriginal.Clone())
ActualizarRegistro(aptToUpdate.ID)
RadScheduler1.UpdateAppointment(aptToUpdate, aptOriginal)
End If
End If
EditedAppointmentID = ""
EditedAppointmentParentID = ""
RadDock1.Closed = True
Else
RadDock1.Closed = False
RadDock1.Visible = True
End If
End Sub
Private Function PopulateBasicAppointmentPropertiesFromForm() As Appointment
Return PopulateBasicAppointmentPropertiesFromForm(Nothing)
End Function
''' <summary>
''' Setear Valores Necesarios dentro de Actividad en el Calendario
''' </summary>
''' <param name="apt"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function PopulateBasicAppointmentPropertiesFromForm(apt As Appointment) As Appointment
If apt Is Nothing Then
apt = New Appointment()
End If
Dim ID_TASK As New Resource("ID_TASK", Integer.Parse(TxtIdTask.Text), TxtIdTask.Text)
Dim complejidad As New Resource("ID_COMPLEJIDAD", Integer.Parse(ddlComplejidad.SelectedValue), ddlComplejidad.SelectedItem.Text)
Dim start As DateTime = RadScheduler1.DisplayToUtc(dtpHoraInicio.SelectedDate.Value)
Dim [end] As DateTime = RadScheduler1.DisplayToUtc(dtpHoraFinal.SelectedDate.Value)
apt.Subject = TxtDescripcion.Text
apt.Start = start
apt.[End] = [end]
apt.RecurrenceRule = RecurrenceRuleText
Dim existingComplejidad As Resource = apt.Resources.GetResourceByType("ID_COMPLEJIDAD")
If existingComplejidad IsNot Nothing Then
apt.Resources.Remove(existingComplejidad)
End If
apt.Resources.Add(complejidad)
Return apt
End Function
Protected Sub RadAjaxManager1_AjaxRequest(sender As Object, e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
RadScheduler1.Rebind()
End Sub
''' <summary>
''' Evento validar si ya existe una actividad en el mismo horario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Public Sub RadScheduler1_AppointmentInsert(sender As Object, e As AppointmentInsertEventArgs) Handles RadScheduler1.AppointmentInsert
If (RadScheduler1.Appointments.GetAppointmentsInRange(e.Appointment.Start, e.Appointment.End).Count > 0) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Ya existe una actividad asignada a esta hora');",
True)
e.Cancel = True
End If
End Sub
''' <summary>
''' Evento validar si ya existe una actividad en el mismo horario
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Public Sub RadScheduler1_AppointmentUpdate(sender As Object, e As AppointmentUpdateEventArgs) Handles RadScheduler1.AppointmentUpdate
If (RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End)).Count > 0 Then
For Each apt As Appointment In RadScheduler1.Appointments.GetAppointmentsInRange(e.ModifiedAppointment.Start, e.ModifiedAppointment.End)
If (apt.ID <> e.Appointment.ID) Then
ScriptManager.RegisterStartupScript(
Me,
Me.GetType(),
"popup",
"alert('Ya existe una actividad asignada a esta hora');",
True)
e.Cancel = True
End If
Next
End If
End Sub