private void btn_TinhLaiSuat_Click(object sender, EventArgs e) { if (IsInValid()) { return; } foreach (DataGridViewRow row in grid_TienDoThanhToan.Rows) { if (row.Cells[0].Value == null) { continue; } var tienDoTruoc = tienDos.LastOrDefault(); var tongTienTruoc = tienDoTruoc != null ? tienDoTruoc.TongTienVay : 0; var tienDo = new TienDo(); tienDo.Name = row.Cells[0].Value.ToString(); tienDo.TiLeThanhToan = row.Cells[1].Value.ToString().ParseDouble(); tienDo.SoTien = row.Cells[2].Value.ToString().ParseDouble(); tienDo.ThoiHanThanhToan = row.Cells[3].Value.ToString().ParseDatetime(); tienDo.TongTienVay = tongTienTruoc + tienDo.SoTien; tienDos.Add(tienDo); } var tongTien = double.Parse(txt_TongTien.Text); var phanTramVay = double.Parse(txt_PhanTramVay.Text); var soTienVay = double.Parse(txt_SoTienVay.Text); var soThangVay = Int32.Parse(txt_SoThangVay.Text); var soThangConLai = soThangVay; var laiSuatUuDai1 = double.Parse(txt_LaiSuatUuDai1.Text) / 100; var sothangUuDai1 = Int32.Parse(txt_SoThangUuDai1.Text); var laiSuatThaNoi = double.Parse(txt_LaiSuatThaNoi.Text) / 100; var ngayGiaiNgan = dateTimeNgayGiaiNgan.Value; var ngayHetHan = ngayGiaiNgan.AddMonths(soThangVay); var tongTra = 0.0; DataRow dw; DataTable dt = new DataTable(); dt.Columns.Add("STT", typeof(int)); dt.Columns.Add("KyTraNo", typeof(DateTime)); dt.Columns.Add("SoGocConLai", typeof(string)); dt.Columns.Add("Goc", typeof(string)); dt.Columns.Add("Lai", typeof(string)); dt.Columns.Add("TienLai", typeof(string)); dt.Columns.Add("Tong", typeof(string)); for (int i = 1; i < soThangVay; i++) { double lai = 0; double laisuat = 0; var kyTraNo = ngayGiaiNgan.AddMonths(i); var tienDo = GetTienDo(kyTraNo); if (tienDo != null) { RemoveTienDo(tienDo); } soTienVay = tienDo != null ? tienDo.TongTienVay - tongTra : soTienVay; var goc = Math.Round(soTienVay / (soThangVay - i), 0); if (sothangUuDai1 > 0) { lai = Math.Round(soTienVay * laiSuatUuDai1 / 12, 0); laisuat = laiSuatUuDai1 * 100; sothangUuDai1--; } else { lai = Math.Round(soTienVay * laiSuatThaNoi / 12, 0); laisuat = laiSuatThaNoi * 100; } soTienVay -= goc; tongTra += goc; dw = dt.NewRow(); dw["STT"] = i; dw["KyTraNo"] = kyTraNo; dw["SoGocConLai"] = soTienVay.AddSeparator(); dw["Goc"] = goc.AddSeparator(); dw["Lai"] = $"{laisuat}%"; dw["TienLai"] = lai.AddSeparator(); dw["Tong"] = (goc + lai).AddSeparator(); dt.Rows.Add(dw); } grid_KetQua.DataSource = dt; }
private void RemoveTienDo(TienDo tienDo) { tienDos.Remove(tienDo); }