技术文章 > 带农历的日历

带农历的日历

2018-08-22 01:39

文档管理软件,文档管理系统,知识管理系统,档案管理系统的技术资料:
如需要定制,将参数定义部分提出来就行了。
CNDate类可以到网上找到开源代码。看看效果
[code]
csharp
private static string[] mArrWeekText = new string[]{"日","一","二","三","四","五","六"};
/*
* rSelectedDt :选定的DateTime
* rDayLink : 加在日期上的链接
*
*/
public string DrawCalendar(DateTime rSelectedDt,string rDayLink)
{
StringBuilder _sb = new StringBuilder();
_sb.Append("");
_sb.Append("");
for(int i=0;i {
_sb.Append("
");
}
DateTime next_month_dt = DateTime.Parse(rSelectedDt.Year+"-"+rSelectedDt.AddMonths(1).Month+"-1");
DateTime first_day_dt = DateTime.Parse(rSelectedDt.Year+"-"+rSelectedDt.Month+"-1");
int _MaxYear = DateTime.Now.Year;
int _SelectedMonth = rSelectedDt.Month;
int _SelectedYear = rSelectedDt.Year;
int _SelectedDay = rSelectedDt.Day;
int _FirstDayOfWeek = 0;
int _SelectedMonthDays = next_month_dt.AddDays(-1).Day;

switch(first_day_dt.DayOfWeek)
{
case DayOfWeek.Monday:
_FirstDayOfWeek = 1;
break;
case DayOfWeek.Tuesday:
_FirstDayOfWeek = 2;
break;
case DayOfWeek.Wednesday:
_FirstDayOfWeek = 3;
break;
case DayOfWeek.Thursday:
_FirstDayOfWeek = 4;
break;
case DayOfWeek.Friday:
_FirstDayOfWeek = 5;
break;
case DayOfWeek.Saturday:
_FirstDayOfWeek = 6;
break;
case DayOfWeek.Sunday:
_FirstDayOfWeek = 0;
break;
}

int _dayofweek = _FirstDayOfWeek;
if(_dayofweek>0)
{
_sb.Append("");
for(int i=0;i<_FirstDayOfWeek;i++)
{
_sb.Append("");
}
}

string class_commonday = "cl_commonday";
string class_daylink = "cl_weekendday";
string nl_day = "";
for(int i=1;i<=_SelectedMonthDays;i++)
{
DateTime dt = DateTime.Parse(rSelectedDt.Year+"-"+rSelectedDt.Month+"-"+i);
nl_day = new CNDate(dt).GetLunarHolDay();

if(i==rSelectedDt.Day)
class_commonday = "cl_selectedday";
else if(i==DateTime.Now.Day)
class_commonday = "cl_today";
else
class_commonday = "cl_commonday";

if(i==rSelectedDt.Day)
class_daylink = "cl_curdaylink";
else if(_dayofweek==0 || _dayofweek==6)
class_daylink = "cl_weekendlink";
else
class_daylink = "cl_daylink";

if(_dayofweek==0)
_sb.Append("");
_dayofweek = 0;
}
else
{
_sb.Append("");
_dayofweek++;
}
}

if(_dayofweek<6)
{
for(int i=0;i<6-_dayofweek+1;i++)
{
_sb.Append("");
}
_sb.Append("");
}
_sb.Append("");
_sb.Append("
");
_sb.Append(mArrWeekText[i]);
_sb.Append("
");
else
_sb.Append("
");

_sb.Append(" _sb.Append(rSelectedDt.Year+"-"+rSelectedDt.Month+"-"+i);
_sb.Append("\" title="农历"+nl_day+"" class=""+class_daylink+"">"+i.ToString()+"
");
if(_dayofweek==6)
{
_sb.Append("
");
return _sb.ToString();
}
[/code]