-3

Here is the Part of the code of DateTime Picker.When Someone Select StartDate & EndDate from date time picker it comes to unitHolidays.

In here i need get full holiday.I need to consider if someone select any Start Date but time is 12:00:00 AM to any End Date with time is 12:00:00 AM ( ex : see full holiday )

Full Holiday 9/19/2013 12:00:00 AM to 9/20/2013 12:00:00 AM

But my following code, it takes any 12 hour slot is a holiday.

  foreach (UnitHolidays uh in unitHolidays)
  {

       for (DateTime dth = uh.StartDate; dth <= uh.EndDate; dth = dth.AddDays(1))
       { 
           RadCalendarDay rcdHoliday = new RadCalendarDay();
           rcdHoliday.Date = dth.Date;
           rcdHoliday.IsDisabled = true;
           rcdHoliday.IsSelectable = true;
           rcdHoliday.ToolTip = "Holiday";
           rcdHoliday.ItemStyle.BackColor = System.Drawing.Color.MediumOrchid;
           rdpStDt.Calendar.SpecialDays.Add(rcdHoliday);
       }
   }

I need if someone select 12:00:00 AM to 12:00:00 AM then only I need to take it as a holiday.

4

2 回答 2

2

如上所述,类似于:

public class Holiday
{
     public DateTime Start { get; set; }
     public DateTime End { get; set; }

     public List<Holiday> GetHolidays()
     {
          return new List<Holiday>() { new Holiday() { 
                Start = new DateTime(2013, 9, 19), 
                End = new DateTime(2013, 9, 20)
          };
     }

     public bool IsHoliday(DateTime date)
     {
          return GetHolidays().Where(c => c.Start <= date && c.End >= date).Count() > 0;
     }
}

但是,我认为这会更轻松一些:

public class Holiday
{
     public List<DateTime> GetHolidays()
     {
          return new List<DateTime>() { 
               new DateTime(2013, 9, 19)
          };
     }

     public bool IsHoliday(DateTime date)
     {
          return GetHolidays().Where(c => c.Date == date.Date).Count() > 0;
     }
}
于 2013-09-19T16:58:51.173 回答
1

开始日期和结束日期不会描述一整天9/19/2013 12:00:00 AM9/19/2013 11:59:59 PM?您应该使用而不是,因为它将包括第二天,而不是同一天。>=<<<=

你想要这样的东西:

private bool IsHoliday(DateTime startDate, DateTime endDate)
{
    return DateTime.Now >= startDate && DateTime.Now < endDate;
}
于 2013-09-19T16:50:52.737 回答