A Calendar that is smart enough to know the entries that go along with it
상속: System.Web.UI.WebControls.Calendar
예제 #1
0
        /// <summary>
        /// Gets the entries for this month that we will be rendering
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void calendarMonth_PreRender(object sender, EventArgs e)
        {
            Control           root           = contentPlaceHolder;
            SiteConfig        siteConfig     = SiteConfig.GetSiteConfig();
            string            languageFilter = Request.Headers["Accept-Language"];
            MonthViewCalendar eventSource    = sender as MonthViewCalendar;

            requestPage = Page as SharedBasePage;

            // if we adjust for time zones (we don't show everything in UTC), we get the entries
            // using the configured time zone.
            eventSource.EntriesThisMonth = new EntryCollection();
            if (siteConfig.AdjustDisplayTimeZone)
            {
                //Store away these Entries for the DayRender step...
                eventSource.EntriesThisMonth = requestPage.DataService.GetEntriesForMonth(eventSource.VisibleDate, siteConfig.GetConfiguredTimeZone(), languageFilter);
            }
            else
            {
                //Store away these Entries for the DayRender step...
                eventSource.EntriesThisMonth = requestPage.DataService.GetEntriesForMonth(eventSource.VisibleDate, new Util.UTCTimeZone(), languageFilter);
            }
        }
예제 #2
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
			resmgr = ((System.Resources.ResourceManager)ApplicationResourceTable.Get());
			requestPage = Page as SharedBasePage;

			#region Setup Year Hyperlinks
			DateTime[] daysWithEntries = null;

			//Print out a list of all the years that have entries
			// with links to the Year View
			if ( requestPage.SiteConfig.AdjustDisplayTimeZone )
			{
				daysWithEntries = requestPage.DataService.GetDaysWithEntries(requestPage.SiteConfig.GetConfiguredTimeZone());
			}
			else
			{
				daysWithEntries = requestPage.DataService.GetDaysWithEntries(new newtelligence.DasBlog.Util.UTCTimeZone());
			}

            var years = new SortedSet<int>();
			foreach (DateTime date in daysWithEntries) years.Add(date.Year);
			foreach(int year in years.Reverse<int>())
			{
				HyperLink h = new HyperLink();
				h.NavigateUrl = GetUrlWithYear(year);
				h.Text = year.ToString();
				contentPlaceHolder.Controls.Add(h);

				Literal l = new Literal();
				l.Text = "&nbsp;";
				contentPlaceHolder.Controls.Add(l);
           	}
	
			Literal l2 = new Literal();
			l2.Text = "<br /><br />";
			contentPlaceHolder.Controls.Add(l2);
			#endregion

			#region Year View
			//I know this could be cleaner and the Year viewing code could better share the Month viewing code
			// but they are sufficiently different that I chose to keep them fairly separate
			if (Request.QueryString["year"] != null)
			{
				int year = int.Parse(Request.QueryString["year"]);
				int monthsInYear = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar.GetMonthsInYear(year);
				for(int i = 1; i <= monthsInYear; i++)
				{
					MonthViewCalendar c = new MonthViewCalendar();

					ApplyCalendarStyles(c);

					c.DayRender += new DayRenderEventHandler(calendarMonth_DayRender);
					c.VisibleMonthChanged += new MonthChangedEventHandler(calendarMonth_VisibleMonthChanged);
					c.SelectionChanged += new EventHandler(calendarMonth_SelectionChanged);
					c.PreRender += new EventHandler(calendarMonth_PreRender);

					//Don't show the Next/Prev for the Year Calendar 
					c.ShowNextPrevMonth = false;

					//Tell this Calendar to show a specific month
					c.VisibleDate = new DateTime(year, i, 1);

					contentPlaceHolder.Controls.Add(c);
				}
				requestPage.TitleOverride = year.ToString();
			}
			#endregion
			else //Month View
			#region Month View
			{
				//Setup the Event Handlers for the Calendar
				calendarMonth.DayRender += new DayRenderEventHandler(calendarMonth_DayRender);
				calendarMonth.VisibleMonthChanged += new MonthChangedEventHandler(calendarMonth_VisibleMonthChanged);
				calendarMonth.SelectionChanged += new EventHandler(calendarMonth_SelectionChanged);
				calendarMonth.PreRender += new EventHandler(calendarMonth_PreRender);

				ApplyCalendarStyles(calendarMonth);
			
				contentPlaceHolder.Controls.Add(calendarMonth);

				//Default to this month, otherwise parse out a yyyy-MM
				if ( Request.QueryString["month"] == null ) 
				{
					_month = DateTime.Now.Date;
				}
				else
				{
					try 
					{
						_month = DateTime.ParseExact(Request.QueryString["month"],"yyyy-MM", System.Globalization.CultureInfo.InvariantCulture);
					}
					catch 
					{
					}
				}
			
				//Set the title, and tell the calendar to show today
				requestPage.TitleOverride = _month.ToString("MMMM, yyyy");
				calendarMonth.VisibleDate = _month;
			}
			#endregion
		}
예제 #3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            resmgr      = ((System.Resources.ResourceManager)ApplicationResourceTable.Get());
            requestPage = Page as SharedBasePage;

            #region Setup Year Hyperlinks
            DateTime[] daysWithEntries = null;

            //Print out a list of all the years that have entries
            // with links to the Year View
            if (requestPage.SiteConfig.AdjustDisplayTimeZone)
            {
                daysWithEntries = requestPage.DataService.GetDaysWithEntries(requestPage.SiteConfig.GetConfiguredTimeZone());
            }
            else
            {
                daysWithEntries = requestPage.DataService.GetDaysWithEntries(new newtelligence.DasBlog.Util.UTCTimeZone());
            }

            var years = new SortedSet <int>();
            foreach (DateTime date in daysWithEntries)
            {
                years.Add(date.Year);
            }
            foreach (int year in years.Reverse <int>())
            {
                HyperLink h = new HyperLink();
                h.NavigateUrl = GetUrlWithYear(year);
                h.Text        = year.ToString();
                contentPlaceHolder.Controls.Add(h);

                Literal l = new Literal();
                l.Text = "&nbsp;";
                contentPlaceHolder.Controls.Add(l);
            }

            Literal l2 = new Literal();
            l2.Text = "<br /><br />";
            contentPlaceHolder.Controls.Add(l2);
            #endregion

            #region Year View
            //I know this could be cleaner and the Year viewing code could better share the Month viewing code
            // but they are sufficiently different that I chose to keep them fairly separate
            if (Request.QueryString["year"] != null)
            {
                int year         = int.Parse(Request.QueryString["year"]);
                int monthsInYear = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar.GetMonthsInYear(year);
                for (int i = 1; i <= monthsInYear; i++)
                {
                    MonthViewCalendar c = new MonthViewCalendar();

                    ApplyCalendarStyles(c);

                    c.DayRender           += new DayRenderEventHandler(calendarMonth_DayRender);
                    c.VisibleMonthChanged += new MonthChangedEventHandler(calendarMonth_VisibleMonthChanged);
                    c.SelectionChanged    += new EventHandler(calendarMonth_SelectionChanged);
                    c.PreRender           += new EventHandler(calendarMonth_PreRender);

                    //Don't show the Next/Prev for the Year Calendar
                    c.ShowNextPrevMonth = false;

                    //Tell this Calendar to show a specific month
                    c.VisibleDate = new DateTime(year, i, 1);

                    contentPlaceHolder.Controls.Add(c);
                }
                requestPage.TitleOverride = year.ToString();
            }
            #endregion
            else             //Month View
            #region Month View
            {
                //Setup the Event Handlers for the Calendar
                calendarMonth.DayRender           += new DayRenderEventHandler(calendarMonth_DayRender);
                calendarMonth.VisibleMonthChanged += new MonthChangedEventHandler(calendarMonth_VisibleMonthChanged);
                calendarMonth.SelectionChanged    += new EventHandler(calendarMonth_SelectionChanged);
                calendarMonth.PreRender           += new EventHandler(calendarMonth_PreRender);

                ApplyCalendarStyles(calendarMonth);

                contentPlaceHolder.Controls.Add(calendarMonth);

                //Default to this month, otherwise parse out a yyyy-MM
                if (Request.QueryString["month"] == null)
                {
                    _month = DateTime.Now.Date;
                }
                else
                {
                    try
                    {
                        _month = DateTime.ParseExact(Request.QueryString["month"], "yyyy-MM", System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch
                    {
                    }
                }

                //Set the title, and tell the calendar to show today
                requestPage.TitleOverride = _month.ToString("MMMM, yyyy");
                calendarMonth.VisibleDate = _month;
            }
            #endregion
        }
예제 #4
0
        private void calendarMonth_DayRender(object sender, DayRenderEventArgs e)
        {
            SharedBasePage    requestPage = this.Page as SharedBasePage;
            MonthViewCalendar eventSource = sender as MonthViewCalendar;

            // This is a standard text label with just the day.  This may get tossed later when
            // we add a HyperLink for those days that have entries.  Otherwise, this serves to
            // override the default LinkButton/PostBack behavior.
            e.Cell.Controls.Clear();
            Literal day = new Literal();

            day.Text = e.Day.DayNumberText;
            e.Cell.Controls.Add(day);

            //For every entry this month, see if we have to render it in this day.
            // I'm sure there are cleaner and faster ways to get this, but I'm using OutputCaching
            // in the ASCX page, so I don't feel so bad.  It's inefficient, but it's largely cached.
            bool controlsCleared = false;

            foreach (Entry entry in eventSource.EntriesThisMonth)
            {
                if (e.Day.Date == entry.CreatedLocalTime.Date)
                {
                    if (controlsCleared == false)
                    {
                        controlsCleared = true;
                        //Override the default LinkButton and PostBack stuff and
                        // replace with a simpler HyperLink Control.
                        e.Cell.Controls.Clear();
                        HyperLink dayLink = new HyperLink();
                        dayLink.Text        = e.Day.DayNumberText;
                        dayLink.NavigateUrl = SiteUtilities.GetDayViewUrl(requestPage.SiteConfig, e.Day.Date);
                        e.Cell.Controls.Add(dayLink);
                    }
                    e.Day.IsSelectable = false;
                    Literal lit = new Literal();
                    lit.Text = "<br />";
                    e.Cell.Controls.Add(lit);

                    HyperLink link = new HyperLink();
                    link.Text        = (entry.Title != null ? entry.Title : TruncateDotDotDot(entry.Content));
                    link.NavigateUrl = SiteUtilities.GetPermaLinkUrl(requestPage.SiteConfig, (ITitledEntry)entry);
                    e.Cell.Controls.Add(link);
                    e.Day.IsSelectable = true;

                    //Poorman's spacer
                    Literal lit2 = new Literal();
                    lit2.Text = "<br />-<br />";
                    e.Cell.Controls.Add(lit2);
                }
            }

            // Because we are using the CssClass property, we explicitely want to check
            // whether a day is both weekend _and_ lastmonth.
            // Otherwise this day would show up either
            // with 'hCalendarOtherMonthStyle' or with 'hCalendarWeekendStyle'.
            if ((e.Day.IsWeekend) && (e.Day.IsOtherMonth))
            {
                e.Cell.CssClass = "lCalendarOtherMonthWeekendStyle";
            }
        }