예제 #1
0
        private void deleteCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvCustomers.SelectedRows.Count > 0)
            {
                DialogResult userConfirmation = MessageBox.Show("Are you sure to delete selected customer?", "Confirm", MessageBoxButtons.YesNoCancel);
                if (userConfirmation != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }

                userConfirmation = MessageBox.Show("Are you sure to delete selected customer?", "Confirm", MessageBoxButtons.YesNoCancel);
                if (userConfirmation != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }

                userConfirmation = MessageBox.Show("Are you sure to delete selected customer?", "Confirm", MessageBoxButtons.YesNoCancel);
                if (userConfirmation != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }

                this.Cursor = Cursors.WaitCursor;
                try
                {
                    Customer_ID = Convert.ToInt16(dgvCustomers.SelectedRows[0].Cells["Customer_ID"].Value);
                    using (DataTable dt = objBusinessRules.DeleteCustomer(Customer_ID))
                    {
                        switch (Convert.ToInt16(dt.Rows[0][0]))
                        {
                        case 0:
                        {
                            MessageBox.Show("Customer is having seats booked. Cannot be deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            break;
                        }

                        default:
                        {
                            MessageBox.Show("Customer successfully deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            SearchCustomers(txtSearchFirstName.Text.Trim(), txtSearchLastName.Text.Trim(), txtSearchMobileNo.Text.Trim());
                            break;
                        }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    this.Cursor = DefaultCursor;
                }
            }
        }