我有一个要求,当假期在一周内时,我需要在时间表中禁用字段,我需要禁用当天的字段。但它一直循环到数据库中的假期结束。例如,我将 startdate 设为 11.08.2013,我需要在本周循环到 15.08.2013,因为 8 月 15 日是印度的独立日。
8 月 15 日,该字段应被禁用。但是在这里,我得到了像圣诞节这样的价值,这是一年中的最后一个公共假期,并且整天都受到影响......
代码:
DateTime dtstart = Convert.ToDateTime(startdate);
con.Open();
OleDbCommand cmd1 = new OleDbCommand("select * from ind_holidays", con);
OleDbDataReader dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
string holiday = dr1[0].ToString();
string date = dr1[1].ToString().Substring(0, 10);
DateTime holi_date = Convert.ToDateTime(date);
while (dtstart <= holi_date)
{
if (dtstart.DayOfWeek == DayOfWeek.Monday)
{
devmontxt.Text = holiday;
devmontxt.Enabled = false;
trmontxt.Text = holiday;
trmontxt.Enabled = false;
lunmontxt.Text = holiday;
lunmontxt.Enabled = false;
permontxt.Text = holiday;
permontxt.Enabled = false;
totmontxt.Text = holiday;
totmontxt.Enabled = false;
}
if (dtstart.DayOfWeek == DayOfWeek.Tuesday)
{
devtuetxt.Text = holiday;
devtuetxt.Enabled = false;
trtuetxt.Text = holiday;
trtuetxt.Enabled = false;
luntuetxt.Text = holiday;
luntuetxt.Enabled = false;
pertuetxt.Text = holiday;
pertuetxt.Enabled = false;
tottuetxt.Text = holiday;
tottuetxt.Enabled = false;
}
if (dtstart.DayOfWeek == DayOfWeek.Wednesday)
{
devwedtxt.Text = holiday;
devwedtxt.Enabled = false;
trwedtxt.Text = holiday;
trwedtxt.Enabled = false;
lunwedtxt.Text = holiday;
lunwedtxt.Enabled = false;
perwedtxt.Text = holiday;
perwedtxt.Enabled = false;
totwedtxt.Text = holiday;
totwedtxt.Enabled = false;
}
if (dtstart.DayOfWeek == DayOfWeek.Thursday)
{
devthutxt.Text = holiday;
devthutxt.Enabled = false;
trthutxt.Text = holiday;
trthutxt.Enabled = false;
lunthutxt.Text = holiday;
lunthutxt.Enabled = false;
perthutxt.Text = holiday;
perthutxt.Enabled = false;
totthutxt.Text = holiday;
totthutxt.Enabled = false;
}
if (dtstart.DayOfWeek == DayOfWeek.Friday)
{
devfritxt.Text = holiday;
devfritxt.Enabled = false;
trfritxt.Text = holiday;
trfritxt.Enabled = false;
lunfritxt.Text = holiday;
lunfritxt.Enabled = false;
perfritxt.Text = holiday;
perfritxt.Enabled = false;
totfritxt.Text = holiday;
totfritxt.Enabled = false;
}
if (dtstart.DayOfWeek == DayOfWeek.Saturday)
{
devsattxt.Text = holiday;
devsattxt.Enabled = false;
trsattxt.Text = holiday;
trsattxt.Enabled = false;
lunsattxt.Text = holiday;
lunsattxt.Enabled = false;
persattxt.Text = holiday;
persattxt.Enabled = false;
totsattxt.Text = holiday;
totsattxt.Enabled = false;
}
dtstart = dtstart.AddDays(1);
continue;
}
}
dr1.Close();
con.Close();
}