温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using System; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Collections; 11
using System.Globalization; 12
using System.Threading; 13
14
using SpaceBuilder.Blogs.Components; 15
using SpaceBuilder.Components; 16
using SpaceBuilder.Configuration; 17
using SpaceBuilder.Utils; 18
using System.Collections.Generic; 19
using TunyNet.Utils; 20
21
namespace SpaceBuilder.Blogs.Controls 22
{ 23
/// <summary> 24
/// 博客日历 25
/// </summary> 26
public class WeblogCalendar : WeblogThemedControl 27
{ 28
protected override void OnLoad(EventArgs e) 29
{ 30
base.OnLoad(e); 31
this.EnsureChildControls(); 32
Bind(); 33
} 34
35
public void Bind() 36
{ 37
新增日历格式 52
53
int month = ValueHelper.SafeInt(Context.Request.QueryString["M"], -1); 54
int year = ValueHelper.SafeInt(Context.Request.QueryString["Y"], -1); 55
int day = ValueHelper.SafeInt(Context.Request.QueryString["D"], -1); 56
57
if (month != -1 && year != -1) 58
{ 59
CurrentDate = new DateTime(year, month, day != -1 ? day : 1); 60
postCalendar.VisibleDate = CurrentDate; 61
} 62
} 63
64
private ArchiveDataItem DataItem(int day) 65
{ 66
if (days == null) 67
{ 68
days = BlogPosts.GetPostsByMonth(this.CurrentWeblog.SectionID, CurrentDate); 69
postCalendar.VisibleDate = CurrentDate; 70
} 71
72
if (days.ContainsKey(day)) 73
return days[day]; 74
else 75
return null; 76
} 77
78
79
private System.Web.UI.WebControls.Calendar postCalendar = null; 80
private DateTime CurrentDate = DateTime.Now; 81
private Dictionary<int, ArchiveDataItem> days = null; 82
83
protected override void AttachChildControls() 84
{ 85
postCalendar = FindControl("PostCalendar") as System.Web.UI.WebControls.Calendar; 86
postCalendar.DayRender += new DayRenderEventHandler(postCalendar_DayRender); 87
postCalendar.VisibleMonthChanged += new MonthChangedEventHandler(postCalendar_VisibleMonthChanged); 88
} 89
90
private void postCalendar_DayRender(object sender, DayRenderEventArgs e) 91
{ 92
e.Cell.Controls.Clear(); 93
int day = e.Day.Date.Day; 94
95
ArchiveDataItem item = DataItem(day); 96
if (!e.Day.IsOtherMonth && item != null) 97
{ 98
HyperLink hl = new HyperLink(); 99
hl.NavigateUrl = BlogUrls.Instance().ShowBlogPostByDay(this.CurrentWeblog.ApplicationKey, item.Date); 100
hl.Text = e.Day.DayNumberText; 101
if (item.Count > 1) 102
hl.ToolTip = item.Count + " 篇文章"; 103
else 104
hl.ToolTip = item.Count + " 篇文章"; 105
106
e.Cell.Controls.Add(hl); 107
} 108
else 109
{ 110
e.Cell.Controls.Add(new LiteralControl(e.Day.DayNumberText)); 111
} 112
113
} 114
115
private void postCalendar_VisibleMonthChanged(object sender, MonthChangedEventArgs e) 116
{ 117
CurrentDate = e.NewDate; 118
} 119
} 120
} 121





}