I have this class
public class MonthlyPayment
{
public int Luna { get; set; }
public double SoldInitial { get; set; }
public double PlataLunara { get; set; }
public double Dobanda { get; set; }
public double Principal { get; set; }
public double Asigurare { get; set; }
public double Comision { get; set; }
public double TotalLunar { get; set; }
public double SoldCredit { get; set; }
}
I have this DataContext class
public class CreditDataContext {
public List<MonthlyPayment> MonthlyPayments { get; set; }
public void LoadMonthlyPayments() {
MonthlyPayments = new List<MonthlyPayment>();
MonthlyPayment payment = null;
payment = new MonthlyPayment() {
Luna = 0,
SoldInitial = 0,
PlataLunara = 0,
Dobanda = 0,
Principal = 0,
Asigurare = 0,
Comision = 200,
TotalLunar = 200,
SoldCredit = 10000
};
MonthlyPayments.Add(payment);
for (int i = 1; i <= 12; i++) {
MonthlyPayments.Add(InitializeMyObject(i, MonthlyPayments[i - 1]));
}
}
public MonthlyPayment InitializeMyObject(int i, MonthlyPayment lastMonth) {
MonthlyPayment x = new MonthlyPayment();
x.Luna = i;
x.SoldInitial = Math.Round(lastMonth.SoldCredit, 2);
double s = 10000;
double a = 0.10 / 100;
double c = (0.5 / 12) / 100;;
double d = (9.75 / 100) / 12;
x.Dobanda = Math.Round(d * lastMonth.SoldCredit, 2);
double v = 1 + d;
x.PlataLunara = Math.Round((s * d) / (1 - Math.Pow(v, -12)), 2);
x.Principal = Math.Round(x.PlataLunara - x.Dobanda, 2);
x.Asigurare = Math.Round(a * lastMonth.SoldCredit, 2);
x.Comision = Math.Round(c * s, 2);
x.TotalLunar = Math.Round(x.Comision + x.Asigurare + x.PlataLunara, 2);
x.SoldCredit = Math.Round(lastMonth.SoldCredit - x.Principal, 2);
return x;
}
And textbox:
<pre><TextBox x:Name="textBoxValoareCredit" Width="100" Height="30" Margin="10" VerticalAlignment="Bottom"/>
.....
Now the data is fixed in the code, but I want to use the code above instead of 'SoldInitial',"a","c","d",value entered in this textbox:
What I have tried:
double SoldInitial, Dobanda,ComisionAnaliza,Asigurare,Comision;
SoldInitial= float.Parse(textBoxValoareCredit.Text);
Dobanda = float.Parse(textBoxDobanda.Text);
ComisionAnaliza = float.Parse(textBoxComisionAnaliza.Text);
Asigurare = float.Parse(textBoxAsigurare.Text);
Comision = float.Parse(textBoxComisionLunar.Text);
How do I use the data entered in the textbox in my LoadMonthlyPayments() and MonthlyPayment InitializeMyObject() method?