前几天领导给我任务是:写一个日程管理功能.
在此以前没有写过这样的功能,接到任务,没有一点思路.
最后在网上找了些资料,但是没有找的什么好的资料.只找到可以用 Calendar 控件来实现.
最后我花了天的时间写好了日程管理功能,现在我把它拿出来和大家分享,也希望各位多多指教.
1.我要说的是主要用Calendar 控件的 DayRender 事件
/// <summary>
/// 读取日程信息和设置日程日历
/// 周海军 2007-03-06
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void calSchedule_DayRender(object sender, DayRenderEventArgs e)
{
// 自定义显示内容
// 获取表示呈现在Calendar控件中的日期
CalendarDay d = ((DayRenderEventArgs)e).Day;
CalendarDay day = e.Day;
// 获取表示呈现在Calendar控件中的单元格
TableCell c = ((DayRenderEventArgs)e).Cell;
//c.Width =230;
// 创建农历转换类
// Lunar lr = new Lunar();
if (d.IsOtherMonth)
{
c.Controls.Clear();
}
else
{
DateTime FDate = new DateTime();
string Subject;
DateTime Date = new DateTime();
Date = d.Date;
try
{
c.Controls.Clear();
//显示当天日期,并且超链接
c.Controls.Add(new LiteralControl("<a href='SchedByDay.aspx?date=" + d.Date.Year.ToString() + "-" + d.Date.Month.ToString() + "-" + d.Date.Day.ToString() + "' style='color:#003080;FONT-SIZE: 12px;'>" + d.Date.Day.ToString() + "</a>"));
c.Controls.Add(new LiteralControl(" " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "));
// 显示超链接,自定义一个HyperLink,并设置好属性
HyperLink aHyperLink = new HyperLink();
aHyperLink.ImageUrl = "../images/add_small.gif";
aHyperLink.ToolTip = "新增个人日程";
aHyperLink.NavigateUrl = "Plan_AddEdit.aspx?Id=add&date=" + d.Date.Year.ToString() + "-" + d.Date.Month.ToString() + "-" + d.Date.Day.ToString() + "";
//
c.Controls.Add(aHyperLink);
}
catch (Exception exc)
{
Response.Write(exc.ToString());
}
// 读出该天的信息
Plan_Day plan_day=new Plan_Day();
DataTable Dt = Plan_DayInfo.Plan_GetBy_DateAndUser(Date.ToString("yyyy-MM-dd"),InUser);
// 显示该天所有信息
try
{
if(Dt!=null)
{
for (int i = 0; i < Dt.Rows.Count; i++)
{
// 得到日程主键PlanID
int PlanID = Int32.Parse(Dt.Rows[i]["Plan_ID"].ToString());
// 得到日程安排日期
FDate = DateTime.Parse(Dt.Rows[i]["Plan_Date"].ToString());
// 只获取小时和分钟部分
string FDate_hour = FDate.Hour.ToString();
string FDate_Minute = FDate.Minute.ToString();
if (FDate_Minute == "0")
{
FDate_Minute = "00";
}
// 得到日程标题
Subject = Dt.Rows[i]["Plan_Subject"].ToString();
// 只取标题的前4位
if (Subject.Length > 4)
{
Subject = Subject.Substring(0, 4);
Subject += "..";
}
HtmlAnchor a = new HtmlAnchor();
// 指向日程的详细信息
a.HRef = "Plan_AddEdit.aspx?Id=" + PlanID + "";
a.InnerText = "☉"+Subject+"";
a.Attributes.Add("style", "FONT-SIZE: 12px;");
c.Controls.Add(new LiteralControl(" " + " " + " " + " "));
c.Controls.Add(new LiteralControl("<br>"));
c.Controls.Add(a);
}
e.Cell.Attributes["onmouseout"] = "JavaScript:this.style.backgroundColor='';";
e.Cell.Attributes["onmouseover"] = "JavaScript:this.style.backgroundColor='#e8e8e8';";
}
}
catch
{
return;
}
}
}
我现在把代码也提供给大家:希望多多意见 下载源代码