2015-10-07 72 views
0

我有一個網站(.Net)使用Daypilot pro(7.9)和ajaxtoolkit:CalendarExtender。 它用於在Dynamics中預約日期,它的功能就像魅力,直到我選擇2016年的日期...當我在2016年選擇日期或週數時,日曆跳回到選定周的前一週。我使用瑞典語格式,唯一的線索是2015年有53周,Daypilot可能會因此而感到困惑?daypilot日曆顯示錯誤的一週

下面是代碼(日期時間選擇器來自ajaxtoolkit)

<div id="divCalendar" runat="server" style="float: left; width: 90px; height:25px; margin-top: 2px;"> 
    <ajaxToolKit:CalendarExtender ID="calendar" runat="server" TargetControlID="dateTimeTextBox" 
     Format="yyyy-MM-dd" PopupButtonID="popupButton" firstDayOfWeek="Monday" /> 
    <asp:TextBox ID="dateTimeTextBox" runat="server" CssClass="inputfields" Width="80px" AutoPostBack="true" 
     OnTextChanged="DateTime_Changed" /> 
    <asp:CompareValidator ID="dateTimeTextBoxFormat" runat="server" ControlToValidate="dateTimeTextBox" 
     Operator="DataTypeCheck" Type="Date" ErrorMessage="yyyy-mm-dd." Display="Dynamic" 
     ValidationGroup="DateTime" /> 
    <asp:RequiredFieldValidator ID="dateTimeTextBoxRequired" runat="server" ControlToValidate="dateTimeTextBox" 
     ErrorMessage="*" Display="Dynamic" ValidationGroup="DateTime" /> 
</div> 
<div id="divCalendarButton" runat="server" style="float: left; width: 39px; margin-right: 12px;"> 
    <asp:Image ID="popupButton" runat="server" ImageUrl="/_imgs/btn_on_cal.gif" Style="cursor: pointer; height: 25px; padding-top: 3px;" /> 
</div> 
<div id="divTime" runat="server" style="margin-left: 7px; padding-top: 3px;"> 
    <asp:DropDownList ID="dropDownHours" runat="server" AutoPostBack="true" /> 
    <asp:DropDownList ID="dropDownMinutes" runat="server" AutoPostBack="true" /> 
</div> 

而這裏的DayPilot部分:

<div style="float: left; padding: 5px;"> 

<DayPilot:DayPilotCalendar ID="dayPilotCalendar" runat="server" DataStartField="Start" 
    DataEndField="End" DataTextField="Name" DataValueField="Id" DataTagFields="ActivityTypeName, ColorCode, Status" 
    BusinessBeginsHour="8" BusinessEndsHour="18" CellDuration="15" CellHeight="13" 
    HeightSpec="BusinessHours" ShowAllDayEvents="true" AllDayEnd="Date" ShowAllDayEventStartEnd="false" 
    EventClickHandling="JavaScript" EventClickJavaScript="viewEvent(e);" EventDoubleClickHandling="JavaScript" 
    EventDoubleClickJavaScript="editEvent(e);" DataAllDayField="WholeDayActivity" 
    TimeRangeSelectedHandling="JavaScript" TimeRangeSelectedJavaScript="createEvent(start, end, resource);" 
    TimeRangeDoubleClickHandling="JavaScript" TimeRangeDoubleClickJavaScript="createEvent(start, end, resource);" 
    ContextMenuID="DayPilotMenuActivity" OnBeforeEventRender="OnBeforeEventRender" 
    BubbleID="ActivityCalendarBubble" ShowToolTip="false"> 
</DayPilot:DayPilotCalendar> 

我希望有人可以幫助我找到解決辦法離子爲此。客戶感到惱火,他們不得不選擇他們想要在日曆中打開的那個星期後一週= P

+0

您是否檢查過您分配給DayPilotCalendar.StartDate更改視圖的日期?這是對的嗎? – Dan

回答

0

Thx Dan,這是問題所在。 我從辦公室裏的英雄那裏得到了幫助,幫助我把正確的約會交給了。開始日期!

我們從這個變化:

public static DateTime GetDateFromWeekNumber(int year, int weekNumber) 
    { 
     DateTime date = new DateTime(year, 1, 1); 
     date = date.AddDays(7 * (weekNumber - 1)); 
     date = date.AddDays(-(int)date.DayOfWeek + 1); 

     return date; 
    } 

要這樣:

public static DateTime GetFirstDayOfWeek(DateTime dayInWeek) 
    { 
     CultureInfo cultureInfo = CultureInfo.CurrentCulture; 

     DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek; 
     DateTime firstDayInWeek = dayInWeek.Date; 
     while (firstDayInWeek.DayOfWeek != firstDay) 
      firstDayInWeek = firstDayInWeek.AddDays(-1); 

     return firstDayInWeek; 
    } 

而現在它可以作爲一個魅力!不是Daypilot,只是舊代碼= D