private void button1_Click(object sender, EventArgs e) { Recommendations r = new Recommendations(null); r.ShowDialog(); }
private void picRecommend_Click(object sender, EventArgs e) { SongModel songModel = new SongModel(); List<Song> songList = songModel.getAllSongs(); List<Song> songsInPlaylist = thePlaylist.getSongs(); // get all artists List<String> artists = new List<String>(); for (int i = 0; i < thePlaylist.getSongs().Count; i++) { String artist = thePlaylist.getSongs()[i].getArtist(); if (!artists.Contains(artist)) { artists.Add(thePlaylist.getSongs()[i].getArtist()); } } List<Song> suitableSongs = songList.Where(song => artists.Contains(song.getArtist())).ToList(); // get all genres List<String> genres = new List<String>(); for (int i = 0; i < thePlaylist.getSongs().Count; i++) { if (!genres.Contains(thePlaylist.getSongs()[i].getGenre())) { genres.Add(thePlaylist.getSongs()[i].getGenre()); } } List<Song> matchingGenres = songList.Where(song => genres.Contains(song.getGenre())).ToList(); for (int i = 0; i < matchingGenres.Count; i++) { suitableSongs.Add(matchingGenres[i]); } // Remove songs that already exist in playlist for (int j = 0; j < suitableSongs.Count; j++) { for (int i = 0; i < songsInPlaylist.Count; i++) { if (suitableSongs[j].getSongID().Equals(songsInPlaylist[i].getSongID())) { suitableSongs.RemoveAt(j); if (j > 0) { j--; } else { j = -1; } break; } } } // GET SONGS List<Song> selectedSongs = new List<Song>(); while (selectedSongs.Count < 5 && suitableSongs.Count > 0) { Random r = new Random(); bool add = true; int index = r.Next(0, suitableSongs.Count-1); for (int i = 0; i < selectedSongs.Count; i++) { if (selectedSongs[i].getSongID().Equals(suitableSongs[index].getSongID())) { add = false; suitableSongs.RemoveAt(index); break; } } if (add) { selectedSongs.Add(suitableSongs[index]); suitableSongs.RemoveAt(index); } } Recommendations recommendations = new Recommendations(this); recommendations.setSongs(selectedSongs, thePlaylist); recommendations.createAlbums(); recommendations.ShowDialog(); }