Exemple #1
0
 private void GetInvoice(int invoiceID)
 {
     try
     {
         invoice = InvoiceDB.GetInvoice(invoiceID);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
Exemple #2
0
        private void DeleteBtn_Click(object sender, EventArgs e)
        {
            if (invoiceIDTextBox.Text.Length == 0)
            {
                MessageBox.Show("Please select an invoice first.");
                return;
            }


            int invoiceID = Convert.ToInt32(invoiceIDTextBox.Text);

            this.GetInvoice(invoiceID);

            DialogResult result = MessageBox.Show("Delete " + invoice.invoiceID + "?",
                                                  "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    if (!InvoiceDB.DeleteInvoice(invoice))
                    {
                        MessageBox.Show("Another user has updated or deleted " +
                                        "that invoice.", "Database Error");
                        this.GetInvoice(invoice.invoiceID);
                        if (invoice != null)
                        {
                            this.DisplayInvoice();
                        }
                        else
                        {
                            this.ClearControls();
                        }
                    }
                    else
                    {
                        this.ClearControls();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Can't delete due to referencial integrity.");
                    //MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
        }