@helper SignInCalender(DateTime argDate)
{
DateTime vFirstDay = new DateTime(argDate.Year, argDate.Month, 1);
int vLastday = argDate.AddMonths(1).AddDays(-1).Day;//获取当月的最后一天
int vWeek = (int)vFirstDay.DayOfWeek;//获取当年当月1号的星期
int vMaxCells = 28;//页面上最多显示的单元格数
int vPrdictDays = vLastday + vWeek;
if (vPrdictDays > 35)
{
vMaxCells = 42;
}
else if (vPrdictDays > 28)
{
vMaxCells = 35;
}
System.Web.Mvc.TagBuilder tagTable = new System.Web.Mvc.TagBuilder("table");
tagTable.InnerHtml = "<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td></tr>";
int vDay = 1;
System.Web.Mvc.TagBuilder tagFirsTR = new System.Web.Mvc.TagBuilder("tr");
for (int j = 0; j < vMaxCells; j++)
{
System.Web.Mvc.TagBuilder tagTd = new System.Web.Mvc.TagBuilder("td");
string vDays = string.Empty;
if (j >= vWeek && vDay <= vLastday)
{
vDays = vDay.ToString();
vDay++;
}
tagTd.SetInnerText(vDays);
tagFirsTR.InnerHtml += tagTd.ToString();
if ((j+1) % 7 == 0)
{
tagTable.InnerHtml += tagFirsTR.ToString();
tagFirsTR.InnerHtml = string.Empty;
}
}
@System.Web.Mvc.MvcHtmlString.Create(tagTable.ToString());
}