debt calc

This commit is contained in:
redtea committed 2024-06-07 12:06:02 +03:00
1 parent ecfe62cc05
commit 71dd5be182
3 files changed
+11 -10

No files matched your search

-1
View File
@@ -13,6 +13,5 @@ namespace PaymentLogs.Domain
public int CourseId { get; set; } public int CourseId { get; set; }
public int CoursePrice { get; set; } public int CoursePrice { get; set; }
public int Paid { get; set; } public int Paid { get; set; }
public int Debt { get; set; }
} }
} }
+7 -4
View File
@@ -33,6 +33,7 @@ namespace PaymentLogs
dataGridView1.Columns.Add("course_price", "Цена"); dataGridView1.Columns.Add("course_price", "Цена");
dataGridView1.Columns.Add("paid", "Оплачено"); dataGridView1.Columns.Add("paid", "Оплачено");
dataGridView1.Columns.Add("debt", "Долг"); dataGridView1.Columns.Add("debt", "Долг");
dataGridView1.Columns["debt"].ReadOnly = true;
foreach (Payment payment in Program.PaymentRepository.All()) foreach (Payment payment in Program.PaymentRepository.All())
{ {
if(payment.CourseId != _course.Id) if(payment.CourseId != _course.Id)
@@ -40,7 +41,7 @@ namespace PaymentLogs
continue; continue;
} }
dataGridView1.Rows.Add(payment.Id.ToString(), payment.FCs.ToString(), Program.CourseRepository.Get(payment.CourseId).Name, 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) private void toolStripButton2_Click(object sender, EventArgs e)
{ {
this.ActiveControl = null;
foreach (DataGridViewRow row in dataGridView1.Rows) foreach (DataGridViewRow row in dataGridView1.Rows)
{ {
try try
@@ -70,8 +72,7 @@ namespace PaymentLogs
FCs = row.Cells["fcs"].Value.ToString(), FCs = row.Cells["fcs"].Value.ToString(),
CourseId = Program.CourseRepository.ByName(row.Cells["course"].Value.ToString()).Id, CourseId = Program.CourseRepository.ByName(row.Cells["course"].Value.ToString()).Id,
CoursePrice = Convert.ToInt32(row.Cells["course_price"].Value), CoursePrice = Convert.ToInt32(row.Cells["course_price"].Value),
Paid = Convert.ToInt32(row.Cells["paid"].Value), Paid = Convert.ToInt32(row.Cells["paid"].Value)
Debt = Convert.ToInt32(row.Cells["debt"].Value)
}; };
Program.PaymentRepository.Update(payment.Id, payment); Program.PaymentRepository.Update(payment.Id, payment);
} }
@@ -109,7 +110,9 @@ namespace PaymentLogs
List<string> list = new List<string> List<string> list = new List<string>
{ row.Cells["id"].Value.ToString(), row.Cells["fcs"].Value.ToString(), { row.Cells["id"].Value.ToString(), row.Cells["fcs"].Value.ToString(),
row.Cells["course"].Value.ToString(), row.Cells["course_price"].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); filtredList.Add(list);
} }
+4 -5
View File
@@ -29,8 +29,7 @@ namespace PaymentLogs.Repositories
FCs = reader.GetString("fcs"), FCs = reader.GetString("fcs"),
CourseId = reader.GetInt32("course_id"), CourseId = reader.GetInt32("course_id"),
CoursePrice = reader.GetInt32("course_price"), CoursePrice = reader.GetInt32("course_price"),
Paid = reader.GetInt32("paid"), Paid = reader.GetInt32("paid")
Debt = reader.GetInt32("debt")
}; };
_data[payment.Id] = payment; _data[payment.Id] = payment;
@@ -45,10 +44,10 @@ namespace PaymentLogs.Repositories
db.openConnection(); db.openConnection();
foreach(Payment payment in _data.Values) foreach(Payment payment in _data.Values)
{ {
string sql = $" INSERT INTO `payments` (`id`, `fcs`, `course_id`, `course_price`, `paid`, `debt`) " + string sql = $" INSERT INTO `payments` (`id`, `fcs`, `course_id`, `course_price`, `paid`) " +
$"VALUES ('{payment.Id}','{payment.FCs}', '{payment.CourseId}', '{payment.CoursePrice}', '{payment.Paid}', '{payment.Debt}') " + $"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}', " + $"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()); MySqlCommand cmd = new MySqlCommand(sql, db.getConnection());
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();