예제 #1
0
        private void deleteButton_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this song?", "MiniPlayer",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                int songId = Convert.ToInt32(songIdComboBox.SelectedItem);
                Console.WriteLine("Deleting song " + songId);

                if (musicLib.DeleteSong(songId))
                {
                    // Remove the song from the list box and select the next item
                    (songIdComboBox.ItemsSource as ObservableCollection <string>).Remove(
                        songIdComboBox.SelectedItem.ToString());
                    if (songIdComboBox.Items.Count > 0)
                    {
                        songIdComboBox.SelectedItem = songIdComboBox.Items[0];
                    }
                    else
                    {
                        // No more songs to display
                        deleteButton.IsEnabled = false;
                        titleTextBox.Text      = "";
                        artistTextBox.Text     = "";
                        albumTextBox.Text      = "";
                        genreTextBox.Text      = "";
                        lengthTextBox.Text     = "";
                        filenameTextBox.Text   = "";
                    }
                }
                else
                {
                    Console.WriteLine("There was a problem deleting song with the id: " + songId);
                }
            }
        }
예제 #2
0
        private void DeleteCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this song?", "MiniPlayer",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                string songId = songIdComboBox.SelectedItem.ToString();
                Console.WriteLine("Deleting song " + songId);

                musicLib.DeleteSong(Convert.ToInt32(songId));
                // Remove the song from the combo box and select the next item
                songIds.Remove(songIdComboBox.SelectedItem.ToString());
                if (songIdComboBox.Items.Count > 0)
                {
                    songIdComboBox.SelectedItem = songIdComboBox.Items[0];
                }
                else
                {
                    // No more songs to display
                    titleTextBox.Text    = "";
                    artistTextBox.Text   = "";
                    albumTextBox.Text    = "";
                    genreTextBox.Text    = "";
                    lengthTextBox.Text   = "";
                    filenameTextBox.Text = "";
                }
            }
        }
        private void DeleteCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete this song?", "MiniPlayer",
                                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                string songId = songIdComboBox.SelectedItem.ToString();
                Console.WriteLine("Deleting song " + songId);

                //// Search the primary key for the selected song and delete it from
                //// the song table
                //DataTable table = musicDataSet.Tables["song"];
                //table.Rows.Remove(table.Rows.Find(songId));

                //// Remove from playlist_song every occurance of songId.
                //// Add rows to a separate list before deleting because we'll get an exception
                //// if we try to delete more than one row while looping through table.Rows

                //List<DataRow> rows = new List<DataRow>();
                //table = musicDataSet.Tables["playlist_song"];
                //foreach (DataRow row in table.Rows)
                //    if (row["song_id"].ToString() == songId.ToString())
                //        rows.Add(row);

                //foreach (DataRow row in rows)
                //    row.Delete();
                int songIdint = System.Convert.ToInt32(songId);
                musicLib.DeleteSong(songIdint);

                // Remove the song from the combo box and select the next item
                songIds.Remove(songIdComboBox.SelectedItem.ToString());
                if (songIdComboBox.Items.Count > 0)
                {
                    songIdComboBox.SelectedItem = songIdComboBox.Items[0];
                }
                else
                {
                    // No more songs to display
                    titleTextBox.Text    = "";
                    artistTextBox.Text   = "";
                    albumTextBox.Text    = "";
                    genreTextBox.Text    = "";
                    lengthTextBox.Text   = "";
                    filenameTextBox.Text = "";
                }
            }
        }