110,571
社区成员
发帖
与我相关
我的任务
分享
protected void cldLunarCalendar_DayRender(object sender, DayRenderEventArgs e)
{
UserInfo user = (UserInfo)Session["CurrentUser"];
//自定义显示内容
CalendarDay calDay = ((DayRenderEventArgs)e).Day;
//获取表示呈现在控件中的单元格
TableCell tc = ((DayRenderEventArgs)e).Cell;
//农历转换对象
//CNDate dt = new CNDate(calDay.Date);
LunarDate dt = new LunarDate(calDay.Date);
if (calDay.IsOtherMonth)
{
tc.Controls.Clear();
}
else
{
try
{
HyperLink aHyperLink = new HyperLink();
aHyperLink.ImageUrl = "~/images/add_Schedule.gif";
aHyperLink.ToolTip = "新增个人日程";
aHyperLink.NavigateUrl = "SaveMySchedule.aspx?userid=0&scheduleId=0&today=" + calDay.Date.ToShortDateString();
tc.Controls.Add(new LiteralControl(" " + " " + " "));
tc.Controls.Add(aHyperLink);
tc.Controls.Add(new LiteralControl("<br>" +dt.GetLunarHolDay()));
IList<int> scheduleList = ScheduleManager.GetScheduleIdList(user.UserId, calDay.Date.ToShortDateString());
foreach (int scheduleId in scheduleList)
{
if (scheduleId != 0)
{
Schedule schedule = ScheduleManager.GetScheduleByScheduleId(scheduleId);
HtmlAnchor ha = new HtmlAnchor();
ha.HRef = "SaveMySchedule.aspx?scheduleId=" + schedule.ScheduleId.ToString() + "&userid=0&today=" + "";
ha.InnerText = "◎" + schedule.BeginTime.Hour.ToString() + ":" + schedule.BeginTime.Minute.ToString() + " " + schedule.Title.Substring(0, 3) + "...";
tc.Controls.Add(new LiteralControl(" " + " " + " "));
tc.Controls.Add(new LiteralControl("<br>"));
tc.Controls.Add(ha);
tc.Controls.Add(new LiteralControl("<br>"));
}
}
}
catch (Exception exc)
{
Response.Write(exc.ToString());
}
e.Cell.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';";
e.Cell.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
}
}
protected void Page_Load(object sender, EventArgs e)
{
createCalendar(2008,12);//输入参数进行测试
}
private void createCalendar(int year,int month)
{
int days = DateTime.DaysInMonth(year,month);//得到当月的天数
DateTime dt = new DateTime(year,month, 1);
int weeke =Convert.ToInt32(dt.DayOfWeek.ToString("d"));//得到当月的第一天是星期几
string[,] cal=new string[7,6];//创建一个二维数组来存放日期
for (int day= 1; day<= days;day++ )
{
int x = (day + weeke - 1) % 7;//根据星期的规律循环x轴坐标
int y = (day + weeke - 1) / 7;//根据(月/星期)循环Y轴坐标
for (int j = 0; j < 6;j++ )
{
for (int i = 0; i < 7;i++ )
{
cal[x, y] = day.ToString();//开始赋值
}
}
}
//输出
System.Text.StringBuilder st = new System.Text.StringBuilder();
st.Append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"1\">");
st.Append("<thead><th> 星期天</th><th>星期一</th><th>星期二</th><th> 星期三</th><th>星期四</th><th>星期五</th><th> 星期六</th></thead>");
for(int i=0;i<6;i++)
{
st.Append("<tr>");
for(int j=0;j<7;j++)
{
st.Append("<td>"+cal[j,i]+"</td>");
}
st.Append("</tr>");
}
st.Append("</table>");
Response.Write(st);
Response.End();
}