public bool DeleteCustomer(int customerid, Session DXSession) { SPG.CustomersDataTable customers = Adapter.GetCustomerByID(customerid); int rowsAffected = 0; if (customers.Count() == 1) { if ((new ItemsBLL()).GetItemsByCustomerID(customerid).Count != 0 || (new ProductionBLL()).GetProductionByCustomerID(customerid).Count != 0 || (new InventoryBLL()).GetInventoryView(null, null, customerid, null, null).Count != 0) { if (MessageBox.Show("You can't delete this customer because there are items or production/inventory assigned to him. Do you want ot mark him as inactive?", "Delete Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { Adapter.InactivateCustomer(customerid); return(true); } else { return(true); } } RelatedCustomerBLL.DeleteRelatedCustomers(GetCustomer(customerid, DXSession)); rowsAffected = Adapter.Delete(customerid, customers[0].ts); } return(Convert.ToBoolean(rowsAffected)); }
private void deleteBarButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (MessageBox.Show("Are you sure you want to delete this customer.", "Delete Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No) { return; } try { if (m_Customer.DeleteCustomer(m_CurrentCustomer.Value, m_CustomersSession) == true) { RelatedCustomerBLL.DeleteRelatedCustomers(CustomersBLL.GetCustomer(m_CurrentCustomer.Value, m_CustomersSession)); BindCustomerSearch(); } else { MessageBox.Show("The customer was not deleted."); } } catch (ApplicationException ex) { MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error); } }