public void createTempPlaylist(Playlist p) { try { //init(); ISession session = cluster.Connect("maltmusic"); String plName = p.getPlaylistName(); Guid pid = p.getID(); String owner = p.getOwner(); String todo = ("insert into list_playlist (\n" + "playlist_id, owner,playlist_name)\n" + "values (:pid,:own,:plnm) if not exists using TTL 3600"); PreparedStatement ps = session.Prepare(todo); BoundStatement bs = ps.Bind(pid, owner, plName); session.Execute(bs); addToTempPlaylist(p, session); } catch (Exception e) { Console.WriteLine("Exception during playlist create" + e); } }
// public void renamePlaylist(Playlist playlist, String newName) { try { //init(); // Connect to cluster ISession session = cluster.Connect("maltmusic"); // get playlist id and owner Guid play_id = playlist.getID(); String owner = playlist.getOwner(); // Delete Playlist with old name String todo = "delete from list_playlist WHERE playlist_id = :pid"; PreparedStatement ps = session.Prepare(todo); BoundStatement bs = ps.Bind(play_id); session.Execute(bs); // Recreate playlist with new name, same old id // Slightly hacky way of updating a primary key String insert = "insert into list_playlist (\n" + "playlist_id, owner,playlist_name)\n" + "values (:pid,:own,:plnm) if not exists"; PreparedStatement preps = session.Prepare(insert); BoundStatement bounds = preps.Bind(play_id, owner, newName); session.Execute(bounds); } catch (Exception ex) { Console.WriteLine("Renaming a plist broke " + ex); } }
public ViewPlaylist(Playlist playlist, frmMusicPlayer music, User currentUser, HomePage parent) { InitializeComponent(); picSave.Visible = true; //Set player, playlist, user this.musicPlayer = music; this.currentUser = currentUser; this.thePlaylist = playlist; lblPlaylistName.Text = thePlaylist.getPlaylistName(); lblOwner.Text = thePlaylist.getOwner(); this.parent = parent; //Initially hide edit box txtPlaylistNameEdit.Hide(); List<Song> songs = thePlaylist.getSongs(); int numSongs = thePlaylist.getSongs().Count; lblNumSongs.Text = numSongs.ToString(); if (numSongs == 1) { lblNumSongs.Text += " song"; } else { lblNumSongs.Text += " songs"; } //Get total playlist length int totalLength = 0; for (int i = 0; i < songs.Count; i++) { totalLength += songs[i].getLength(); } int hours = totalLength / 3600; int minutes = (totalLength - hours * 3600) / 60; int seconds = totalLength - (hours * 3600) - (minutes * 60); //Set up string saying how long the playlist is String output = ""; if(hours > 0) { output += hours.ToString() + " hours, \n"; } if (minutes > 0) { output += minutes.ToString() + " minutes, \n"; } if (seconds > 0) { output += seconds.ToString() + " seconds, \n"; } if (output.Equals("")) { output = "O seconds"; } else { output = output.Substring(0, output.Length - 3); } //Set length to label lblTime.Text = output; String currUser = this.currentUser.getUsername(); String owner = thePlaylist.getOwner(); String first6 = ""; if (!(thePlaylist.getPlaylistName().Length < 6)) { first6 = thePlaylist.getPlaylistName().Substring(0, 6); } if (currUser.Equals(owner) && first6 != "" ) { if (first6.Equals("$temp$")) { lblPlaylistName.Text = thePlaylist.getPlaylistName().Substring(6); thePlaylist.setName(thePlaylist.getPlaylistName().Substring(6)); } else { picSave.Visible = false; } picRecommend.Visible = true; picPlay.Left = lblPlaylistName.Left + lblPlaylistName.Width + 10; } else { picSave.Left = lblPlaylistName.Left + lblPlaylistName.Width + 10; picPlay.Left = lblPlaylistName.Left + lblPlaylistName.Width + 15 + picSave.Width; picRecommend.Visible = false; } }