//Deletes customer
        private void btnCustomerFormDeleteCust_Click(object sender, EventArgs e)
        {
            if (customerIDTextBox.Text == "")
            {
                MessageBox.Show("No customer selected. Please select a customer to delete.", "Delete Error");
            }
            else
            {
                int currentCust = Convert.ToInt32(customerIDTextBox.Text);
                var editedCust  = (from customer in CustDb.Customers
                                   where customer.CustomerID == currentCust
                                   select customer).Single();

                DialogResult result = MessageBox.Show($"Delete {editedCust.CustomerFName} {editedCust.CustomerLName}?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    try
                    {
                        CustDb.Customers.Remove(editedCust);
                        CustDb.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        this.Close();
                        if (CustDb.Entry(editedCust).State == EntityState.Detached)
                        {
                            MessageBox.Show("Another user has deleted that customer.", "Concurrency Error");
                        }
                        else
                        {
                            MessageBox.Show("Another user has updated that customer.", "Concurrency Error");
                        }
                        CustomersListForm newForm = new CustomersListForm();
                        newForm.Show();
                    }
                    catch (DbUpdateException)
                    {
                        this.Close();
                        MessageBox.Show("Unable to delete customer. The customer has invoices in the invoices table.", "Customer Not Deleted");
                        CustomersListForm newForm = new CustomersListForm();
                        newForm.Show();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
 private void btnAddCustomerFormSaveChanges_Click(object sender, EventArgs e)
 {
     customer.CustomerFName    = customerFNameTextBox.Text;
     customer.CustomerLName    = customerLNameTextBox.Text;
     customer.CustomerPhoneNum = customerPhoneNumTextBox.Text;
     customer.CustomerAddress  = customerAddressTextBox.Text;
     customer.CustomerCity     = customerCityTextBox.Text;
     customer.CustomerState    = customerStateComboBox.SelectedValue.ToString();
     customer.CustomerZipCode  = customerZipCodeTextBox.Text;
     Db.Customers.Add(customer);
     Db.SaveChanges();
     CustomersListForm = new CustomersListForm();
     CustomersListForm.Show();
     this.Close();
 }
 private void btnAddCustomerFormCancel_Click(object sender, EventArgs e)
 {
     CustomersListForm = new CustomersListForm();
     CustomersListForm.Show();
     this.Close();
 }