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

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

6 Answers 833 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Michael Dunbar
Top achievements
Rank 2
Michael Dunbar asked on 19 Jan 2010, 11:54 AM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 20 Jan 2010, 11:46 AM
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.
0
Phil
Top achievements
Rank 1
answered on 15 Feb 2012, 02:44 PM
Hi

does this also work during databinding?

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

kind regards

John
 

0
Peter
Telerik team
answered on 16 Feb 2012, 06:06 PM
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 >>
0
AJIT
Top achievements
Rank 1
answered on 28 Aug 2018, 01:15 PM
share complete demo appointment schedule with database .
0
AJIT
Top achievements
Rank 1
answered on 28 Aug 2018, 01:36 PM
i want visible false Month and timeline , next and previous button from form. 
0
Peter Milchev
Telerik team
answered on 31 Aug 2018, 10:54 AM
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.
Tags
Scheduler
Asked by
Michael Dunbar
Top achievements
Rank 2
Answers by
Peter
Telerik team
Phil
Top achievements
Rank 1
AJIT
Top achievements
Rank 1
Peter Milchev
Telerik team
Share this question
or