/// <summary> /// Returns a collection of <see cref="TimeRange"/> where /// From is a start of the month (or <see cref="From"/>) and To is the end of the month (or <see cref="To"/>). /// At least one time range will be returned. /// </summary> /// <returns>Collection of Time Ranges.</returns> public IReadOnlyCollection <MonthRange> SplitByMonths() { var list = new List <MonthRange>(); if (SameMonth()) { list.Add(new MonthRange(@from: _from.StartOfTheDay(), to: _to.EndOfTheDay())); return(list); } DateTimeOffset firstDayOfTheLastTimelineMonth = _to.FirstDayOfMonth(); // Add first month remaining days list.Add(new MonthRange(_from.StartOfTheDay(), _from.LastDayOfMonth())); // Add All months days in between for (var st = From.AddMonths(1); st < firstDayOfTheLastTimelineMonth; st = st.AddMonths(1)) { var extended = new Date(st); list.Add(new MonthRange(extended.FirstDayOfMonth(), extended.LastDayOfMonth())); } // Add last month days list.Add(new MonthRange(firstDayOfTheLastTimelineMonth, _to.EndOfTheDay())); return(list); }
void HandleStateConfirm(ManageDataSession Data, BudgetSession S) { switch (Data.State) { case ManageDataState.Main: { MainRadioButton Next = GetMainRadioButton(Data); HandleShowState(Data, Next.NewState, true); return; } case ManageDataState.AddSingle: { if (!float.TryParse(inCurAmt.Value, out float Amt)) { throw new DisplayException("Could not parse currency amount"); } if (!DateTime.TryParse(dateBegin.Value, out DateTime Date)) { throw new DisplayException("Could not parse date"); } DAL DbDAL = new DAL(); Transaction T = new Transaction(S.CurrentUser, Date, Amt); T.Description = inComment.Value.Trim(); DbDAL.Insert(T); break; } case ManageDataState.AddMultiple: { if (!float.TryParse(inCurAmt.Value, out float Amt)) { throw new DisplayException("Could not parse currency amount"); } if (!DateTime.TryParse(dateBegin.Value, out DateTime From)) { throw new DisplayException("Could not parse From date"); } if (!DateTime.TryParse(dateEnd.Value, out DateTime To)) { throw new DisplayException("Could not parse To date"); } else { To = To.AddDays(1); } DAL DbDAL = new DAL(); while (From < To) { Transaction T = new Transaction(S.CurrentUser, From, Amt); T.Description = inComment.Value.Trim(); DbDAL.Insert(T); From = From.AddMonths(1); } break; } case ManageDataState.AddRepeating: break; case ManageDataState.AddMaestroPlus: { DAL DbDAL = new DAL(); MaestroPlusCalculator MaestroCalc = new MaestroPlusCalculator(DbDAL); int MonthCount = int.Parse(inMonthCount.Value); float Amt = float.Parse(inCurAmt.Value); DateTime From = DateTime.Parse(dateBegin.Value); string Comment = inComment.Value.Trim(); MaestroCalc.Calculate(MonthCount, Amt, out float OneTime, out float Monthly); MaestroEntry MaestroEntry = new MaestroEntry(); MaestroEntry.Description = Comment; DbDAL.Insert(MaestroEntry); Transaction TOneTime = new Transaction(S.CurrentUser, From, -OneTime); TOneTime.Description = "Maestro OneTime " + Comment; TOneTime.Maestro = MaestroEntry.ID; DbDAL.Insert(TOneTime); Transaction MaestroPayment = new Transaction(S.CurrentUser, From, Amt); MaestroPayment.Description = Comment; MaestroPayment.Maestro = MaestroEntry.ID; DbDAL.Insert(MaestroPayment); From = From.AddMonths(1); for (int i = 0; i < MonthCount; i++) { Transaction MaestroMonthly = new Transaction(S.CurrentUser, From, -Monthly); MaestroMonthly.Description = Comment; MaestroMonthly.Maestro = MaestroEntry.ID; DbDAL.Insert(MaestroMonthly); From = From.AddMonths(1); } break; } case ManageDataState.ManageMaestroPlus: break; default: throw new Exception("Invalid state " + Data.State); } }