Example #1
0
        private void btn_deleteInvoice_Click(object sender, EventArgs e)
        {
            try
            {
                // Get the invoice ID from the application.
                invoice.InvoiceId = Convert.ToInt32(txtbx_invoiceID.Text);

                // Delete records in Database for all services selected in the combo box.
                DeleteServicesFromDb();

                // Delete records in Database for all prescriptions selected in the combo box.
                DeletePrescriptionsFromDb();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }

            // Delete record from database and assign the return value to variable.
            bool success = invoice.Delete(invoice);

            // If the operation is successful, the method will return TRUE.
            if (success)
            {
                // Successfully deleted.
                MessageBox.Show("Invoice succesfully deleted.");

                // Call the method to refresh DataGrid view after deletion.
                LoadInvoiceDgvData();

                // Call the method to clear all input/selection fields
                Clear();
            }
            else
            {
                // Delete failed.
                MessageBox.Show("Failed to delete invoice. Try again.");
            }
        }