Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. private void Form2_Load(object sender, EventArgs e)
  2. {
  3. CreditData helper = new CreditData();
  4. double cash = helper.sumCredit;
  5. double percent = helper._percent;
  6. if(helper.ann == 0)
  7. {
  8. double commonPay = helper.comm;
  9. }
  10. else
  11. {
  12. double coeffAnn = helper.ann;
  13. percent /= 12;// % 1 mnth
  14. percent /= 100;
  15.  
  16. DataTable table = new DataTable();
  17.  
  18. table.Columns.Add("Місяць", typeof(int));
  19. table.Columns.Add("Сума щомісячного платежу", typeof(double));
  20. table.Columns.Add("%", typeof(double));
  21. table.Columns.Add("Погашення основної суми кредиту", typeof(double));
  22. table.Columns.Add("Залишок позики", typeof(double));
  23.  
  24. for(int k = 0; k < helper.termin; k++)
  25. {
  26. table.Rows.Add(k + 1, coeffAnn, percent * cash, coeffAnn - (percent * cash), cash - (coeffAnn - (percent * cash)));
  27. }
  28. dataGridView1.DataSource = table;
  29. }
  30. }
  31.  
  32. public partial class Form1 : Form
  33. {
  34. public Form1()
  35. {
  36. InitializeComponent();
  37. }
  38.  
  39. private void button1_Click(object sender, EventArgs e)
  40. {
  41. double start_sum;
  42. double interest_rate;
  43. double donation;
  44. int term;
  45. bool checking = true;
  46. CreditData helper = new CreditData();
  47. //test: Is you dork or no?
  48. try
  49. {
  50. term = Int32.Parse(textBox5.Text);
  51. start_sum = double.Parse(textBox4.Text);
  52. interest_rate = double.Parse(textBox1.Text);
  53. donation = double.Parse(textBox2.Text);
  54. }
  55. catch
  56. {
  57. MessageBox.Show("Error!nBe more attentive, please!nYou made a mistake!");
  58. checking = false;
  59. }
  60. bool checking_comboBox;
  61. bool checking_zero = true;
  62. if(checking != false)
  63. {
  64. if ((start_sum = double.Parse(textBox4.Text)) == 0
  65. || (interest_rate = double.Parse(textBox1.Text)) == 0
  66. || (donation = double.Parse(textBox2.Text)) == 0
  67. || (term = Int32.Parse(textBox5.Text)) == 0)
  68. {
  69. MessageBox.Show("Error!nYou cannot enter 0!");
  70. checking_zero = false;
  71. }
  72. }
  73.  
  74. if (comboBox1.SelectedIndex > -1) checking_comboBox = true;
  75. else checking_comboBox = false;
  76.  
  77. if (checking == false || checking_zero == false || checking_comboBox == false)
  78. {
  79. textBox1.Clear();
  80. textBox2.Clear();
  81. textBox3.Clear();
  82. textBox4.Clear();
  83. textBox5.Clear();
  84. }
  85. //end test
  86. else if (checking_zero == true && checking == true && checking_comboBox == true)
  87. {
  88. start_sum = double.Parse(textBox4.Text);
  89. interest_rate = double.Parse(textBox1.Text);
  90. donation = double.Parse(textBox2.Text);
  91. term = Int32.Parse(textBox5.Text);
  92. textBox3.Text = (start_sum = start_sum - donation).ToString();
  93. helper.sumCredit = start_sum;
  94. helper._percent = interest_rate;
  95. helper.termin = term;
  96. helper.ann = 0;
  97. helper.comm = 0;
  98. Form2 _show = new Form2();
  99. if (comboBox1.SelectedIndex == 0)
  100. {
  101. helper.ann = Annuity(start_sum, interest_rate, term);
  102. _show.Show();
  103. }
  104. else if (comboBox1.SelectedIndex == 1)
  105. {
  106. helper.comm = CommonMethod(start_sum, term);
  107. _show.Show();
  108. }
  109.  
  110. }
  111. }
  112. double Annuity(double _startSum, double _interestRate, int _term)
  113. {
  114. double coefficientAnnuity = (_interestRate / 100) / 12 * Math.Pow((1 + (_interestRate / 100) / 12), _term) / (Math.Pow((1 + (_interestRate / 100) / 12), _term) - 1);
  115. coefficientAnnuity = _startSum * coefficientAnnuity;//тіло кредиту з відсотками
  116. return coefficientAnnuity;
  117. }
  118. double CommonMethod(double _startSum, int _term)
  119. {
  120. double monthlyPay = _startSum / _term;
  121. return monthlyPay;
  122. }
  123. }
  124.  
  125. class CreditData
  126. {
  127. public double sumCredit { get; set; }
  128. public double _percent { get; set; }
  129. public double ann { get; set; }
  130. public double comm { get; set; }
  131. public int termin { get; set; }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement