public DailyPlaylistPage(User BaseUser, MainWindow main) { InitializeComponent(); user = BaseUser; mainWindow = main; Recommender recommender = new Recommender(db); playlist = recommender.getDailyPlaylist(user.UserID, "Daily Playlist"); _PlaylistID = playlist.playlistID; _PlaylistName = playlist.playlistName; Console.WriteLine(_PlaylistName); SongsInPlaylist = playlist.GetSongsInPlaylist(); Thickness SongBlockThickness = new Thickness(5, 2, 0, 0); SolidColorBrush whiteText = new SolidColorBrush(System.Windows.Media.Colors.White); StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; var PlaylistBlock = new TextBlock { Text = $"{playlist.playlistName}", FontSize = 25, Foreground = whiteText, Margin = new Thickness(0, 10, 0, 5), }; var PlayPlaylistButton = new Button { Name = $"_{_PlaylistID}", Content = "Play", FontSize = 30, Margin = new Thickness(0, 10, 25, 0), Padding = new Thickness(5), BorderThickness = new Thickness(0), Height = 50, Width = 100 }; PlayPlaylistButton.Click += PlayPlaylist; sp.Children.Add(PlayPlaylistButton); sp.Children.Add(PlaylistBlock); DailyPlaylistName.Children.Add(sp); OrderList.RowDefinitions.Add(new RowDefinition()); // Add the Songname text block to the Songlist grid var OrderName = new TextBlock { Name = "Name", Text = "Name", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderName, 0); Grid.SetColumn(OrderName, 1); // Add the artist text block to the Songlist grid var OrderArtist = new TextBlock { Name = $"Artist", Text = $"Artist", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderArtist, 0); Grid.SetColumn(OrderArtist, 2); // Add the album text block to the Songlist grid var OrderAlbum = new TextBlock { Name = $"Album", Text = $"Album", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderAlbum, 0); Grid.SetColumn(OrderAlbum, 3); // Add the year text block to the Songlist grid var OrderYear = new TextBlock { Name = $"Year", Text = $"Year", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderYear, 0); Grid.SetColumn(OrderYear, 4); // Add the elements to the Songlist grid Children collection OrderList.Children.Add(OrderName); OrderList.Children.Add(OrderArtist); OrderList.Children.Add(OrderAlbum); OrderList.Children.Add(OrderYear); //Adds the necessary amount of rows for the playlist for (int i = 0; i < playlist.songPlaylist.Count; i++) { Song playlistSong = playlist.songPlaylist[i]; RowDefinition rowDef = new RowDefinition(); rowDef.Name = $"Row_{i}"; DailySongList.RowDefinitions.Add(rowDef); RowDefinitionCollection RowNames = DailySongList.RowDefinitions; Array RowArray = RowNames.ToArray(); // Add the play button to the Songlist grid var PlayButton = new Button { Name = $"__{playlistSong.SongID}", Content = "Play", Margin = new Thickness(5, 0, 0, 5), Padding = new Thickness(5), BorderThickness = new Thickness(0), FontSize = 15, Tag = playlistSong }; Grid.SetRow(PlayButton, i); Grid.SetColumn(PlayButton, 0); PlayButton.Click += PlaySongFromPlaylist; // Add the Songname text block to the Songlist grid var SongBlockName = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.SongName}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockName, i); Grid.SetColumn(SongBlockName, 1); // Add the artist text block to the Songlist grid var SongBlockArtist = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Artist}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockArtist, i); Grid.SetColumn(SongBlockArtist, 2); // Add the album text block to the Songlist grid var SongBlockAlbum = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Album}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockAlbum, i); Grid.SetColumn(SongBlockAlbum, 3); // Add the year text block to the Songlist grid var SongBlockYear = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Year}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockYear, i); Grid.SetColumn(SongBlockYear, 4); // Add the elements to the Songlist grid Children collection DailySongList.Children.Add(PlayButton); DailySongList.Children.Add(SongBlockName); DailySongList.Children.Add(SongBlockArtist); DailySongList.Children.Add(SongBlockAlbum); DailySongList.Children.Add(SongBlockYear); ContextMenu menu = new ContextMenu(); menu.Background = new SolidColorBrush(System.Windows.Media.Colors.Black); menu.Foreground = new SolidColorBrush(System.Windows.Media.Colors.White); DailySongList.ContextMenu = null; DailySongList.MouseRightButtonDown += new MouseButtonEventHandler(SongContextMenuOpening); } }
public void reinitialize(Playlist playlist, MainWindow main, User BaseUser) { InitializeComponent(); SongList.Children.Clear(); PlaylistName.Children.Clear(); DeletePlaylist.Children.Clear(); RecommendedSongList.Children.Clear(); Recommender recommender = new Recommender(db); RecommendedSongs = recommender.GetRecommendedSongsForPlaylist(playlist, 5); RecommendedAds = recommender.GetRecommendedAdsFromPlaylist(playlist); playlistToUse = playlist; mainWindow = main; user = BaseUser; _PlaylistName = playlistToUse.playlistName; _PlaylistID = playlistToUse.playlistID; switch (orderBy) { case "name": playlistToUse.songPlaylist = playlistToUse.songPlaylist.OrderBy(x => x.SongName).ToList(); break; case "album": playlistToUse.songPlaylist = playlistToUse.songPlaylist.OrderBy(x => x.Album).ToList(); break; case "year": playlistToUse.songPlaylist = playlistToUse.songPlaylist.OrderBy(x => x.Year).ToList(); break; case "artist": playlistToUse.songPlaylist = playlistToUse.songPlaylist.OrderBy(x => x.Artist).ToList(); break; default: playlistToUse.songPlaylist = playlistToUse.songPlaylist.OrderBy(x => x.SongID).ToList(); break; } user = BaseUser; SongsInPlaylist = playlist.GetSongsInPlaylist(); Thickness SongBlockThickness = new Thickness(5, 2, 0, 0); SolidColorBrush whiteText = new SolidColorBrush(System.Windows.Media.Colors.White); StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; StackPanel sp1 = new StackPanel(); sp1.Orientation = Orientation.Horizontal; var PlaylistBlock = new TextBlock { Text = $"{playlistToUse.playlistName}", FontSize = 25, Foreground = whiteText, Margin = new Thickness(0, 10, 0, 5) }; var PlayPlaylistButton = new Button { Name = $"_{_PlaylistID}", Content = "Play", FontSize = 30, Margin = new Thickness(10, 10, 25, 0), Padding = new Thickness(5), BorderThickness = new Thickness(0), Height = 50, Width = 100 }; PlayPlaylistButton.Click += PlayPlaylist; var DeletePlaylistButton = new Button { Name = $"Delete_{_PlaylistID}", Content = "Delete", Tag = playlistToUse, FontSize = 15, Margin = new Thickness(10, 10, 0, 5) }; DeletePlaylistButton.Click += DeletePlaylistClick; var RenamePlaylistButton = new Button { Name = $"Rename_{_PlaylistID}", Content = "Rename", Tag = playlistToUse, FontSize = 15, Margin = new Thickness(-50, 10, 0, 5) }; RenamePlaylistButton.Click += RenamePlaylist; sp.Children.Add(PlayPlaylistButton); sp.Children.Add(PlaylistBlock); sp1.Children.Add(RenamePlaylistButton); sp1.Children.Add(DeletePlaylistButton); DeletePlaylist.Children.Add(sp1); PlaylistName.Children.Add(sp); OrderList.RowDefinitions.Add(new RowDefinition()); // Add the Songname text block to the Songlist grid var OrderName = new TextBlock { Name = "Name", Text = "Name", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderName, 0); Grid.SetColumn(OrderName, 1); OrderName.MouseLeftButtonUp += (sender, args) => { _orderBy = "name"; OnLabelClick(sender, args); }; // Add the artist text block to the Songlist grid var OrderArtist = new TextBlock { Name = $"Artist", Text = $"Artist", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderArtist, 0); Grid.SetColumn(OrderArtist, 2); OrderArtist.MouseLeftButtonUp += (sender, args) => { _orderBy = "artist"; OnLabelClick(sender, args); }; // Add the album text block to the Songlist grid var OrderAlbum = new TextBlock { Name = $"Album", Text = $"Album", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderAlbum, 0); Grid.SetColumn(OrderAlbum, 3); OrderAlbum.MouseLeftButtonUp += (sender, args) => { _orderBy = "album"; OnLabelClick(sender, args); }; // Add the year text block to the Songlist grid var OrderYear = new TextBlock { Name = $"Year", Text = $"Year", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(OrderYear, 0); Grid.SetColumn(OrderYear, 4); OrderYear.MouseLeftButtonUp += (sender, args) => { _orderBy = "year"; OnLabelClick(sender, args); }; // Add the elements to the Songlist grid Children collection OrderList.Children.Add(OrderName); OrderList.Children.Add(OrderArtist); OrderList.Children.Add(OrderAlbum); OrderList.Children.Add(OrderYear); //Adds the necessary amount of rows for the playlist for (int i = 0; i < SongsInPlaylist.Count; i++) { Song playlistSong = SongsInPlaylist[i]; RowDefinition rowDef = new RowDefinition(); rowDef.Name = $"Row_{i}"; SongList.RowDefinitions.Add(rowDef); RowDefinitionCollection RowNames = SongList.RowDefinitions; Array RowArray = RowNames.ToArray(); SolidColorBrush btnTextColor = new SolidColorBrush(); btnTextColor.Color = Color.FromRgb(0, 0, 0); // Add the play button to the Songlist grid var PlayButton = new Button { Name = $"__{playlistSong.SongID}", Content = "Play", Margin = new Thickness(5, 0, 0, 5), Padding = new Thickness(5), BorderThickness = new Thickness(0), FontSize = 15, Tag = playlistSong }; Grid.SetRow(PlayButton, i); Grid.SetColumn(PlayButton, 0); PlayButton.Click += PlaySongFromPlaylist; // Add the Songname text block to the Songlist grid var SongBlockName = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.SongName}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockName, i); Grid.SetColumn(SongBlockName, 1); // Add the artist text block to the Songlist grid var SongBlockArtist = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Artist}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockArtist, i); Grid.SetColumn(SongBlockArtist, 2); // Add the album text block to the Songlist grid var SongBlockAlbum = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Album}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockAlbum, i); Grid.SetColumn(SongBlockAlbum, 3); // Add the year text block to the Songlist grid var SongBlockYear = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Year}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockYear, i); Grid.SetColumn(SongBlockYear, 4); // Add the elements to the Songlist grid Children collection SongList.Children.Add(PlayButton); SongList.Children.Add(SongBlockName); SongList.Children.Add(SongBlockArtist); SongList.Children.Add(SongBlockAlbum); SongList.Children.Add(SongBlockYear); SongList.MouseRightButtonDown -= SongContextMenuOpening; SongList.MouseRightButtonDown += new MouseButtonEventHandler(SongContextMenuOpening); } List <Song> RecommendedSongsAndAds = new List <Song>(RecommendedAds); foreach (Song song in RecommendedSongs) { RecommendedSongsAndAds.Add(song); } for (int i = 0; i < RecommendedSongsAndAds.Count(); i++) { int amount = RecommendedAds.Count; Song playlistSong = RecommendedSongsAndAds[i]; RowDefinition rowDef = new RowDefinition(); rowDef.Name = $"Row_{i}"; RecommendedSongList.RowDefinitions.Add(rowDef); RowDefinitionCollection RowNames = RecommendedSongList.RowDefinitions; Array RowArray = RowNames.ToArray(); // Add the play button to the Songlist grid var PlayButton = new Button { Name = $"__{playlistSong.SongID}", Content = "Play", Margin = new Thickness(5, 0, 0, 5), Padding = new Thickness(5), BorderThickness = new Thickness(0), FontSize = 15, Tag = playlistSong }; Grid.SetRow(PlayButton, i); Grid.SetColumn(PlayButton, 0); PlayButton.Click += (ob, s) => { db.AddCreditsFromSongClick(true, playlistSong.SongID); PlaySongFromPlaylist(ob, s); }; var SongBlockName = new TextBlock { Name = $"_{playlistSong.SongID}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; // Add the Songname text block to the Songlist grid if (i < amount) { SongBlockName.Text = $"(Ad) {playlistSong.SongName}"; db.UpdateTimesDisplayedAd(playlistSong.SongID); } else { SongBlockName.Text = $"{playlistSong.SongName}"; } Grid.SetRow(SongBlockName, i); Grid.SetColumn(SongBlockName, 1); // Add the artist text block to the Songlist grid var SongBlockArtist = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Artist}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockArtist, i); Grid.SetColumn(SongBlockArtist, 2); // Add the album text block to the Songlist grid var SongBlockAlbum = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Album}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockAlbum, i); Grid.SetColumn(SongBlockAlbum, 3); // Add the year text block to the Songlist grid var SongBlockYear = new TextBlock { Name = $"_{playlistSong.SongID}", Text = $"{playlistSong.Year}", Foreground = whiteText, Margin = SongBlockThickness, FontSize = 15 }; Grid.SetRow(SongBlockYear, i); Grid.SetColumn(SongBlockYear, 4); // Add the elements to the Songlist grid Children collection RecommendedSongList.Children.Add(PlayButton); RecommendedSongList.Children.Add(SongBlockName); RecommendedSongList.Children.Add(SongBlockArtist); RecommendedSongList.Children.Add(SongBlockAlbum); RecommendedSongList.Children.Add(SongBlockYear); ContextMenu menu = new ContextMenu(); menu.Background = new SolidColorBrush(System.Windows.Media.Colors.Black); menu.Foreground = new SolidColorBrush(System.Windows.Media.Colors.White); RecommendedSongList.ContextMenu = null; RecommendedSongList.MouseRightButtonDown += new MouseButtonEventHandler(SongContextMenuFromRecommended); } }