Utöka mallen kalenderhändelse

Vote:
 
Hej, Jag hade tänkt utöka mallen Kalenderhändelse så att man utöver möjligheten att välja återkommande dag även ska kunna välja hur ofta händelsen återkommer, typ varje vecka, varannan vecka, var tredje vecka, en gång i månaden. Som det fungerar nu så finns ju bara möjligheten varje vecka. Har ni några idéer på hur jag skulle kunna åstadkomma detta? Mvh Mattias Olsson
#12830
Nov 09, 2006 13:41
Vote:
 
Jag löste det själv på följande vis genom att utöka EPiServer.WebControls.Calendar. Kommentera gärna brister i koden: using System; using System.Globalization; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using EPiServer; using EPiServer.Core; using EPiServer.WebControls; using EPiServer.DataAbstraction; namespace Extrude.EPi.WebControls { /// /// Summary description for Calendar. /// [ToolboxData("<{0}:Calendar runat=server>")] public class Calendar : EPiServer.WebControls.Calendar { public Calendar() { } protected override void CreateChildControls() { if (EventTemplate == null) return; PageDataCollection pages = GetPages(); if (pages.Count == 0) return; PageData rootPage = null; int dayCnt = 0; int eventCnt = 0; int calendarType = -1; if (this.PageLink != PageReference.EmptyReference) rootPage = GetPage(this.PageLink); if (rootPage.Property.Exists("CalendarType") && rootPage["CalendarType"] != null && rootPage["CalendarType"].ToString().Length > 0) calendarType = Convert.ToInt32(rootPage["CalendarType"]); // Fall tillbaka på dagens datum och 1 år framåt if (this.SelectedDates.Count == 0) { int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); this.SelectedDates.SelectRange(DateTime.Now, DateTime.Now.AddYears(1)); } foreach (DateTime span in this.SelectedDates) { foreach (PageData page in pages) { if (calendarType > -1 && (page.PageTypeID != calendarType)) break; if (page.Property.Exists("EventStartDate")) { DateTime startDate = (DateTime)page["EventStartDate"]; DateTime endDate = (DateTime)page["EventStopDate"]; if (span.Date >= startDate.Date && span.Date <= endDate.Date) { int validDays = 0; int validDaysInterval = 1; // Återkommande dag if (page.Property.Exists("ValidDays") && page["ValidDays"] != null) validDays = Convert.ToInt32(page["ValidDays"]); // Återkommande intervall (ex. 1 = varje vecka, 2 = varannan vecka, 52 = en gång om året osv) if (page.Property.Exists("ValidDaysInterval") && page["ValidDaysInterval"] != null) validDaysInterval = Convert.ToInt32(page["ValidDaysInterval"]); if (validDays > 0) { if (validDaysInterval == 1) { // Varje vecka if (this.IsEventRecurring(page, this.GetDayNumber((int)span.DayOfWeek))) { if (dayCnt < 1 && DayPrefixTemplate != null) this.CreateDayPrefix(span); if (!this.DateIsActive(span)) this.AddActiveDate(span); this.CreateEventTemplate(page, span); dayCnt++; eventCnt++; } } else { // Varannan, var tredje, var fjärde osv int offset = validDaysInterval * 7; if (this.IsEventRecurring(page, this.GetDayNumber((int)span.DayOfWeek))) { DateTime tmp = startDate.AddDays(this.GetDayOfWeekDiff(span, startDate)); TimeSpan daysDiff = span.Subtract(tmp.Date); if (daysDiff.TotalDays % offset == 0) { if (dayCnt < 1 && DayPrefixTemplate != null) this.CreateDayPrefix(span); if (!this.DateIsActive(span)) this.AddActiveDate(span); this.CreateEventTemplate(page, span); dayCnt++; eventCnt++; } } } } else { if (dayCnt < 1 && DayPrefixTemplate != null) this.CreateDayPrefix(span); if (!this.DateIsActive(span)) this.AddActiveDate(span); this.CreateEventTemplate(page, span); dayCnt++; eventCnt++; } } } if (MaxCount > 0 && eventCnt >= MaxCount) break; } if ((DaySuffixTemplate != null) && this.DateIsActive(span)) this.CreateDaySuffix(span); if (MaxCount > 0 && eventCnt >= MaxCount) break; dayCnt = 0; } } private int GetDayOfWeek(DayOfWeek dow) { int[] days = {7, 1, 2, 3, 4, 5, 6}; return days[(int)dow]; } protected int GetDayOfWeekDiff(DateTime dt1, DateTime dt2) { return (this.GetDayOfWeek(dt1.DayOfWeek) - this.GetDayOfWeek(dt2.DayOfWeek)); } } }
#14951
Dec 13, 2006 17:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.