search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Set different business hours for different days

Asked by Anonymous
9 years ago.

Hello,

I am evaluating your DayPilot Calendar Pro and am having problems getting business days to set.
I have followed all your examples, with no luck.

In my app, users will be able to define their own schedules. This information is stored in the database (sql server 2005).

I have an example in my database where a user works, Monday 3:00 pm to 8:00 pm, Tuesday 9:00 am to 6:00 pm, Friday 2:00 pm to 6:00 pm, Saturday 9:00 am to 8:00 pm.

Since each day is different I am using your beforecellrender event. (I guess I will have to store working days in an array in order to not hit the database each time a cell is rendered).

I have tried many different ways to accomplish this and have provided examples below

Basically, on each day, I need to set the days business start/end date/time using information from my db like

Dim dc As New SalonDataClassesDataContext

For Each DOW In dc.vWorkDays

Dim dhs As Integer = DOW.StartTime.Hour
Dim dhe As Integer = DOW.EndTime.Hour

CalSchedules.BusinessBeginsHour = dhs
CalSchedules.BusinessEndsHour = dhe
CalSchedules.Date = DOW.WeekDay

Next


Can something like this be done using your control?

Thanks,

Sheri

UNSUCCESSFULL ATTEMPTS BELOW


Protected Sub CalSchedules_BeforeCellRender(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.BeforeCellRenderEventArgs) Handles CalSchedules.BeforeCellRender
Dim dc As New SalonDataClassesDataContext

For Each DOW In dc.vWorkDays
If e.Start.DayOfWeek.ToString = DOW.WorkDay.Trim Then
Dim st As Integer = e.Start.Hour
Dim se As Integer = e.End.Hour

If e.Start.Hour >= DOW.StartTime.Hour And e.End.Hour <= DOW.EndTime.Hour Then
e.IsBusiness = True
Else
e.IsBusiness = False
End If
End If
Next

End Sub
Protected Sub CalSchedules_BeforeCellRender(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.BeforeCellRenderEventArgs) Handles CalSchedules.BeforeCellRender
Dim dc As New SalonDataClassesDataContext

For Each DOW In dc.vWorkDays
If e.Start.DayOfWeek.ToString = DOW.WorkDay.Trim Then
Dim st As Integer = e.Start.Hour
Dim se As Integer = e.End.Hour


'If Me.CalSchedules.BusinessBeginsHour <= DOW.StartTime.Hour Then
' Dim st As String = e.Start.Hour.ToString
' Dim dhs As Integer = DOW.StartTime.Hour
' Dim dhe As Integer = DOW.EndTime.Hour

' CalSchedules.BusinessBeginsHour = dhs
' CalSchedules.BusinessEndsHour = dhe
' e.IsBusiness = True

'ElseIf Me.CalSchedules.BusinessBeginsHour >= DOW.StartTime.Hour Then
' Dim dhs As Integer = DOW.StartTime.Hour
' Dim dhe As Integer = DOW.EndTime.Hour

' CalSchedules.BusinessBeginsHour = dhs
' CalSchedules.BusinessEndsHour = dhe
' e.IsBusiness = True
'Else
' e.IsBusiness = False
'End If

'' If e.Start.Hour >= Me.CalSchedules.BusinessBeginsHour And e.Start.Hour <= Me.CalSchedules.BusinessEndsHour Then
'' Dim wd As String = DOW.WorkDay.ToString.Trim


'' ' If ea.Hour >= CalSchedules.BusinessBeginsHour Then
' CalSchedules.BusinessBeginsHour = dhs
' CalSchedules.BusinessEndsHour = dhe
' e.IsBusiness = True
' End If
End If
Next
'Dim s As New Scheduling
's.CheckDay(Me.CalSchedules, e)
'Me.UpdatePanelCalendar.Update()
End Sub


Answer posted by Dan Letecky [DayPilot]
8 years ago.

The BusinessBeginsHour and BusinessEndsHour properties should only be set once and before the cells are generated (i.e. before BeforeCellRender). Chaning BusinessBeginsHour inside BeforeCellRender handler has no effect.

Inside BeforeCellRender handler, you can change the IsBusiness status separately for each cell:

    protected void DayPilotCalendar1_BeforeCellRender(object sender, BeforeCellRenderEventArgs e)
    {
        if ((e.Start.DayOfWeek == DayOfWeek.Saturday || e.Start.DayOfWeek == DayOfWeek.Sunday)
            || (e.Start.Hour >= 9 && e.Start.Hour < 18))
        {
            e.IsBusiness = true;
        }
   }

See also:
http://www.daypilot.org/calendar-business-hours.html

This question is more than 3 months old and has been closed. Please create a new question if you have anything to add.