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

Dynamically setting DayBeginsHour in C# code-behind

Asked by Jeff Woods
6 years ago.

Hello Dan,

My telescope observatory app has a varying DayBeginsHour, depending on the season. In the summer, the sun sets closer to 9 pm, and in the winter, closer to 5 pm. I'm trying to get the app to allow me to dynamically alter the hours based on the season, and having mixed success.

I'm in Resources view mode, and trying to alter the hours during the column reconstruction, which happens on every callback, and in particular whenever the date in the navigator changes:

private void BuildColumns()
{
ReservationsPilot.Columns.Clear();

// seasonally adjust business hours here.

SunInfo theSun;
ObservatorySite.Location site = GetSiteFromCookie(ReservationsPilot.StartDate);

theSun = SunInfo.CalculateSunPosition(ReservationsPilot.StartDate, site, true);

ReservationsPilot.DayBeginsHour = theSun.SunSet.AddMinutes(-40).Hour;
ReservationsPilot.DayEndsHour = theSun.SunRise.AddHours(2).Hour;
ReservationsPilot.BusinessBeginsHour = ReservationsPilot.DayBeginsHour;
ReservationsPilot.BusinessEndsHour = ReservationsPilot.DayEndsHour;

for (int i = 0; i < ReservationsPilot.Days; i++)
{
DateTime dateSelected = ReservationsPilot.StartDate.AddDays(i);

Column c = new Column(dateSelected.ToLongDateString(), "Date");
c.Date = dateSelected;
ReservationsPilot.Columns.Add(c);

Column resCol = new Column("Reservations", "Customer");
resCol.Date = dateSelected;
c.Children.Add(resCol);

Column astroCol = new Column("Sun / Moon", "System");
astroCol.Date = dateSelected;
c.Children.Add(astroCol);
}
}

That function is called immediately before every DataBind call, so that should work.... and mostly does.

The problem is the events aren't following suit. When it is time to add an extra hour to the view (sunset is earlier), it does so... but the events do NOT move to their new homes. The events then become "orphaned" an hour away from their true home.

I read the other answer you gave two months ago about how to do this in AfterRender via JavaScript, but I can't do that here because I need access to the values from my Astronomy library (CalculateSunPosition) in order to determine the new values for DayBeginsHour and DayEndsHour. I need to do it in the code-behind, where I have that available.

I also tried using the UpdatePanel method you glossed over in that answer, and could not get it to work.

Can you provide a more complete code example of how one could do this? Thanks!

Jeff Woods
iTelescope.Net

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

Jeff,

There was a problem with passing the updated DayBeginsHour/DayEndsHour to the client side during CallBacks. It's fixed now in build 7.8.3155. See the sandbox:

http://www.daypilot.org/sandbox/

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