private void RenameProfile_Click(object sender, RoutedEventArgs e) { UI.InputWindow get = new UI.InputWindow("Enter New Profile Name", ""); if (get.Response != "") { XMLUtilities.RenameProfile(Profiles.SelectedItem.ToString(), get.Response); UpdateProfiles(); } }
private void Edit_Click(object sender, RoutedEventArgs e) { Button senderButt = (Button)sender; //edit button that was clicked List <string> TagsToUpdate; //List of tags string selectedTag = senderButt.Tag.ToString(); //tag associated with edit button that was clicked string updatedTag; //new tag submitted by user in inputWindow string searchString = ";"; //tag string try { UI.InputWindow IW = new UI.InputWindow("Enter new tag name to update", selectedTag); //create new input window for user to input updated tag name IW.ShowDialog(); //show InputWindow updatedTag = IW.Response; //collect inputted tag form InputWindow if (updatedTag != "" && updatedTag != null) //as long as the updated tag isn't empty or null we can go about changing the databases { MessageBoxResult check = MessageBox.Show("Are you sure you Want to Update this Tag?", "Update?", MessageBoxButton.YesNo, MessageBoxImage.Warning); //verify user actually wants to update tag if (check == MessageBoxResult.Yes) { if (fileName != "") //if we are NOT in all tags mode { foreach (string tag in TagNames) //grab each tag and form the tag string with new tag in place of the old tag { if (tag == selectedTag) { searchString = searchString + updatedTag + ";"; } else { searchString = searchString + tag + ";"; } } if (!DB.UpdateTaginImageData(Data, fileName, searchString)) //update tag string in database with updated tag string { throw new Exception("Error updating tag to " + updatedTag + " for file " + fileName); } DB.UpdateTagsCount(Data, selectedTag, false); //decrease count of old tag by one in tags table if (DB.TagExists(Data, updatedTag)) //if updated tag already exists increase its count by one in tags table { DB.UpdateTagsCount(Data, updatedTag, true); } else //if updated tag didn't already exist in tags table add it { if (!DB.AddtoTags(Data, updatedTag)) { throw new Exception("Error adding " + updatedTag + " to Tags Database"); } } if (DB.GetIndividualTagCount(Data, selectedTag) == 0) //if old tag in tags table now has a count of one delete it { DB.DeleteTag(Data, selectedTag); } } else //if we are in all tags mode { FileNames = DB.SearchForFiles(Data, selectedTag); //retrieve all files tagged with selected tag if (FileNames == null) { throw new Exception("Error retrieving files tagged with " + selectedTag); } foreach (string file in FileNames) //for each file { searchString = ";"; TagsToUpdate = DB.GetImageTags(Data, file); //retrieve tags for file if (TagsToUpdate == null) { throw new Exception("Error retrieving tags to update " + selectedTag); } foreach (string tag in TagsToUpdate) //update tag string for file with new tag in place of old tag { if (tag == selectedTag) { searchString = searchString + updatedTag + ";"; } else { searchString = searchString + tag + ";"; } } if (!DB.UpdateTaginImageData(Data, file, searchString)) //update tag string in database with updated tags string { throw new Exception("Error updating tag to " + updatedTag + " for file " + file); } DB.UpdateTagsCount(Data, selectedTag, false); //decrement old tag count in tags table if (DB.TagExists(Data, updatedTag)) //if new tag exists in tags table increment its tag count { DB.UpdateTagsCount(Data, updatedTag, true); } else //if new tag does not exist in tags table add it { if (!DB.AddtoTags(Data, updatedTag)) { throw new Exception("Error adding " + updatedTag + " to Tags Database"); } } if (DB.GetIndividualTagCount(Data, selectedTag) == 0) //if old tag count is now zero delete tag from tags table { DB.DeleteTag(Data, selectedTag); } } } UpdateUI(); } } } catch (Exception ex) { MessageBox.Show("Error editing tag - " + ex.Message); Error.WriteToLog(ex); } }