0
public static bool IsHoliday(this DateTime date)
{
  mySqlCommand.CommandType = CommandType.Text;
  mySqlCommand.CommandText = "Select date from HolidayTable”
  SqlDataReader sqlreader = mySqlCommand.ExecuteReader();

  List<DateTime> holidays = new List<DateTime>();  

  while (sqlreader.Read())
  {
      list.Add(reader.GetDateTime(0));
  }    
  holidays.ToArray();
  return holidays.Contains(date.Date);
}

我将如何从我的数据库中加载假期?

替换这个硬代码。

DateTime[] holidays =
new DateTime[] { 
new DateTime(2013,12,27),
new DateTime(2013,12,28)};

它将添加到已在 AddWorkDays() 上排除星期日和星期六的 DateTimeExtensions

4

1 回答 1

0
public static bool IsHoliday(this DateTime date)
{
ConnectionStringSettings myConnectionString = ConfigurationManager.ConnectionStrings["System.Properties.Settings.ConnectionString"];
SqlConnection mySqlConnection = new SqlConnection(myConnectionString.ConnectionString);
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("SELECT Date FROM Holiday", mySqlConnection);
SqlDataReader sqlreader = mySqlCommand.ExecuteReader();

List<DateTime> holidays = new List<DateTime>();

while (sqlreader.Read())
{
holidays.Add(sqlreader.GetDateTime(0));
}
holidays.ToArray();
mySqlConnection.Close();
return holidays.Contains(date.Date);
}

我得到了答案!谢谢 :)

于 2013-04-27T16:06:13.277 回答