private void fillDatePicker(DatePicker pDatePicker, int pId) { pDatePicker.BlackoutDates.Clear(); pDatePicker.BlackoutDates.AddDatesInPast(); List <DateTime> dateList = new List <DateTime>(); DataSet dataSet = ShowingsClass.getShowingForPlays(pId); //DataSet dataSet = ShowingsClass.getAllShowings(); foreach (DataRow row in dataSet.Tables[0].Rows) { int tempShowingId = int.Parse(row["Showing_Id"].ToString()); DateTime showingDate = ShowingsClass.turnSqlLiteDateStringIntoDateTime(row["Date"].ToString()); if (showingDate >= DateTime.Now) { dateList.Add(showingDate); } } dateList.Sort(); //if (dateList.Count != 0) //{ // DateTime nextStartDate = DateTime.Now.AddDays(-1); // int count = 1; // foreach (DateTime showingDateFromList in dateList) // { // if (count < dateList.Count) // { // nextStartDate = showingDateFromList; // if (showingDateFromList.AddDays(1).Date == dateList[count].Date) // { // //next date in list is for next day so do nothing // } // else // { // pDatePicker.BlackoutDates.Add(new CalendarDateRange(nextStartDate.AddDays(1), dateList[count].AddDays(-1))); // } // count = count + 1; // } // } // pDatePicker.BlackoutDates.Add(new CalendarDateRange(dateList[count - 1].AddDays(1), nextStartDate.AddYears(500))); // pDatePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.Now, dateList[0].AddDays(-1))); //} //else //{ // pDatePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.Now, DateTime.Now.AddYears(500))); //} if (dateList.Count == 0) { pDatePicker.BlackoutDates.Add(new CalendarDateRange(DateTime.Now, DateTime.Now.AddYears(1))); } else { DateTime startDate = DateTime.Now; for (int i = 0; i < dateList.Count; i++) { if (startDate.Date != dateList[i].Date) { pDatePicker.BlackoutDates.Add(new CalendarDateRange(startDate, dateList[i].AddDays(-1))); } startDate = dateList[i].AddDays(1); } pDatePicker.BlackoutDates.Add(new CalendarDateRange(startDate, startDate.AddMonths(12))); } }