.NET判断某一年的所有放假的日期

时间:2022-06-04 06:11:14

由于工作需求写的一个程序,判断某一年所有的放假日期,根据国家的法定假日和补休日期进行的判断。

        protected void Button1_Click(object sender, EventArgs e)
{
string sql = "";
//2015年1月1日的星期数
int year = ;
int week = ;
for (int month = ; month <= ; month++)
{
int day = ;
switch (month)
{
case :
if (IsLeapYear(year))
{
day = ;
}
else
{
day = ;
}
break;
case :
day = ;
break;
case :
day = ;
break;
case :
day = ;
break;
case :
day = ;
break;
}
for (int a = ; a <= day; a++)
{
string time = string.Format("{0}-{1}-{2}", year, month, a);
if (week == || checkfangjia(time))
{
if (!bufangjia(time))
{ string m = string.Format("INSERT INTO [dbo].[tm_holidays] ([id], [year], [date]) VALUES (N'" + year + "', N'{0} 00:00:00.000');</br>", time);
sql += m;
Response.Write(m);
//Response.Write("2015年" + month + "月" + a + "日" + "星期" + week + "</br>");
}
}
if (week == )
{
week = ;
}
else
{
week++;
}
}
}
}
//判断某一天是否放假
public bool checkfangjia(string day)
{
//所有放假的日期
string[] fangjia = { "2015-1-1", "2015-1-2", "2015-1-3", "2015-2-18", "2015-2-19", "2015-2-20", "2015-2-21", "2015-2-22", "2015-2-23", "2015-2-24", "2015-4-4", "2015-4-5", "2015-4-6", "2015-5-1", "2015-5-2", "2015-5-3", "2015-6-20", "2015-6-21", "2015-6-22", "2015-9-26", "2015-9-27", "2015-10-1", "2015-10-2", "2015-10-3", "2015-10-4", "2015-10-5", "2015-10-6", "2015-10-7" };
foreach (string s in fangjia)
{
if (s.Equals(day))
{
return true;
}
}
return false;
}
//判断某一天是否调休
public bool bufangjia(string day)
{
//与周六 周日调休的日期
string[] bufangjia = { "2015-1-4", "2015-2-15", "2015-2-28", "2015-10-10" };
foreach (string s in bufangjia)
{
if (s.Equals(day))
{
return true;
}
}
return false;
}
//判断平年还是闰年
private bool IsLeapYear(int year)
{
if (year % == )
{
if (year % == )
{
return true;
}
}
else
{
if (year % == )
{
return true;
}
}
return false;
}