private void DeleteInvoice() { if (MessageBox.Show("Sei sicura di voler cancellare la fattura?", "Cancellazione", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } if (ProformaInvoice.Id == null) { MessageBox.Show("Errore la fattura non è stata caricata correttamente!", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (var db = new Db.PhisioDB()) { if (ProformaInvoice.Id != null) { //Invoice.Deleted = true; foreach (var visit in ProformaInvoice.Visitsproformainvoiceidfkeys) { visit.Payed = false; visit.InvoiceId = null; visit.Invoice = null; visit.Invoiced = false; visit.SaveToDB(); } ProformaInvoice.SaveToDB(); MessageBox.Show("Fattura Eliminata!", "Cancellazione", MessageBoxButtons.OK, MessageBoxIcon.Information); DeletedInvoice?.Invoke(this, new EventArgs()); } } }