private void Populate(ObservableCollection <InterestInfo> interestInfoCollection, int index) { InterestCalculationInput input = GetInput(index); List <InterestInfo> interestList = InterestCalculationManager.CreateInterestDetails(input); foreach (InterestInfo info in interestList) { interestInfoCollection.Add(info); } }
private void CalculateInterest() { InterestCalculationInput input = GetInput(0); this.interestInfoListQ.Clear(); this.interestInfoListA.Clear(); this.interestInfoListH.Clear(); this.interestInfoListM.Clear(); CalculateSimpleInterest(); Populate(interestInfoListQ, 1); Populate(interestInfoListH, 2); Populate(interestInfoListM, 0); Populate(interestInfoListA, 3); SetClipboardWithRTF(); }
private void CalculateSimpleInterest() { InterestCalculationInput input = GetInput(0); DateTime startDate = input.StartDate; DateTime endDate = input.EndDate; TimeSpan t = input.EndDate - input.StartDate; int totalDays = Convert.ToInt32(t.TotalDays) + 1; int yeardiff = totalDays / 365; int monthdiff = (totalDays % 365) / 30; DateTime afterYear = input.StartDate.AddYears(yeardiff); DateTime afterMonths = afterYear.AddMonths(monthdiff); int daydiff = Convert.ToInt32((input.EndDate - afterMonths).TotalDays) + 1; DateTime afterDays = afterMonths.AddDays(daydiff); //int daydiff = endDate.Day - startDate.Day; //if (daydiff < 0) //{ // daydiff += (startDate.Month == 2 && isLeapYear(startDate.Year)) ? 29 : daysOfMonth[startDate.Month]; // endDate = endDate.AddMonths(-1); //} //int monthdiff = endDate.Month - startDate.Month; //if (monthdiff < 0) //{ // monthdiff += 12; // endDate = endDate.AddYears(-1); //} //int yeardiff = endDate.Year - startDate.Year; //daydiff++; //if (daydiff == 31) //{ // daydiff = 0; // monthdiff++; //} //if (monthdiff == 12) //{ // monthdiff = 0; // yeardiff++; //} double interestamount = input.Principal * input.InterestRate / 100; double yearsinterest = (yeardiff * interestamount); double monthsinterest = monthdiff * interestamount / 12; double daysinterest = daydiff * interestamount / 365; double xdaysinterest = totalDays * interestamount / 365; double totalinterest = yearsinterest + monthsinterest + daysinterest; this.Years.Text = yeardiff.ToString() + (yeardiff == 1 ? " year" : " years"); this.Months.Text = monthdiff.ToString() + (monthdiff == 1 ? " month" : " months"); this.Days.Text = (daydiff).ToString() + (daydiff == 1 ? " day" : " days");; this.XDays.Text = totalDays.ToString() + " days"; this.YearsInterest.Text = yearsinterest.ToString("C"); this.MonthsInterest.Text = monthsinterest.ToString("C"); this.DaysInterest.Text = daysinterest.ToString("C"); this.XDaysInterest.Text = xdaysinterest.ToString("C"); this.TotalInterest.Text = totalinterest.ToString("C"); this.XTotalInterest.Text = xdaysinterest.ToString("C"); this.TotalAmountWithInterest.Text = (input.Principal + totalinterest).ToString("C"); this.XTotalAmountWithInterest.Text = (input.Principal + xdaysinterest).ToString("C"); }