Example #1
0
        private void DeleteRegistrationBtn_Click(object sender, EventArgs e)
        {
            if (registrationListBox.SelectedIndex < 0)
            {
                MessageBox.Show("Please select a registration");
                return;
            }

            Registration registration = (Registration)registrationListBox.SelectedItem;

            string message = $"Are you sure you want to delete Customer #{registration.CustomerID}'s registration?";

            DialogResult result = MessageBox.Show(text: message,
                                                  caption: "Delete?",
                                                  buttons: MessageBoxButtons.YesNo,
                                                  icon: MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                try
                {
                    BookRegistrationDB.Delete(registration.CustomerID);
                    registrationListBox.Items.Remove(registration);
                    MessageBox.Show("Registration deleted");
                }
                catch (SqlException)
                {
                    MessageBox.Show("We are having server issues. Try again later");
                }
                catch (Exception)
                {
                    MessageBox.Show("No registrations were deleted");
                }
            }
        }