private void DeleteCommandMethod() { if (SelectedBook != null) { MessageBoxResult messageBoxResult = MessageBox.Show("Вы уверены, что хотите удалить эту книгу?", "Подтвердите безвозвратное удаление книги", MessageBoxButton.YesNo, MessageBoxImage.Question); if (messageBoxResult == MessageBoxResult.Yes) { LibraryList.Remove(SelectedBook); } } }
/// <summary> /// Remove given collection of controls (representing WBImages) from library; used with front-end button command /// </summary> /// <param name="collection">Collection of controls representing WBImages to be removed (object type since coming from command)</param> private void Remove(object collection) { // Cast the collection of controls to a collection of WBImages System.Collections.IList items = (System.Collections.IList)collection; var selectedImages = items.Cast <WBImage>(); // Remove each WBImage in the collection from the library list foreach (WBImage image in selectedImages.ToList()) { LibraryList.Remove(image); } // Set empty flag if library is empty after removal if (LibraryList.Count < 1) { IsEmpty = true; } // Save changes to last library file SaveLastLibrary(); // Update manager Manager.CheckAndUpdate(); }
/// <summary> /// Checks for any missing images in library (i.e. image exists in library but not on disk); gives /// user message box notif and returns true if missing image(s) found; returns false otherwise /// </summary> /// <returns>True if missing image(s) found, false otherwise</returns> public bool CheckMissing() { List <string> missingImages = new List <string>(); // Loop over each WBImage in library foreach (WBImage image in LibraryList.ToList()) { // Check if image does not exist at WBImage's associated path (or no permissions to that file) if (!File.Exists(image.Path)) { // Add this image's file name to the list of missing images missingImages.Add(Path.GetFileName(image.Path)); // Remove this WBImage from the library LibraryList.Remove(image); } } // If missing images found, show message box explaining this to user and return true if (missingImages.Count > 0) { string message = "The following image files are missing and were removed from the library:\n\n"; foreach (string filename in missingImages) { message += filename + "\n"; } message += "\nThese files may have been moved or deleted, or WallBrite may not have permission to access them. If you're sure " + "the files are still where they were, try running WallBrite as administrator to make sure it has permissions to access them."; FlexibleMessageBox.Show(message, "Missing Files", WinForms.MessageBoxButtons.OK, WinForms.MessageBoxIcon.Warning); return(true); } // If no missing images found, return false return(false); }