///<summary>Fills comboBoxMonthSelect when appropriate, otherwise butThisMonth and butLastMonth are used. Returns true if comboBoxMonthSelect ///will be used instead of butThisMonth/butLastMonth.</summary> private bool FillComboBoxMonthSelect() { switch (CreditCards.GetFrequencyType(_creditCardCur.ChargeFrequency)) { case ChargeFrequencyType.FixedDayOfMonth: //EX: 2nd and 15th of each Month, instance of a singular day being charged is in GetValidPayDate(...) List <int> listDaysOfMonth = CreditCards.GetDaysOfMonthForChargeFrequency(_creditCardCur.ChargeFrequency).Split(',').Select(x => PIn.Int(x)) .OrderByDescending(x => x).ToList(); if (listDaysOfMonth.Count > 1) { comboBoxMonthSelect.Items.Clear(); List <DateTime> listDates = new List <DateTime>(); listDaysOfMonth.ForEach(x => { int monthOffset = (x > DateTime.Today.Day) ? -1 : 0; DateTime thisMonth = GetDateForDayOfMonth(DateTime.Today.AddMonths(monthOffset), x); //This Month/Closest Month DateTime lastMonth = GetDateForDayOfMonth(DateTime.Today.AddMonths(monthOffset - 1), x); //Last Month/Previous Month if (thisMonth >= _creditCardCur.DateStart) { listDates.Add(thisMonth); } if (lastMonth >= _creditCardCur.DateStart) { listDates.Add(lastMonth); } }); listDates.OrderByDescending(x => x).ForEach(x => comboBoxMonthSelect.Items.Add(new ODBoxItem <DateTime>(x.ToShortDateString(), x))); if (comboBoxMonthSelect.Items.Count > 0) { comboBoxMonthSelect.SelectedIndex = 0; //Begin with the most recent date. } EnableComboBoxMonthUI(); return(true); } break; case ChargeFrequencyType.FixedWeekDay: DayOfWeekFrequency frequency = CreditCards.GetDayOfWeekFrequency(_creditCardCur.ChargeFrequency); DayOfWeek ccDayOfWeek = CreditCards.GetDayOfWeek(_creditCardCur.ChargeFrequency); if (frequency.In(DayOfWeekFrequency.Every, DayOfWeekFrequency.EveryOther)) { FillComboBoxForWeekDays(ccDayOfWeek, isEveryOther: frequency == DayOfWeekFrequency.EveryOther); EnableComboBoxMonthUI(); return(true); } break; default: throw new ODException(Lan.g(this, "Invalid ChargeFrequency.")); } return(false); //Either the frequency is FixedDayOfMonth with 1 day per month, or it is FixedWeekDay with nth day frequency (1st, 2nd, 3rd, etc.) }
///<summary>Returns a valid date based on the Month and Year taken from the date passed in and the Day that is set for the recurring charges.</summary> private DateTime GetValidPayDate(DateTime date) { int dayOfMonth; DateTime retVal; if (PrefC.IsODHQ && PrefC.GetBool(PrefName.BillingUseBillingCycleDay)) { dayOfMonth = _pat.BillingCycleDay; return(GetDateForDayOfMonth(date, dayOfMonth)); } switch (CreditCards.GetFrequencyType(_creditCardCur.ChargeFrequency)) { case ChargeFrequencyType.FixedDayOfMonth: //EX: 1st of Each Month (This check only accounts for a singular day of the month being run) List <int> listDaysOfMonth = CreditCards.GetDaysOfMonthForChargeFrequency(_creditCardCur.ChargeFrequency).Split(',').Select(x => PIn.Int(x)) .OrderByDescending(x => x).ToList(); if (listDaysOfMonth.Count == 1) //There is only 1 day being charged in a month { dayOfMonth = listDaysOfMonth.First(); //This may result in a future date for the "This Month" button. The button will get disabled later. retVal = GetDateForDayOfMonth(date, dayOfMonth); } else { throw new ODException(Lan.g(this, "Invalid ChargeFrequency.")); } break; case ChargeFrequencyType.FixedWeekDay: DayOfWeekFrequency frequency = CreditCards.GetDayOfWeekFrequency(_creditCardCur.ChargeFrequency); if (!frequency.In(DayOfWeekFrequency.Every, DayOfWeekFrequency.EveryOther)) //EX: 1st Sunday of Each Month { retVal = CreditCards.GetNthWeekdayofMonth(date, (int)frequency - 1, CreditCards.GetDayOfWeek(_creditCardCur.ChargeFrequency)); //This may result in a future date for the "This Month" button. The button will get disabled later. } else { throw new ODException(Lan.g(this, "Invalid ChargeFrequency.")); } break; default: throw new ODException(Lan.g(this, "Invalid ChargeFrequency.")); } return(retVal); }