这是我在做BLOG时的处理方法,没什么实际价值*_+,在这里帖出来 !
顺便帮下朋友…………
http://community.csdn.net/Expert/topic/4716/4716187.xml?temp=.4245722
如下:
private void BlogCal_PreRender(object sender, System.EventArgs e)
{
#region 建立日历前的星期名处理
Thread threadCurrent = Thread.CurrentThread;
CultureInfo ciNew = (CultureInfo)threadCurrent.CurrentCulture.Clone();
ciNew.DateTimeFormat.DayNames = new string[]{"日","一","二","三","四","五","六"};
ciNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
threadCurrent.CurrentCulture = ciNew;
//System.Globalization.CultureInfo cInfo =
(System.Globalization.CultureInfo)System.Globalization.CultureInfo.CurrentCulture.Clon
e();
//cInfo.DateTimeFormat.DayNames =new String[]{"周一","二","三","四","五","六","七
"};
//System.Threading.Thread.CurrentThread.CurrentCulture = cInfo ;
#endregion
}
private void BlogCal_DayRender(object sender,
System.Web.UI.WebControls.DayRenderEventArgs e)
{
#region 处理有日志的天数和日历的风格
//该控件在创建每一天时发生。
CalendarDay d = ((DayRenderEventArgs)e).Day;
//Common.JS(d.Date.Month.ToString());
//Common.JS(d.Date.Day.ToString());
TableCell c = ((DayRenderEventArgs)e).Cell;
// 初始化当前月有Blog的日期数组
if( intPreMonth == 0 )
{
intPreMonth = d.Date.Month; // 注意:日历控件初始化时我们得到的第一个月并不是当前
月,而是前一个月的月份
intCurrentMonth = intPreMonth+1;
//Common.JS(intCurrentMonth.ToString());
if (intCurrentMonth>12)
intCurrentMonth=1 ;
intNextMonth = intCurrentMonth+1;
if (intNextMonth >12)
intNextMonth =1;
arrPreDays = getArrayDay(d.Date.Year,intPreMonth); //得到前一个月有blog的日期数组
arrCurrentDays = getArrayDay(d.Date.Year,intCurrentMonth) ;//得到当月有blog的日期
数组
//Common.JS(arrCurrentDays.ToString());
arrNextDays = getArrayDay(d.Date.Year,intNextMonth) ;//得到下个月有blog的日期数组
}
int j=0;
if( d.Date.Month.Equals(intPreMonth) )
{
while( ! arrPreDays[j].Equals(0) )
{
if(d.Date.Day.Equals(arrPreDays[j]))
{
c.Controls.Clear();
c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/default.aspx?log_Year="+d.Date.Year+"&log_Month="+d.Date.Month+"&log_Day="+d.Dat
e.Day+"' title='查看该天发表的日志'><font color=#C04000>"+d.Date.Day+"</font></a>"));
//c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/"+d.Date.Year+"/"+d.Date.Month+"/"+d.Date.Day+"/' title='查看该天发表的日志
'><font color=#C04000>"+d.Date.Day+"</font></a>"));
}
j++;
}
}
else if( d.Date.Month.Equals(intCurrentMonth) )
{
while( ! arrCurrentDays[j].Equals(0) )
{
if(d.Date.Day.Equals(arrCurrentDays[j]))
{
c.Controls.Clear();
c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/default.aspx?log_Year="+d.Date.Year+"&log_Month="+d.Date.Month+"&log_Day="+d.Dat
e.Day+"' title='查看该天发表的日志'><font color=#C04000>"+d.Date.Day+"</font></a>"));
//c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/"+d.Date.Year+"/"+d.Date.Month+"/"+d.Date.Day+"/' title='查看该天发表的日志
'><font color=#C04000>"+d.Date.Day+"</font></a>"));
//Common.JS(intCurrentMonth.ToString());
}
j++;
}
}
else if( d.Date.Month.Equals(intNextMonth) )
{
while( ! arrNextDays[j].Equals(0) )
{
if(d.Date.Day.Equals(arrNextDays[j]))
{
c.Controls.Clear();
c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/default.aspx?log_Year="+d.Date.Year+"&log_Month="+d.Date.Month+"&log_Day="+d.Dat
e.Day+"' title='查看该天发表的日志'><font color=#C04000>"+d.Date.Day+"</font></a>"));
//c.Controls.Add(new LiteralControl("<a
href="http://www.tyblog.com/"+d.Date.Year+"/"+d.Date.Month+"/"+d.Date.Day+"/' title='查看该天发表的日志
'><font color=#C04000>"+d.Date.Day+"</font></a>"));
}
j++;
}
}
#endregion
}
// 得到该月有blog的日期数组
private int[] getArrayDay(int intYear,int intMonth)
{
#region 获得有日志的日期 存放到数组 公用
int[] intArray = new int[31];
int i=0;
//从数据库里选取符合要求的记录,将日期存入数组
string strSql = "select * from blog_Content where year(log_PostTime)="+intYear+"
and month(log_PostTime)="+intMonth;
//处理年 交给SQL来处理
SqlCommand cmd=new SqlCommand(strSql,cn2);
cn2.Open();
SqlDataReader dr =cmd.ExecuteReader();
while(dr.Read())
{
if( i==0 )
{
intArray[i] = int.Parse(dr["log_PostDay"].ToString());//dr.GetDateTime(0).Day;
i++;
}
else if(int.Parse(dr["log_PostDay"].ToString())!= intArray[i-1]) //if(
dr.GetDateTime(0).Day != intArray[i-1] )
{
intArray[i] = int.Parse(dr["log_PostDay"].ToString());//dr.GetDateTime(0).Day;
i++;
}
}
dr.Close();
cn2.Close();
return intArray;
#endregion
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=773453