/* * Function to attempt log in to a user account * @PARAMETERS: - song: the song to add * @RETURNS: The User who has been logged in - null if unsuccesful * @AUTHORS: Andrew Davis and Matt Malone * NOTE - Commented code left in by Matt - just in case it breaks */ public bool doInsertTrack(Song song, ISession session) { try { // Call to initialise cluster connection //init(); /// Guid tid = song.getSongID(); String artist = song.getArtist(); String album = song.getAlbum(); int year = song.getYear(); String genre = song.getGenre(); String file_loc = song.getFileLocation(); int length = song.getLength(); String trackname = song.getTrackName(); // Connect to cluster //ISession session = cluster.Connect("maltmusic"); //Guid tid = Guid.NewGuid(); // Prepare and bind statement passing in username String todo = ("insert into tracks (\n" + "track_id, artist, album, year,genre, file_loc,length,track_name)\n" + "values (:tid, :art,:alb,:yr,:gnr,:floc,:len,:tnm) if not exists"); PreparedStatement ps = session.Prepare(todo); BoundStatement bs = ps.Bind(tid, artist, album, year, genre, file_loc, length, trackname); // Execute Query session.Execute(bs); //session.Dispose(); return true; // Catch exceptions } catch (Exception ex) { Console.WriteLine("SOMETHING WENT WRONG in INSERT TRACK: " + ex.Message); return false; } }
//Plays the song the user selected private void lblPlay_Click(object sender, EventArgs e) { Song toAdd = new Song(); //Parse song String[] tmp = selectedSong.Split(','); int x = int.Parse(tmp[0]); int y = int.Parse(tmp[1]); String songName = songLabelsName[x][y].Text; for (int i = 0; i < songs.Count; i++) { if (songs[i].getTrackName().Equals(songName)) { toAdd = songs[i]; break; } } if (toAdd.getTrackName() != null && toAdd.getTrackName() != "") { //Stop currently playing song String filePath = toAdd.getFileLocation(); musicPlayer.stopSong(); //Load album art String imagePath = "../../tracks/" + toAdd.getArtist() + "/" + toAdd.getAlbum() + "/" + toAdd.getAlbum() + ".jpg"; //Send song to music player Playlist toPlay = new Playlist(); toPlay.addSongs(toAdd); musicPlayer.setPlaylist(toPlay, 0); musicPlayer.playCurrentSong(); } pnlOptions.Visible = false; }