private void RemoveAlbum(object sender, RoutedEventArgs e) { string catnumber = ""; for (i = 0; i < album_list.Count; i++) { if (album_list[i].nome == c.currentAlbum) { catnumber = album_list[i].catalog_number; } } if (!verifySGBDConnection()) { return; } SqlCommand cmd = new SqlCommand("SampleKeeper.remove_album", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@catalog_number", catnumber); cmd.Connection = cn; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message); } finally { cn.Close(); SearchWindow window = new SearchWindow(user, userid); window.Show(); this.Close(); } }
private void Button_Click(object sender, RoutedEventArgs e) { SearchWindow sw = new SearchWindow(user, userid); albumlist = sw.album_list; genrelist = sw.genre_list; string var = ""; int var2 = 0; for (int i = 0; i < albumlist.Count; i++) { if (albumlist[i].nome == albumbox.SelectedItem.ToString()) { var = albumlist[i].catalog_number; break; } } for (int i = 0; i < genrelist.Count; i++) { if (genrelist[i].nome == genre.SelectedItem.ToString()) { var2 = genrelist[i].id; Console.Write(var2); break; } } DateTime timestamp = DateTime.ParseExact(duration.Text, "mm:ss", System.Globalization.CultureInfo.CurrentCulture); if (!verifySGBDConnection()) { return; } SqlCommand cmd = new SqlCommand("SampleKeeper.add_music", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@nome", song.Text); cmd.Parameters.AddWithValue("@ISRC", ISRC.Text); cmd.Parameters.AddWithValue("@duracao", timestamp); cmd.Parameters.AddWithValue("@album", var); cmd.Parameters.AddWithValue("@genero", var2); // para alterar? cmd.Parameters.AddWithValue("@path_to", song.Text + ".mp3"); cmd.Connection = cn; if (song.Text == "" || albumbox.SelectedItem == null || genre.SelectedItem == null || duration.Text == "" || ISRC.Text == "") { hidden.Content = "You must fill in all the fields!"; } else if (ISRC.GetLineLength(0) < 15) { hidden.Content = "ISRC must have 15 characters!"; } else { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception("Failed to update contact in database. \n ERROR MESSAGE: \n" + ex.Message); } finally { cn.Close(); } this.Close(); } }