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

calculate total hours

5 Answers 200 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
rajinder singh
Top achievements
Rank 1
rajinder singh asked on 24 Oct 2009, 01:02 PM
hi..telerik..
is there any way to calculate the total number of hours between start time and end time. i need it to calculate when i save the appointment and display it along with the appointmnet title on schedular,..

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Oct 2009, 09:33 AM
Hi Rajinder Singh,

I have tried following code in order to show the hours with the appointment. Give a try with this;

C#:
 
protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e) 
    e.Appointment.Subject = e.Appointment.ToolTip + " (" + e.Appointment.Duration.TotalHours + " hours)"

-Shinu.
0
rajinder singh
Top achievements
Rank 1
answered on 30 Oct 2009, 07:24 AM

thanx shinu...but now i am confused how to save it into my database with other values.i dont want to show it into my subject field..i tried but it show my an error that invalid data type "time"..

 

 

 

Protected

 

Sub RadScheduler1_AppointmentCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.AppointmentCreatedEventArgs) Handles RadScheduler1.AppointmentCreated

 

 


Dim
spanvalue As TimeSpan

 

spanvalue = e.Appointment.End.Subtract(e.Appointment.Start)

 

 

 

 


End sub

could u please suggest me the way how to save this spanvalue for select employeeid in to database when client click on save button of schedular.

0
Peter
Telerik team
answered on 04 Nov 2009, 09:40 AM
Hello rajinder,

You could use custom attributes to save any additional data for an appoitnment, but you don't really need to do this for your case. You could use the same approach that Shinu suggested, but the other way around - set the ToolTip instead of the Subject like this:

protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)  
{  
    e.Appointment.ToolTip = e.Appointment.Subject+ " (" + e.Appointment.Duration.TotalHours + " hours)";  
}  


Greetings,
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
rajinder singh
Top achievements
Rank 1
answered on 04 Nov 2009, 12:50 PM
thanx peter...yes tooltip is working
 but i want to  save this value into my database so that i can access that  value to calculate total hours of week and prepare salary..please also suggest me if there is any other way prepare salary..please
0
Peter
Telerik team
answered on 09 Nov 2009, 08:20 AM
Hello rajinder,

Please, set CustomAttributeNames="Duration" for RadScheduler, where "Duration" is an existing field or column in your RadScheduler's data source. Optionally, you can set EnableCustomAttributeEditing="true" if you want the Duration custom attribute to be displayed in the advanced form. Then you can handle AppointmentDataBound like this.

protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)
    {
  
        e.Appointment.Attributes["Duration"] = e.Appointment.Duration.TotalHours.ToString();
    }

You access the Duration value in the same way as you set it - e.Appointment.Attributes["Duration"]. However, note that it is of type string so you should convert it to double if you need to perform any arithmetic operations with it.


Greetings,
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.
Tags
Scheduler
Asked by
rajinder singh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
rajinder singh
Top achievements
Rank 1
Peter
Telerik team
Share this question
or