Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Form2_Load(object sender, EventArgs e)
- {
- CreditData helper = new CreditData();
- double cash = helper.sumCredit;
- double percent = helper._percent;
- if(helper.ann == 0)
- {
- double commonPay = helper.comm;
- }
- else
- {
- double coeffAnn = helper.ann;
- percent /= 12;// % 1 mnth
- percent /= 100;
- DataTable table = new DataTable();
- table.Columns.Add("Місяць", typeof(int));
- table.Columns.Add("Сума щомісячного платежу", typeof(double));
- table.Columns.Add("%", typeof(double));
- table.Columns.Add("Погашення основної суми кредиту", typeof(double));
- table.Columns.Add("Залишок позики", typeof(double));
- for(int k = 0; k < helper.termin; k++)
- {
- table.Rows.Add(k + 1, coeffAnn, percent * cash, coeffAnn - (percent * cash), cash - (coeffAnn - (percent * cash)));
- }
- dataGridView1.DataSource = table;
- }
- }
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- double start_sum;
- double interest_rate;
- double donation;
- int term;
- bool checking = true;
- CreditData helper = new CreditData();
- //test: Is you dork or no?
- try
- {
- term = Int32.Parse(textBox5.Text);
- start_sum = double.Parse(textBox4.Text);
- interest_rate = double.Parse(textBox1.Text);
- donation = double.Parse(textBox2.Text);
- }
- catch
- {
- MessageBox.Show("Error!nBe more attentive, please!nYou made a mistake!");
- checking = false;
- }
- bool checking_comboBox;
- bool checking_zero = true;
- if(checking != false)
- {
- if ((start_sum = double.Parse(textBox4.Text)) == 0
- || (interest_rate = double.Parse(textBox1.Text)) == 0
- || (donation = double.Parse(textBox2.Text)) == 0
- || (term = Int32.Parse(textBox5.Text)) == 0)
- {
- MessageBox.Show("Error!nYou cannot enter 0!");
- checking_zero = false;
- }
- }
- if (comboBox1.SelectedIndex > -1) checking_comboBox = true;
- else checking_comboBox = false;
- if (checking == false || checking_zero == false || checking_comboBox == false)
- {
- textBox1.Clear();
- textBox2.Clear();
- textBox3.Clear();
- textBox4.Clear();
- textBox5.Clear();
- }
- //end test
- else if (checking_zero == true && checking == true && checking_comboBox == true)
- {
- start_sum = double.Parse(textBox4.Text);
- interest_rate = double.Parse(textBox1.Text);
- donation = double.Parse(textBox2.Text);
- term = Int32.Parse(textBox5.Text);
- textBox3.Text = (start_sum = start_sum - donation).ToString();
- helper.sumCredit = start_sum;
- helper._percent = interest_rate;
- helper.termin = term;
- helper.ann = 0;
- helper.comm = 0;
- Form2 _show = new Form2();
- if (comboBox1.SelectedIndex == 0)
- {
- helper.ann = Annuity(start_sum, interest_rate, term);
- _show.Show();
- }
- else if (comboBox1.SelectedIndex == 1)
- {
- helper.comm = CommonMethod(start_sum, term);
- _show.Show();
- }
- }
- }
- double Annuity(double _startSum, double _interestRate, int _term)
- {
- double coefficientAnnuity = (_interestRate / 100) / 12 * Math.Pow((1 + (_interestRate / 100) / 12), _term) / (Math.Pow((1 + (_interestRate / 100) / 12), _term) - 1);
- coefficientAnnuity = _startSum * coefficientAnnuity;//тіло кредиту з відсотками
- return coefficientAnnuity;
- }
- double CommonMethod(double _startSum, int _term)
- {
- double monthlyPay = _startSum / _term;
- return monthlyPay;
- }
- }
- class CreditData
- {
- public double sumCredit { get; set; }
- public double _percent { get; set; }
- public double ann { get; set; }
- public double comm { get; set; }
- public int termin { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement