public decimal TotalPaid(int SupplierInvoiceId) { DataTable dtPaymentToSupplier = BLPaymentToSupplier.GetPaymentToSupplierListBySupplierInvoiceId(APCContext,SupplierInvoiceId); decimal totalPaid = 0; for (int i = 0; i < dtPaymentToSupplier.Rows.Count; i++) { totalPaid = totalPaid + decimal.Parse(dtPaymentToSupplier.Rows[i]["PaymentAmount"].ToString()); } return totalPaid; }
private void btnSubmit_Click(object sender, EventArgs e) { SupplierInvoice supplierInvoice = BLSupplierInvoice.GetSupplierInvoiceListById(APCContext,int.Parse(tbSupplierInvoiceId.Text)).First(); BLPaymentToSupplier.insertPaymentToSupplier(APCContext, supplierInvoice, decimal.Parse(tbPaymentAmount.Text), calPaidDate.Value); //check if payment has been made full - if yes then can mark as paid. if (supplierInvoice.PaymentDue <= TotalPaid(supplierInvoice.Id)) { supplierInvoice.Paid = true; supplierInvoice.PaidDate = DateTime.Now; APCContext.SaveChanges(); } MessageBox.Show("Payment has been recorded"); }