- Function running environment: Holiday data is stored in the database table in the following format:
// Determine whether the date is a holiday
Private bool isholiday (datetime DT)
{
Database DB = databasefactory. createdatabase ("sqldbconnection ");
String SQL = @ "select count (*)
From [oa_sys_holiday]
Where [date] = @ starttime ";
Bool result = false;
Using (dbcommand comm = dB. getsqlstringcommand (SQL ))
{
DB. addinparameter (Comm, "@ starttime", dbtype. String, DT. tow.datestring ());
If (INT) dB. executescalar (Comm)> 0)
{
Result = true;
}
}
Return result;
}
// Date addition (excluding holidays)
Private datetime adddaywithoutholiday (datetime startdate, int days)
{
While (isholiday (startdate) // skip holidays (ensure that the start time is not a holiday): If the start time is a holiday, locate the end time of the holiday as the start time
{
Startdate = startdate. adddays (1 );
Datetime dt = startdate. date;
Startdate = DT;
}
For (INT I = 0; I <days; I ++)
{
Startdate = startdate. adddays (1 );
If (isholiday (startdate ))
{
Do
{
Startdate = startdate. adddays (1 );
} While (isholiday (startdate ));
}
}
Return startdate;
}