Appointment is invalid: Start time must be before the End time.

7 posts, 1 answers
  1. Michael Dunbar
    Michael Dunbar avatar
    129 posts
    Member since:
    Sep 2007

    Posted 19 Jan 2010 Link to this post

    Hello,

    I'm trying to catch this error. If you put a end datetime in that is before the start datetime my application is falling over. Obviously, I am doing this deliberately to break it, but want to catch the error in case a hapless user tries to do the same for some bizarre reason.

    I insert my appointments via a custom Insert template using the Scheduler_AppointmentCommand event. I can catch the input here with:

    try 
                                { 
                                    if (eventEnd >= eventStart) 
                                    { 
                                        UserEventHelper.ArrangeAppraisal(doctor, eventStart, location, label, eventEnd, user.ID); 
                                        litStatus.Text = string.Empty; 
                                    } 
                                    else 
                                    { 

    So, I am not creating an appointment in my business object if the end datetime occurs before the start datetime, but an error is still thrown from the control. Where do I catch this error? Here is the stack trace if that helps:

    [Exception: Appointment is invalid: Start time must be before the End time.]
    Telerik.Web.UI.Appointment.Validate() +162
    Telerik.Web.UI.Scheduling.AppointmentController.InsertAppointmentThroughProvider(Appointment appointment) +17
    Telerik.Web.UI.RadScheduler.InsertAppointmentInline() +106
    Telerik.Web.UI.RadScheduler.OnBubbleEvent(Object source, EventArgs args) +326
    System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
    System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +111
    System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
  2. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 20 Jan 2010 Link to this post

    Hello Michael,

    You can handle AppointmentInsert and AppointmentUpdate to check the values for Start and End time of the appointment and cancel the events or throw an exception:

    protected void RadScheduler1_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
       {
           e.Appointment.Subject = "test";
           e.Appointment.Start = e.Appointment.End.AddHours(1);
           if (e.Appointment.Start > e.Appointment.End)
           {
               e.Cancel = true;
               throw new Exception("start time must be before end time");
           }
       }
       protected void RadScheduler1_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
       {
           if (e.ModifiedAppointment.Start > e.ModifiedAppointment.End)
           {
               //e.Cancel = true;
               throw new Exception("start time must be before end time");
           }
       }


    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Phil
    Phil avatar
    25 posts
    Member since:
    Sep 2012

    Posted 15 Feb 2012 Link to this post

    Hi

    does this also work during databinding?

    Would like to catch the error when it is thrown during binding

    kind regards

    John
     

  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 16 Feb 2012 Link to this post

    Hello,

    You can use a provider and in the GetAppointments method validate the Start and End values before adding the appointment to the return list.
    public override IEnumerable<Appointment> GetAppointments(ISchedulerInfo shedulerInfo)
      {
          var myInfo = shedulerInfo as MySchedulerInfo;
          string teacherID = myInfo.TeacherID;
     
          List<Appointment> appointments = new List<Appointment>();
     
          using (DbConnection conn = OpenConnection())
          {
              DbCommand cmd = DbFactory.CreateCommand();
              cmd.Connection = conn;
              cmd.CommandText = "SELECT [ClassID], [Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentId], [Reminder] FROM [DbProvider_Classes]";
     
              if (teacherID != "all")
                  cmd.CommandText += "WHERE TeacherID = " + teacherID;
     
              using (DbDataReader reader = cmd.ExecuteReader())
              {
                  while (reader.Read())
                  {
                      Appointment apt = new Appointment();
                      apt.ID = reader["ClassID"];
                      apt.Subject = Convert.ToString(reader["Subject"]);
                       
                      //Validate Start and End values here before proceeding
     
                      apt.Start = DateTime.SpecifyKind(Convert.ToDateTime(reader["Start"]), DateTimeKind.Utc);
                      apt.End = DateTime.SpecifyKind(Convert.ToDateTime(reader["End"]), DateTimeKind.Utc);
                      apt.RecurrenceRule = Convert.ToString(reader["RecurrenceRule"]);
                      apt.RecurrenceParentID = reader["RecurrenceParentId"] == DBNull.Value ? null : reader["RecurrenceParentId"];
                      apt.Attributes["AllowEdit"] = "false";


    Greetings,
    Peter
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. AJIT
    AJIT avatar
    3 posts
    Member since:
    Aug 2018

    Posted 28 Aug 2018 in reply to Peter Link to this post

    share complete demo appointment schedule with database .
  6. AJIT
    AJIT avatar
    3 posts
    Member since:
    Aug 2018

    Posted 28 Aug 2018 Link to this post

    i want visible false Month and timeline , next and previous button from form. 
  7. Peter Milchev
    Admin
    Peter Milchev avatar
    464 posts

    Posted 31 Aug 2018 Link to this post

    Hello Ajit,

    The source code for the demo can be found here: https://www.telerik.com/support/code-library/implementing-a-custom-scheduler-provider-that-supports-multi-valued-resources

    To hide the Month and Timeline views you should set the following properties to false:

    MonthView-UserSelectable="false"
    TimelineView-UserSelectable="false"

    To hide the buttons, use the following styles: 

    /* for Lightweight RenderMode */
    .rsToolbar .rsNextDay,
    .rsToolbar .rsPrevDay {
        display: none;
    }
    /* for Classic RenderMode */
    .rsTopWrap .rsHeader .rsNextDay,
    .rsTopWrap .rsHeader .rsPrevDay {
        display: none;
    }

    If you copied the code from a demo, the dropdown you would like to remove is actually the telerik:RadSkinManager which you can just remove or set its ShowChooser property to false: 

    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="false" />

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top