private void comboBoxArtist_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Show the Songs and Albums from the selected Artist. CDCatalogProcess.FilterSongsByArtist((Artist)comboBoxArtist.SelectedItem); listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.songsAndAlbums; }
private void btnRateSongGo_Click(object sender, RoutedEventArgs e) { //It shouldn't be possible to submit this form with an invalid value for Rating, //so no validation is needed. CDCatalogProcess.RateSongGo(song, (comboBoxRateSongRating.SelectedIndex)); this.Close(); }
private void comboBoxAlbum_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Show the Songs on the selected Album. CDCatalogProcess.FilterSongsByAlbum((Album)comboBoxAlbum.SelectedItem); listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.filteredSongList; }
private void btnAddAlbumAddTrack_Click(object sender, RoutedEventArgs e) { //Adding a track is not the same as adding a song to the database. I don't want to add //anything to the DB until it's time to add everything, because if the user cancels out before finishing, //there will be a partial, and probably incorrect, Album and Songs in the DB. //So instead, I've created a temporary List<> that holds all the info I need to add a Song to the DB, //and when the user commits the Album, I'll iterate through the List and add all the Songs at once. string message; if (CDCatalogProcess.AddAlbumVerifyTrack( txtAddAlbumTrackNumIn.Text, txtAddAlbumTrackTitleIn.Text, (Genre)comboBoxAddAlbumGenreIn.SelectedItem, (Artist)comboBoxAddAlbumSongArtist.SelectedItem, txtAddAlbumTrackLengthMinIn.Text, txtAddAlbumTrackLengthSecIn.Text, comboBoxAddAlbumTrackRating.SelectedIndex, out message)) { listBoxAddAlbumSongs.DataContext = null; listBoxAddAlbumSongs.DataContext = CDCatalogProcess.addAlbumTrackList; //Clean up input fields txtAddAlbumTrackNumIn.Text = ""; txtAddAlbumTrackLengthMinIn.Text = ""; txtAddAlbumTrackLengthSecIn.Text = ""; txtAddAlbumTrackTitleIn.Text = ""; } else { MessageBox.Show(message); } }
public void RefreshUIElements() { //When manipulating controls in code, it's best to remove event handlers that are intended to react to user actions. //When each FilterGrid is enabled, its appropriate handler will be reattached. comboBoxAlbum.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxAlbum_SelectionChanged)); comboBoxArtist.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxArtist_SelectionChanged)); comboBoxGenre.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxGenre_SelectionChanged)); comboBoxPlaylist.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxPlaylist_SelectionChanged)); CDCatalogProcess.RefreshMainWindowLists(); comboBoxAlbum.DataContext = null; comboBoxAlbum.DataContext = CDCatalogProcess.filterAlbumList; comboBoxAllSongs.DataContext = null; comboBoxAllSongs.DataContext = CDCatalogProcess.displaySongList; comboBoxArtist.DataContext = null; comboBoxArtist.DataContext = CDCatalogProcess.filterArtistList; comboBoxGenre.DataContext = null; comboBoxGenre.DataContext = CDCatalogProcess.filterGenreList; comboBoxPlaylist.DataContext = null; comboBoxPlaylist.DataContext = CDCatalogProcess.filterPlaylistList; listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.songsAndAlbums; rbViewOptionsAll.IsChecked = true; }
private void btnCreatePlaylistGo_Click(object sender, RoutedEventArgs e) { //Collect and validate inputs: //Name should be any string //Length should be a positive integer //BUGBUG: All this validation code should really be in the Process layer. //BUGBUG: Validation code does not check for duplicate playlist name in database. int length = CDCatalogProcess.CreatePlaylistValidateLength(txtCreatePlaylistMinutes.Text); if (length > 0 && txtCreatePlaylistName.Text.Length > 0) { int duration = CDCatalogProcess.CreatePlaylistGo(txtCreatePlaylistName.Text, length); int secondsperminute = 60; listBoxPlaylistSongs.DataContext = CDCatalogProcess.subWindowPlaylistSongs; int durationminutes = (duration / secondsperminute); int durationseconds = (duration % secondsperminute); lblCreatePlaylistActualLength.Content = ("Playlist will run for " + durationminutes.ToString() + ":" + durationseconds.ToString()); } else { string message = "Something is wrong.\n"; if (length <= 0) { message += "Time must be a positive integer.\n"; } if (txtCreatePlaylistName.Text == "") { message += "Playlist name cannot be empty."; } MessageBox.Show(message); } //Create playlist //Display playlist in listbox --handled by MainWindow. }
private void comboBoxPlaylist_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Show the Songs in the selected Playlist. CDCatalogProcess.FilterSongsByPlaylist((Playlist)comboBoxPlaylist.SelectedItem); listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.filteredSongList; }
private void comboBoxGenre_SelectionChanged(object sender, SelectionChangedEventArgs e) { //Show the Songs in the selected Genre, and the Albums on which //those Songs appear. CDCatalogProcess.FilterSongsByGenre((Genre)comboBoxGenre.SelectedItem); listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.songsAndAlbums; }
private void btnAddAlbumAddGenre_Click(object sender, RoutedEventArgs e) { //From the Add Album window, add a Genre. AddGenre addGenreWindow = new AddGenre(); addGenreWindow.ShowDialog(); comboBoxAddAlbumGenreIn.DataContext = null; CDCatalogProcess.AddSongsFillGenres(); comboBoxAddAlbumGenreIn.DataContext = CDCatalogProcess.subWindowGenreList; comboBoxAddAlbumGenreIn.SelectedIndex = 0; }
private void btnAddGenreGo_Click(object sender, RoutedEventArgs e) { //If there's text in the Genre input field, create the Genre. if (txtGenreName.Text != "") { CDCatalogProcess.AddGenreGo(txtGenreName.Text); this.Close(); } else { MessageBox.Show("Genre Name cannot be empty."); } }
private void btnAddAlbumAddArtist_Click(object sender, RoutedEventArgs e) { //From the Add Album window, add an Artist. AddArtist addArtistWindow = new AddArtist(); addArtistWindow.ShowDialog(); comboBoxAddAlbumArtist.DataContext = null; comboBoxAddAlbumSongArtist.DataContext = null; CDCatalogProcess.AddSongsFillArtists(); comboBoxAddAlbumArtist.DataContext = CDCatalogProcess.subWindowArtistList; comboBoxAddAlbumSongArtist.DataContext = CDCatalogProcess.subWindowArtistList; comboBoxAddAlbumArtist.SelectedIndex = 0; }
private void btnAddArtistGo_Click(object sender, RoutedEventArgs e) { //If there's text in the ArtistName input field, create the Artist record in the DB. if (txtArtistName.Text != "") { CDCatalogProcess.AddArtistGo(txtArtistName.Text); this.Close(); } else { MessageBox.Show("Artist Name cannot be empty."); } }
public AddAlbum(MainWindow caller) { InitializeComponent(); CDCatalogProcess.AddSongsFillArtists(); comboBoxAddAlbumArtist.DataContext = CDCatalogProcess.subWindowArtistList; comboBoxAddAlbumArtist.SelectedIndex = 0; comboBoxAddAlbumSongArtist.DataContext = CDCatalogProcess.subWindowArtistList; comboBoxAddAlbumSongArtist.SelectedIndex = 0; CDCatalogProcess.AddSongsFillGenres(); comboBoxAddAlbumGenreIn.DataContext = CDCatalogProcess.subWindowGenreList; comboBoxAddAlbumGenreIn.SelectedIndex = 0; CDCatalogProcess.addAlbumTrackList.Clear(); invoker = caller; }
private void rbViewOptionsArtist_Checked(object sender, RoutedEventArgs e) { //Set up the UI and display listbox to filter Songs and Albums based on the selected Artist. //All ObjectActions grids Visibility="Hidden" HideAllActionGrids(); HideAllFilterGrids(); //gridArtistActions Visibility="Visible" gridArtistActions.Visibility = Visibility.Visible; gridArtistFilter.Visibility = Visibility.Visible; //lblListBox Content = "Artists" CDCatalogProcess.GetAllArtists(); //listBoxFilterList Content = Artist List comboBoxArtist.DataContext = CDCatalogProcess.filterArtistList; comboBoxArtist.AddHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxArtist_SelectionChanged)); comboBoxArtist.SelectedIndex = 0; }
private void SetUpUI() { //Populate all the combobox controls in the AddSong window. comboBoxAddSongArtist.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxAddSongArtist_SelectionChanged)); comboBoxAddSongAlbum.RemoveHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxAddSongAlbum_SelectionChanged)); CDCatalogProcess.AddSongsFillArtists(); comboBoxAddSongArtist.DataContext = CDCatalogProcess.subWindowArtistList; comboBoxAddSongArtist.SelectedIndex = -1; CDCatalogProcess.AddSongsFillAlbums(); comboBoxAddSongAlbum.DataContext = CDCatalogProcess.subWindowAlbumList; comboBoxAddSongAlbum.SelectedIndex = -1; CDCatalogProcess.AddSongsFillGenres(); comboBoxAddSongGenre.DataContext = CDCatalogProcess.subWindowGenreList; comboBoxAddSongGenre.SelectedIndex = -1; comboBoxAddSongArtist.AddHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxAddSongArtist_SelectionChanged)); comboBoxAddSongAlbum.AddHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxAddSongAlbum_SelectionChanged)); }
private void rbViewOptionsGenre_Checked(object sender, RoutedEventArgs e) { //Set up the UI and display listbox to filter Songs based on the selected Genre, //and show all Albums on which a matching Song appears. //All ObjectActions grids Visibility="Hidden" HideAllActionGrids(); HideAllFilterGrids(); //gridGenreActions Visibility="Visible" gridGenreActions.Visibility = Visibility.Visible; gridGenreFilter.Visibility = Visibility.Visible; //lblListBox Content = "Genres" CDCatalogProcess.GetAllGenres(); //listBoxFilterList Content = Genre List comboBoxGenre.DataContext = CDCatalogProcess.filterGenreList; comboBoxGenre.AddHandler(ComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(comboBoxGenre_SelectionChanged)); comboBoxGenre.SelectedIndex = 0; }
private void btnSearchTitle_Click(object sender, RoutedEventArgs e) { //Filter the Songs and Albums display based on the search string entered by the user. if (txtSearchTitle.Text != "") { CDCatalogProcess.GetSongsandAlbumsByTitle(txtSearchTitle.Text); listBoxSongList.DataContext = null; listBoxSongList.DataContext = CDCatalogProcess.songsAndAlbums; if (CDCatalogProcess.songsAndAlbums.Count == 0) { MessageBox.Show("No matching Songs or Albums found."); } } else { MessageBox.Show("Cannot search on blank title."); } }
private void rbViewOptionsAll_Checked(object sender, RoutedEventArgs e) { //Show all songs and albums in the display listbox. if (!rbViewOptionsAll.IsChecked == true) { //This is also the MainWindow.Loaded event handler, so we need to initialize //the radio button th Checked to provide a consistent UI experience. rbViewOptionsAll.IsChecked = true; } //All ObjectActions grids Visibility="Hidden" HideAllActionGrids(); HideAllFilterGrids(); gridAllSongsFilter.Visibility = Visibility.Visible; //listBoxFilterList Content = clear comboBoxAllSongs.DataContext = null; //Song List = All Songs CDCatalogProcess.GetSongsandAlbums(); listBoxSongList.DataContext = CDCatalogProcess.songsAndAlbums; }
private void btnAddAlbumGo_Click(object sender, RoutedEventArgs e) { //Add the new Album and all associated Songs. string message; if (CDCatalogProcess.addAlbumGo(txtAddAlbumTitle.Text, (Artist)comboBoxAddAlbumArtist.SelectedItem, comboBoxAddAlbumRating.SelectedIndex, txtAddAlbumYear.Text, CDCatalogProcess.addAlbumTrackList, out message)) { invoker.RefreshUIElements(); this.Close(); } else { MessageBox.Show(message); } }
private void button4_Click(object sender, EventArgs e) { CDCatalogProcess.GeneratePlayList("Winforms Test Playlist", 120); Playlist playlist = CDCatalogManager.GetPlaylists().Where(p => p.PlaylistName.Equals("Winforms Test Playlist")).Last(); List <PlaylistSong> pl = CDCatalogManager.GetPlaylistSongs().Where(p => p.PlaylistID.Equals(playlist.PlaylistID)).ToList(); List <Song> songs = new List <Song>(); int totalDuration = 0; foreach (PlaylistSong pls in pl) { songs.Add(CDCatalogManager.GetSongs().Where(s => s.SongID.Equals(pls.SongID)).First()); totalDuration += (CDCatalogManager.GetSongs().Where(s => s.SongID.Equals(pls.SongID)).First()).TrackLength; } dataGridView1.DataSource = songs; textBox1.Text = "Total playlist duration is " + totalDuration.ToString() + " seconds."; //using (CDCatalogEntities db = new CDCatalogEntities()) //{ // Playlist playList = new Playlist(); // playList.PlaylistName = "Test Playlist"; // db.Playlists.Add(playList); // db.SaveChanges(); // List<PlaylistSong> playlistSongList = new List<PlaylistSong>(); // int targetMinutes = 12000; // int targetSeconds = (targetMinutes * 60); // List<Song> songList = db.Songs.OrderByDescending(s => s.TrackLength).ToList(); // playlistSongList = RandomPlaylist(songList, targetSeconds, playList); // List<PlaylistSong> pl = db.PlaylistSongs.Where(p => p.PlaylistID.Equals(playList.PlaylistID)).ToList(); // List<Song> songs = new List<Song>(); //} }
private void btnAddSongSave_Click(object sender, RoutedEventArgs e) { //Submit the Song information for validation and DB update. //If validation fails, show the user the list of error messages provided by the validation code. string message; if (CDCatalogProcess.AddSongGo(txtAddSongTitle.Text, (Artist)comboBoxAddSongArtist.SelectedItem, (Album)comboBoxAddSongAlbum.SelectedItem, txtAddSongTrack.Text, (Genre)comboBoxAddSongGenre.SelectedItem, txtAddSongTrackLengthMinutes.Text, txtAddSongTrackLengthSeconds.Text, comboBoxAddSongRating.SelectedIndex, out message)) { invoker.RefreshUIElements(); this.Close(); } else { MessageBox.Show(message); } }