Example #1
0
        protected override void RemoveWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (dgResults.SelectedItems.Count == 0 || dgResults.SelectedItem == null)
            {
                return;
            }

            OnReloading = true;
            if (_materials)
            {
                var repositoryMaterials = dgResults.SelectedItems.OfType <RepositoryMaterial>().ToList();
                if (repositoryMaterials.Count > 0)
                {
                    var failed       = false;
                    var removedCount = 0;
                    if (Global.DeleteQuestion(this))
                    {
                        var progressResources = new ProgressWindow(repositoryMaterials.Count);
                        progressResources.Show(this);
                        foreach (var repositoryMaterial in repositoryMaterials)
                        {
                            if (!RepositoryMaterialsService.Instanse.Remove(repositoryMaterial))
                            {
                                failed = true;
                                Global.DeletionFailed(this);
                            }
                            else
                            {
                                removedCount++;
                            }
                            progressResources.IncreaseProgress();
                        }
                        progressResources.Close();
                        if (repositoryMaterials.Count > 1 && failed)
                        {
                            Global.DeletionSuceededWithSomeFailures(this);
                        }
                        else if (removedCount > 0 & !failed)
                        {
                            Global.DeletionSuceeded(this);
                        }
                        ResetFields();
                        TryToLoad(cmbFilterBy.SelectedIndex);
                    }
                }
            }
            else
            {
                var repositoryItems = dgResults.SelectedItems.OfType <RepositoryItem>().ToList();
                if (repositoryItems.Count > 0)
                {
                    var failed       = false;
                    var removedCount = 0;
                    if (Global.DeleteQuestion(this))
                    {
                        var progressResources = new ProgressWindow(repositoryItems.Count);
                        progressResources.Show(this);
                        foreach (var repositoryItem in repositoryItems)
                        {
                            if (!RepositoryItemsService.Instanse.Remove(repositoryItem))
                            {
                                failed = true;
                                Global.DeletionFailed(this);
                            }
                            else
                            {
                                removedCount++;
                            }
                            progressResources.IncreaseProgress();
                        }
                        progressResources.Close();
                        if (repositoryItems.Count > 1 && failed)
                        {
                            Global.DeletionSuceededWithSomeFailures(this);
                        }
                        else if (removedCount > 0 & !failed)
                        {
                            Global.DeletionSuceeded(this);
                        }
                        ResetFields();
                        TryToLoad(cmbFilterBy.SelectedIndex);
                    }
                }
            }

            OnReloading = false;
        }