【发布时间】:2014-08-05 16:34:33
【问题描述】:
所以我正在构建一个会议安排程序,其中每个潜在参与者都有一组不可用的日期。为了测试,我插入了自己的。
用户输入一个日期范围,然后将其放入中间所有日期的列表中。
我目前有一个不可用日期列表,具体取决于用户邀请谁参加活动。这被保存到一个名为 availableDates 的列表中。
我正在尝试删除 datesBetween 列表中存在的所有日期,这些日期也在availableDates 列表中,只留下不在某人不可用日期上的日期。
我尝试了一些不同的方法,但似乎无法正常工作。
private void compileDates()
{
DateTime startingDate = cal1.SelectionEnd; //Get the starting date from the first calender
DateTime endingDate = cal2.SelectionEnd; //Get the ending date from the first calender
var namesList = lstConfirmedParticipants.Items.Cast<String>().ToList(); //Collects all the participants names and converts it to a list
List<DateTime> PhillChambers = new List<DateTime>(); //Set Pauls Unavailable Dates
PhillChambers.Add(new DateTime(2014, 08, 11));
PhillChambers.Add(new DateTime(2014, 08, 12));
PhillChambers.Add(new DateTime(2014, 08, 17));
List<DateTime> HenryWright = new List<DateTime>(); //Set Pauls Unavailable Dates
HenryWright.Add(new DateTime(2014, 08, 09));
HenryWright.Add(new DateTime(2014, 08, 12));
HenryWright.Add(new DateTime(2014, 08, 14));
List<DateTime> PaulaCooper = new List<DateTime>(); //Set Pauls Unavailable Dates
PaulaCooper.Add(new DateTime(2014, 08, 11));
PaulaCooper.Add(new DateTime(2014, 08, 12));
PaulaCooper.Add(new DateTime(2014, 08, 16));
List<DateTime> unavailableDates = new List<DateTime>(); //Creates a new list to hold all the unavailable dates
if (namesList.Contains("Paula Cooper"))
{ //Add Paulas Unavailable Dates
unavailableDates.AddRange(PaulaCooper);
}
if (namesList.Contains("Henry Wright"))
{ //Add Henrys Unavailable Dates
unavailableDates.AddRange(HenryWright);
}
if (namesList.Contains("Phill Chambers"))
{ //Add Phills Unavailable Dates
unavailableDates.AddRange(PhillChambers);
}
foreach (DateTime date in GetDateRange(startingDate, endingDate))
{
lstDatesBetween.Items.Add(date.ToShortDateString()); //Get all the dates between the date ranges and put them into the listbox.
}
List<DateTime> datesBetween = lstDatesBetween.Items.OfType<DateTime>().ToList(); //Convert the Listbox into a list holding all the dates between the date ranges
datesBetween.RemoveAll(item => unavailableDates.Contains(item)); //remove all the dates in dates between that also appear in unavailable dates
List<DateTime> availableDates = new List<DateTime>(); //Creates a new list to hold all the available dates(FUTURE USE)
availableDates.AddRange (datesBetween);
lstDatesAvailable.DataSource = availableDates; //display the available dates for the meeting
private List<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate)
{
if (StartingDate > EndingDate)
{
return null;
}
List<DateTime> datesBetween = new List<DateTime>();
DateTime tempDate = StartingDate;
do
{
datesBetween.Add(tempDate);
tempDate = tempDate.AddDays(1);
} while (tempDate <= EndingDate);
return datesBetween;
}
【问题讨论】:
-
调试器说什么?