//Begin listview playing list operation private void LvPlayItemRemove_Click(object sender, RoutedEventArgs e) { if (MessageBoxEx.Show("Delete this music?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } else { if (LvPlay.SelectedItem != null) { try { TreeViewItem item = (TreeViewItem)TvPlaylists.SelectedItem; if (item.Header != null) { string plName = (string)item.Header; db.GetPlaylistByName(plName); ListPlaying = db.GetSongByPlaylistName(plName); Song song = (Song)LvPlay.SelectedItem; int songId = song.Id; ListPlaying.RemoveAt(LvPlay.SelectedIndex); db.DeletePlaylistFromLibBySongIdAndplName(song.Id, plName); RefreshListViewPlaying(); return; } } catch (System.ArgumentOutOfRangeException ex) { MessageBoxEx.Show("ListPlaying Remove failed" + ex.StackTrace); } } else { MessageBoxEx.Show("You should select a music"); } } }
private void PropertyWindow_Loaded(object sender, RoutedEventArgs e) { //song = (Song)ListMusicLibrary[lvLi]; if (song == null) { MessageBoxEx.Show("PropertyWindow load Error media is null"); return; } else { tbSongTitle.Text = song.Title; tbArtistName.Text = song.ArtistName; tbAlbumName.Text = song.AlbumId + ""; tbAlbumId.Text = song.AlbumId + ""; tbSequenceId.Text = song.SequenceId + ""; tbPath.Text = song.PathToFile; string date = song.Year.ToString("yyyy"); tbYear.Text = date; tbGenre.Text = song.Genre; tbRating.Text = song.Rating + ""; tbDescription.Text = song.Description; } }
private void BtPropertySave_Click(object sender, RoutedEventArgs e) { String title = tbSongTitle.Text; String artistName = tbArtistName.Text; String albumName = tbAlbumName.Text; int sequenceId = Convert.ToInt32(tbSequenceId.Text); int AlbumId = Convert.ToInt32(tbAlbumId.Text); String pathToFile = tbPath.Text; //DateTime dt = Convert.ToDateTime(tbYear.Text); Regex regex = new Regex(@"\d+"); String input_year = tbYear.Text; int yearInt = 1000; if (Regex.IsMatch(input_year, "^(19|20)[0-9][0-9]")) { yearInt = Convert.ToInt32(tbYear.Text); } else { MessageBoxEx.Show("Please input 4 digital year"); return; } //To Do Format date and validation uint yearUint = (uint)(yearInt); String genre = tbGenre.Text; string date = song.Year.ToString("yyyy"); int rating = Convert.ToInt32(tbRating.Text); String description = tbDescription.Text; Song new_song = new Song(title, artistName, sequenceId, (int)sequenceId, description, pathToFile, yearUint, genre, rating); db.UpdateSongByPath(new_song); MessageBoxEx.Show("Song of " + new_song.ArtistName + " is being saved"); this.Close(); }
private void MiDelete_Click(object sender, RoutedEventArgs e) { if (MessageBoxEx.Show("Delete this music from library?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } else { if (LvLibrary.SelectedIndex == -1) { return; } else { db.DeleteSongFromLib(ListMusicLibrary[LvLibrary.SelectedIndex]); ListMusicLibrary.RemoveAt(LvLibrary.SelectedIndex); RefreshMusicLibrary(); if (isPlaying) { BtPlay_Click(null, null); } } } }
private void TvPlaylists_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeViewItem item = (TreeViewItem)TvPlaylists.SelectedItem; try { if (item.Header == null) { MessageBoxEx.Show("TreeViewItem playName is Null"); return; } else { string plName = (string)item.Header; db.GetPlaylistByName(plName); ListPlaying = db.GetSongByPlaylistName(plName); LvPlay.ItemsSource = ListPlaying; } } catch (System.NullReferenceException ex) { Console.WriteLine("Item is null" + ex.StackTrace); } }
private void TvPlayListDelete_Click(object sender, RoutedEventArgs e) { string header = ((TreeViewItem)(TvPlaylists.SelectedItem)).Header.ToString(); if (!header.Equals("Playlists") && header != null) { if (MessageBoxEx.Show("Delete this Playlist?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } else { TreeViewItem item = (TreeViewItem)TvPlaylists.SelectedItem; string plName = (string)item.Header; db.DeletePlaylistFromLib(plName); TvPlaylists.Items.Clear(); PopulatePlaylists(); } } else { MessageBoxEx.Show("You should select a playlist"); } }