public void PopulatePlaylists() { playlist_list.Clear(); SqlDataReader SAIDA; SqlDataAdapter da2 = new SqlDataAdapter(); if (cn.State == ConnectionState.Closed) { cn.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM SampleKeeper.getPlaylists(@User_ID)", cn); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@User_ID", userid); SAIDA = command.ExecuteReader(); if (SAIDA.HasRows) { while (SAIDA.Read()) { playlist_list.Add(new Playlist(SAIDA.GetInt32(0), SAIDA.GetString(1))); } } SAIDA.Close(); List <string> newlist = new List <string>(); for (int i = 0; i < playlist_list.Count; i++) { newlist.Add(playlist_list[i].nome); } PlaylistBox.ItemsSource = newlist; }
public void PopulateAlbums() { j = 0; i = 1; k = 2; album_list.Clear(); SqlDataReader SAIDA; SqlDataAdapter da2 = new SqlDataAdapter(); if (cn.State == ConnectionState.Closed) { cn.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM SampleKeeper.populate_albums()", cn); command.CommandType = CommandType.Text; SAIDA = command.ExecuteReader(); if (SAIDA.HasRows) { while (SAIDA.Read()) { album_list.Add(new Album(SAIDA.GetString(0), SAIDA.GetString(1), SAIDA.GetInt32(2), SAIDA.GetString(3), SAIDA.GetString(4), SAIDA.GetString(5))); } } SAIDA.Close(); }
public void setList(string value) { int id = 0; for (int i = 0; i < playlist_list.Count; i++) { if (playlist_list[i].nome == value) { id = playlist_list[i].id; break; } } table_list.Clear(); listv.Items.Clear(); SqlDataReader SAIDA; SqlDataAdapter da2 = new SqlDataAdapter(); if (cn.State == ConnectionState.Closed) { cn.Open(); } SqlCommand command = new SqlCommand("SELECT * FROM SampleKeeper.getPlaylistMusics(@playlist_ID)", cn); command.Parameters.AddWithValue("@playlist_ID", id); command.CommandType = CommandType.Text; SAIDA = command.ExecuteReader(); TimeSpan temp; if (SAIDA.HasRows) { while (SAIDA.Read()) { temp = SAIDA.GetTimeSpan(3); table_list.Add(new MyItem { Nome = SAIDA.GetString(0), Artista = SAIDA.GetString(1), Album = SAIDA.GetString(2), Duracao = temp.ToString(), isrc = SAIDA.GetString(4) }); } } SAIDA.Close(); AuthorName.Content = "Created by " + user; for (int k = 0; k < table_list.Count(); k++) { this.listv.Items.Add(table_list[k]); } bool repeated = false; //Música recomendada if (table_list.Count != 0) { for (int i = 0; i < 5; i++) { repeated = false; SqlDataReader reader; Random rnd = new Random(); int r = rnd.Next(table_list.Count - 1); SqlCommand sql2 = new SqlCommand("SELECT * FROM SampleKeeper.getSimilar(@music1)", cn); sql2.Parameters.AddWithValue("@music1", table_list[r].isrc); sql2.CommandType = CommandType.Text; reader = sql2.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { sem_list.Add(new Semelhantes(reader.GetString(0), reader.GetString(1))); } } int r2 = rnd.Next(sem_list.Count - 1); string trmp; Semelhantes tmp = sem_list[r2]; if (tmp.isrc1 == table_list[r].isrc) { trmp = tmp.isrc2; } else { trmp = tmp.isrc1; } reader.Close(); SqlDataReader reader2; SqlCommand sql3 = new SqlCommand("SELECT * FROM SampleKeeper.getMusicWithISRC(@is)", cn); sql3.Parameters.AddWithValue("@is", trmp); sql3.CommandType = CommandType.Text; reader2 = sql3.ExecuteReader(); TimeSpan temp2; if (reader2.HasRows) { while (reader2.Read()) { temp2 = reader2.GetTimeSpan(3); currentRecomendation = new MyItem { Nome = reader2.GetString(0), Artista = reader2.GetString(1), Album = reader2.GetString(2), Duracao = temp2.ToString(), isrc = trmp }; } } reader2.Close(); for (int j = 0; j < table_list.Count; j++) { Console.WriteLine(currentRecomendation.isrc + "/" + table_list[j].isrc); if (currentRecomendation.isrc == table_list[j].isrc) { repeated = true; break; } } Console.WriteLine("--------"); if (currentRecomendation != null && !repeated) { Console.WriteLine("PASSOU"); setLabels(currentRecomendation); break; } } } }