public void DeleteObject() { if (_invoice != null) { InvoicebindingSource.EndEdit(); _invoice = (Invoice)InvoicebindingSource.DataSource; try { foreach (var p in _invoice.MiscellaneousItem.ToList()) { if (p.MisPartId == 0) { _invoice.MiscellaneousItem.Remove(p); } else { _context.MiscellaneousItems.DeleteObject(p); } } foreach (var pr in _invoice.PaymentRecord.ToList()) { if (pr.PaymentId == 0) { _invoice.PaymentRecord.Remove(pr); } else { _context.PaymentRecords.DeleteObject(pr); } } _context.DeleteObject(_invoice); _context.SaveChanges(); Close(); } catch (Exception e) { ViewHelper.ShowDeleteError(); ErrorLogger.LogError(this, e); } } }
public void SaveChanges() { if (!ValidateForm()) { return; } InvoicebindingSource.EndEdit(); _invoice = (Invoice)InvoicebindingSource.DataSource; var rt = GetPaymentTotal(); var it = GetInvoiceTotal(); if (rt == it) { _invoice.Status = (int)InvoiceStatuses.PaidInFull; } else if (rt < it) { _invoice.Status = (int)InvoiceStatuses.OutStanding; } if (_newMode) { _context.Invoices.AddObject(_invoice); } try { _context.SaveChanges(); _newMode = false; } catch (Exception ex) { ViewHelper.ShowErrorMessage("Error occured while saving the current invoice.", ex); return; } }