diff --git a/paymentLogs/Domain/Payment.cs b/paymentLogs/Domain/Payment.cs index 59d2acf..8474cd4 100644 --- a/paymentLogs/Domain/Payment.cs +++ b/paymentLogs/Domain/Payment.cs @@ -13,6 +13,5 @@ namespace PaymentLogs.Domain public int CourseId { get; set; } public int CoursePrice { get; set; } public int Paid { get; set; } - public int Debt { get; set; } } } diff --git a/paymentLogs/Forms/DataForm.cs b/paymentLogs/Forms/DataForm.cs index c883f16..bb83d8d 100644 --- a/paymentLogs/Forms/DataForm.cs +++ b/paymentLogs/Forms/DataForm.cs @@ -33,6 +33,7 @@ namespace PaymentLogs dataGridView1.Columns.Add("course_price", "Цена"); dataGridView1.Columns.Add("paid", "Оплачено"); dataGridView1.Columns.Add("debt", "Долг"); + dataGridView1.Columns["debt"].ReadOnly = true; foreach (Payment payment in Program.PaymentRepository.All()) { if(payment.CourseId != _course.Id) @@ -40,7 +41,7 @@ namespace PaymentLogs continue; } dataGridView1.Rows.Add(payment.Id.ToString(), payment.FCs.ToString(), Program.CourseRepository.Get(payment.CourseId).Name, - payment.CoursePrice.ToString(), payment.Paid.ToString(), payment.Debt.ToString()); + payment.CoursePrice.ToString(), payment.Paid.ToString(), (payment.CoursePrice - payment.Paid).ToString() ); } } @@ -58,6 +59,7 @@ namespace PaymentLogs private void toolStripButton2_Click(object sender, EventArgs e) { + this.ActiveControl = null; foreach (DataGridViewRow row in dataGridView1.Rows) { try @@ -70,8 +72,7 @@ namespace PaymentLogs FCs = row.Cells["fcs"].Value.ToString(), CourseId = Program.CourseRepository.ByName(row.Cells["course"].Value.ToString()).Id, CoursePrice = Convert.ToInt32(row.Cells["course_price"].Value), - Paid = Convert.ToInt32(row.Cells["paid"].Value), - Debt = Convert.ToInt32(row.Cells["debt"].Value) + Paid = Convert.ToInt32(row.Cells["paid"].Value) }; Program.PaymentRepository.Update(payment.Id, payment); } @@ -109,7 +110,9 @@ namespace PaymentLogs List list = new List { row.Cells["id"].Value.ToString(), row.Cells["fcs"].Value.ToString(), row.Cells["course"].Value.ToString(), row.Cells["course_price"].Value.ToString(), - row.Cells["paid"].Value.ToString(), row.Cells["debt"].Value.ToString() }; + row.Cells["paid"].Value.ToString(), + (Convert.ToInt32(row.Cells["course_price"].Value.ToString()) - (Convert.ToInt32(row.Cells["paid"]))) + .ToString() }; filtredList.Add(list); } diff --git a/paymentLogs/Repositories/PaymentRepo.cs b/paymentLogs/Repositories/PaymentRepo.cs index c3c0b3c..cc9747a 100644 --- a/paymentLogs/Repositories/PaymentRepo.cs +++ b/paymentLogs/Repositories/PaymentRepo.cs @@ -29,8 +29,7 @@ namespace PaymentLogs.Repositories FCs = reader.GetString("fcs"), CourseId = reader.GetInt32("course_id"), CoursePrice = reader.GetInt32("course_price"), - Paid = reader.GetInt32("paid"), - Debt = reader.GetInt32("debt") + Paid = reader.GetInt32("paid") }; _data[payment.Id] = payment; @@ -45,10 +44,10 @@ namespace PaymentLogs.Repositories db.openConnection(); foreach(Payment payment in _data.Values) { - string sql = $" INSERT INTO `payments` (`id`, `fcs`, `course_id`, `course_price`, `paid`, `debt`) " + - $"VALUES ('{payment.Id}','{payment.FCs}', '{payment.CourseId}', '{payment.CoursePrice}', '{payment.Paid}', '{payment.Debt}') " + + string sql = $" INSERT INTO `payments` (`id`, `fcs`, `course_id`, `course_price`, `paid`) " + + $"VALUES ('{payment.Id}','{payment.FCs}', '{payment.CourseId}', '{payment.CoursePrice}', '{payment.Paid}') " + $"ON DUPLICATE KEY UPDATE `fcs`='{payment.FCs}', `course_id`='{payment.CourseId}', `course_price` = '{payment.CoursePrice}', " + - $"`paid` = '{payment.Paid}', `debt`='{payment.Debt}'"; + $"`paid` = '{payment.Paid}'"; MySqlCommand cmd = new MySqlCommand(sql, db.getConnection()); cmd.ExecuteNonQuery();