public ucLoanCalculator() { InitializeComponent(); LoanPayment.InitInterestRateData(editInterestRate); LoanPayment.InitTermOfLoan(editTermOfLoan); LoanPayment.InitStartMonth(editStart); editLoanAmount.Value = 250000; lciInfo.Padding = new DevExpress.XtraLayout.Utils.Padding(2, 2, 2, lciCalc.Height); }
private void gridView1_ShowFilterPopupCheckedListBox(object sender, DevExpress.XtraGrid.Views.Grid.FilterPopupCheckedListBoxEventArgs e) { if (e.Column.FieldName == gcMonth.FieldName) { foreach (CheckedListBoxItem item in e.CheckedComboBox.Items) { item.Description = LoanPayment.GetMonthString(Convert.ToInt32(((DevExpress.XtraGrid.Views.Grid.FilterItem)item.Value).Value), gridControl1.DataSource as List <LoanPayment>); } } }
void Calc() { List <LoanPayment> data = LoanPayment.Calculate(LoanAmount, InterestRate, Months, StartMonth, out monthlyPayment); gridControl1.DataSource = data; lcInfo.Text = string.Format("<size=+3>Your Monthly Payment<br><size=+4>{0:c}", monthlyPayment); BeginInvoke(new MethodInvoker(delegate { gcBalance.BestFit(); })); InterestSeries.DataSource = data; InterestSeries.SummaryFunction = "SUM([Interest])"; PrincipalSeries.DataSource = data; PrincipalSeries.SummaryFunction = "SUM([Principal])"; }
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { LoanPayment payment = gridView1.GetRow(e.RowHandle) as LoanPayment; if (payment == null) { return; } if (e.Column == gcMonth) { e.DisplayText = payment.MonthString; } if (e.Column == gcPayment) { Rectangle r = e.Bounds; r.Inflate(-3, -3); int interestWidth = (int)(r.Width * payment.Interest / payment.MonthlyPayment); int principalWidth = (int)(r.Width * payment.Principal / payment.MonthlyPayment); Rectangle interestRect = new Rectangle(r.X, r.Y, interestWidth, r.Height); Rectangle principalRect = new Rectangle(r.X + interestWidth, r.Y, principalWidth, r.Height); e.Graphics.FillRectangle(interestBrush, interestRect); e.Graphics.FillRectangle(principalBrush, principalRect); using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; if (e.Graphics.MeasureString(string.Format(GetCellFormat(payment.Interest), payment.Interest), cellFont).Width < interestRect.Width) { e.Graphics.DrawString(string.Format(GetCellFormat(payment.Interest), payment.Interest), cellFont, interestForeBrush, interestRect, sf); } else { e.Graphics.DrawString(string.Format(GetCellFormat(payment.Interest), payment.Interest), cellFont, principalForeBrush, principalRect, sf); } sf.Alignment = StringAlignment.Far; if (e.Graphics.MeasureString(string.Format(GetCellFormat(payment.Principal), payment.Principal), cellFont).Width < principalRect.Width) { e.Graphics.DrawString(string.Format(GetCellFormat(payment.Principal), payment.Principal), cellFont, principalForeBrush, principalRect, sf); } else { e.Graphics.DrawString(string.Format(GetCellFormat(payment.Principal), payment.Principal), cellFont, interestForeBrush, interestRect, sf); } } e.Graphics.DrawRectangle(paymentPen, new Rectangle(interestRect.X, interestRect.Y - 1, (interestRect.Width + principalRect.Width), interestRect.Height + 1)); e.Handled = true; } }
public static List <LoanPayment> Calculate(double loanAmount, double interestRate, double months, DateTime startMonth, out double payment) { payment = (loanAmount * interestRate) / (1 - Math.Exp((-months) * Math.Log(1 + interestRate))); payment = LoanPayment.Trunc2(payment); List <LoanPayment> payments = new List <LoanPayment>(); double balance = loanAmount; for (int i = 1; i <= Convert.ToInt32(months); i++) { LoanPayment lp = new LoanPayment(balance, payment, i, interestRate, startMonth); balance = lp.Balance; payments.Add(lp); if (lp.Balance <= 0) { break; } } payments[payments.Count - 1].UpdateBalance(); return(payments); }
private void gridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e) { if (e.SummaryProcess == CustomSummaryProcess.Start) { customSum = new PaymentTypeSum(); } if (e.SummaryProcess == CustomSummaryProcess.Calculate) { LoanPayment payment = gridView1.GetRow(e.RowHandle) as LoanPayment; if (payment != null && e.IsTotalSummary) { customSum.AddToSum(payment.Interest, payment.Principal); } } if (e.SummaryProcess == CustomSummaryProcess.Finalize) { if (e.IsTotalSummary) { e.TotalValue = customSum; } } }