public static void Show(string message, Form theForm) { if (open) { UpdateMessage(message); } if (theForm.InvokeRequired) { theForm.Invoke((MethodInvoker) delegate { Show(message, theForm); }); } else { //if (dialog == null) // dialog = new BusyDialog(); open = true; dialog.ShowMessage(message, theForm); if (OnBusyMessageShown != null) { OnBusyMessageShown(null, new EventArgs()); } } }
private void btnDeleteSelected_Click(object sender, EventArgs e) { using (var uow = UnitOfWorkFactory.CreateUnitOfWork()) { List <ClientEntity> itemsToDelete = new List <ClientEntity>(); var undeletableIds = uow.ClientRepository.GetClientIdsLinkedToFarms(); int undeletableCount = 0; foreach (DataGridViewRow row in dataGridClients.Rows) { ClientEntity doc = (ClientEntity)row.DataBoundItem; if (Convert.ToBoolean(row.Cells[0].Value)) { itemsToDelete.Add(doc); if (undeletableIds.Contains(doc.Id)) { undeletableCount++; } } } if (itemsToDelete.Count() > 0) { if (undeletableCount > 0) { if (MessageBox.Show(string.Format("{0} client(s) cannot be deleted because they are linked to one or more farms. Would you like to continue?", undeletableCount), "Info", MessageBoxButtons.YesNo) == DialogResult.No) { return; } itemsToDelete.RemoveAll(doc => undeletableIds.Contains(doc.Id)); } if (itemsToDelete.Count() > 0 && MessageBox.Show("Are you sure you want to delete the " + itemsToDelete.Count.ToString() + " selected clients(s)?", "Delete?", MessageBoxButtons.YesNo) == DialogResult.Yes) { BusyDialog dialog = new BusyDialog(); dialog.ShowMessage("Deleting...", this.FindForm()); //await CottonDBMS.Cloud.Caching.ClientCache.InvalidateAsync(); uow.ClientRepository.BulkDelete(itemsToDelete); uow.SaveChanges(); dialog.Close(); refresh(); } } else { MessageBox.Show("No records were selected to delete."); } } }