public void InitializeProgressData() { if (ProgressData != null) { return; } ProgressData = new List <HabitDay>(); var currentDay = StartingDay.AddDays(0); for (int i = 0; i < DaysTilCompleted; i++) { ProgressData.Add(new HabitDay(currentDay, DailyObjectives)); currentDay = currentDay.AddDays(1); } EndingDay = currentDay; }
/// <summary> /// Builds a range condition including session and bingoday... if there is a session, splits the condition into 3 or parts. /// </summary> /// <param name="prefix">if null, no prefix, else prefix.bingoday and prefix.session used</param> /// <param name="date_in_week">some day of play... the week that contains this day</param> /// <param name="session_in_day">session on day in week</param> /// <param name="day_of_week_boundry">the day of week that the week starts</param> /// <param name="session_boundry">the session number that starts... 0 for starts on that day.</param> /// <returns></returns> public static string BuildSessionRangeCondition(String prefix , DateTime date_in_week, int session_in_day , int day_of_week_boundry, int session_boundry , out DateTime start_date, out DateTime end_date) { //StartingDay = date_in_week.AddDays( -( ( Convert.ToInt32( date_in_week.DayOfWeek ) + day_of_week_boundry ) - 1 ) % 7 ); //StartingDay = date_in_week.AddDays( -( ( Convert.ToInt32( date_in_week.DayOfWeek ) + day_of_week_boundry ) ) % 7 ); int days; bool monthly; if (Options.Default["Bingo Game Core"]["Defaults"]["Month span", 1].Integer != 0) { monthly = true; days = DateTime.DaysInMonth(date_in_week.Year, date_in_week.Month); // if there's a session boundry, and the session is at or above it // then if the date is the last day of month, then really we're counting // next month's days if (session_boundry > 0) { if (session_in_day >= session_boundry) { if (date_in_week.Day == DateTime.DaysInMonth(date_in_week.Year, date_in_week.Month)) { days = DateTime.DaysInMonth(date_in_week.Year, date_in_week.Month + 1); } } } } else { monthly = false; days = Options.Default["Bingo Game Core"]["Defaults"]["Days To Span", "7"].Integer; } if (session_boundry == 0) { DateTime StartingDay; if (monthly) { StartingDay = date_in_week.AddDays(-(date_in_week.Day - 1)); } else { StartingDay = date_in_week.AddDays(-((Convert.ToInt32(date_in_week.DayOfWeek) + days - day_of_week_boundry) % 7)); } DateTime EndingDay = StartingDay.AddDays(days - 1); start_date = StartingDay; end_date = EndingDay; return("(" + prefix + (prefix == null ? "" : ".") + "bingoday between " + StartingDay.ToString("yyyyMMdd") + " and " + EndingDay.ToString("yyyyMMdd") + ")"); } else { DateTime StartingDay; DateTime EndingDay; if (monthly) { StartingDay = date_in_week.AddDays(-(date_in_week.Day)); // when we started, the boundry was recorded wrong... if (StartingDay.Month == 6 && StartingDay.Day == 30 && StartingDay.Year == 2009) { StartingDay = StartingDay.AddDays(1); EndingDay = StartingDay.AddDays(days - 1); } else { EndingDay = StartingDay.AddDays(days); } } else { StartingDay = date_in_week.AddDays(-((Convert.ToInt32(date_in_week.DayOfWeek) + days - day_of_week_boundry) % 7)); if (StartingDay == date_in_week) { StartingDay = StartingDay.AddDays(-days); } EndingDay = StartingDay.AddDays(days); } if (EndingDay == date_in_week) { if (session_in_day >= session_boundry) { // prior week if (!monthly) { StartingDay = EndingDay; EndingDay = StartingDay.AddDays(days); } } else { // this week. } } if (StartingDay == date_in_week) { if (session_in_day < session_boundry) { // prior week if (!monthly) { EndingDay = StartingDay; StartingDay = EndingDay.AddDays(-days); } } else { // this week. } } String s = "((" + prefix + (prefix == null ? "" : ".") + "bingoday=" + StartingDay.ToString("yyyyMMdd") + " and " + prefix + (prefix == null ? "" : ".") + "session>=" + session_boundry + ")" + " or (" + prefix + (prefix == null ? "" : ".") + "bingoday between " + StartingDay.AddDays(1).ToString("yyyyMMdd") + " and " + EndingDay.AddDays(-1).ToString("yyyyMMdd") + ")" + " or (" + prefix + (prefix == null ? "" : ".") + "bingoday=" + EndingDay.ToString("yyyyMMdd") + " and " + prefix + (prefix == null ? "" : ".") + "session<" + session_boundry + "))" ; start_date = StartingDay; end_date = EndingDay; return(s); } }