Esempio n. 1
0
        private void LoadListboxPlaylist(object sender)//When user click on "Add to playlist" the listbox of Playlists is filled.
        {
            //get the trackID of the track clicked, so it can be use in the listbox to identify which tracks is going to be add to the selected item
            _clickedButtonValue          = (int)sender;
            AddToNewPlaylisButtontHeight = 30;
            PlaylistListHeight           = 300;
            AllPlaylist.Clear();//clear the ObservableCollection of Playlists to avoid repeated playlists

            foreach (var item in mainWindowViewModel.AllPlaylistsController.AllPlaylists.Playlists)
            {
                AllPlaylist.Add(item);//add all playlist to the OC
            }
        }
Esempio n. 2
0
        private void AddTrackToSelectedPlaylist()//This methode is called from the prop SelectedItem. It adds a track to a clicked playlist.
        {
            bool contains = false;

            foreach (var item in AllTestTrack)           //goes through all tracks
            {
                if (item.TrackId == _clickedButtonValue) //find the matching Id
                {
                    for (int i = 0; i < mainWindowViewModel.AllPlaylistsController.AllPlaylists.Playlists.Count; i++)
                    {
                        //find the matching playlist
                        if (SelectedItem.Equals(mainWindowViewModel.AllPlaylistsController.AllPlaylists.Playlists.ElementAt(i)))
                        {
                            Track  testTrack  = item;
                            int    playlistid = mainWindowViewModel.AllPlaylistsController.AllPlaylists.Playlists.ElementAt(i).TrackListID;
                            string selectsql  = $"SELECT idTrack FROM Track WHERE idTrack IN (SELECT trackID FROM Track_has_Playlist WHERE playlistID = {playlistid})";
                            List <Dictionary <string, object> > ids = DatabaseConnector.SelectQueryDB(selectsql);

                            foreach (var dictionary in ids)
                            {
                                foreach (var key in dictionary)
                                {
                                    if ((int)key.Value == testTrack.TrackId)
                                    {
                                        contains = true;
                                    }
                                }
                            }

                            if (!contains)
                            {
                                mainWindowViewModel.AllPlaylistsController.AllPlaylists.Playlists.ElementAt(i).Tracks.AddLast(testTrack);
                                string sql = $"INSERT INTO Track_has_Playlist VALUES ({item.TrackId}, {SelectedItem.TrackListID} )";
                                DatabaseConnector.InsertQueryDB(sql);
                            }
                            else
                            {
                                IWindowManager windowManager = new WindowManager();
                                windowManager.ShowDialog(new PopUpWindowViewModel(this));
                            }
                        }
                    }
                }
            }
            AllPlaylist.Clear();
            PlaylistListHeight           = 0;
            AddToNewPlaylisButtontHeight = 0;
        }