private void buttonSave_Click(object sender, EventArgs e)
 {
     if (this.WindowPanelEditor.Controls.Count != 0)
     {
         if (authorTextfield.Text.Trim() != "" && titelSongTextField.Text.Trim() != "")
         {
             int counterForAbsX = 0;
             List <SongComponent> compiledList = new List <SongComponent>();
             foreach (var list in this.WindowPanelEditor.Controls.OfType <Row>())
             {
                 for (int i = 0; i < list.ListWithSongComponents.Count; i++)
                 {
                     SongComponent tempComponent = list.ListWithSongComponents[i];
                     tempComponent.AbsoluteX = counterForAbsX;
                     compiledList.Add(tempComponent);
                     counterForAbsX += 2;
                 }
             }
             using (DatabaseContext db = new DatabaseContext())
             {
                 db.Songs.Add(new Song()
                 {
                     Author = authorTextfield.Text,
                     Level  = Int32.Parse(levelSelectBox.SelectedValue.ToString()),
                     Name   = titelSongTextField.Text
                 });
                 db.SaveChanges();
                 Song song =
                     db.Songs.Select(x => x)
                     .Where(x => x.Name == titelSongTextField.Text && x.Author == authorTextfield.Text)
                     .FirstOrDefault();
                 int songId = song.SongID;
                 foreach (SongComponent sc in compiledList)
                 {
                     sc.songID = songId;
                     sc.X      = (sc.X % 8);
                     db.SongComponents.Add(sc);
                 }
                 db.SaveChanges();
                 MessageBox.Show("Het lied is toegevoegd");
                 wsvc.Show();
                 this.Close();
             }
         }
     }
     else
     {
         MessageBox.Show("U heeft geen rijen aangemaakt");
     }
 }
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (authorTextfield.Text.Trim() != "" && titelSongTextField.Text.Trim() != "")
     {
         int counterForAbsX = 0;
         List <SongComponent> compiledList = new List <SongComponent>();
         foreach (var list in this.WindowPanelEditor.Controls.OfType <Row>())
         {
             for (int i = 0; i < list.ListWithSongComponents.Count; i++)
             {
                 SongComponent tempComponent = list.ListWithSongComponents[i];
                 tempComponent.AbsoluteX = counterForAbsX;
                 compiledList.Add(tempComponent);
                 counterForAbsX += 2;
             }
         }
         if (compiledList.Count == 0)
         {
             MessageBox.Show("Lied bevat geen componenten");
             return;
         }
         using (DatabaseContext db = new DatabaseContext())
         {
             var result = db.Songs.Where(x => x.Name == titelSongTextField.Text && x.Author == authorTextfield.Text);
             if (result.Count() >= 1)
             {
                 MessageBox.Show("Lied met dezelfde titel en auteur bestaat al! Kies a.u.b. een andere titel of auteur.");
                 return;
             }
             Song song = new Song()
             {
                 Author = authorTextfield.Text, Level = Int32.Parse(numericUpDown1.Value.ToString()), Name = titelSongTextField.Text
             };
             db.Songs.Add(song);
             db.SaveChanges();
             int songId = song.SongID;
             foreach (SongComponent sc in compiledList)
             {
                 sc.songID = songId;
                 sc.X      = (sc.X % 8);
                 db.SongComponents.Add(sc);
             }
             db.SaveChanges();
             this.Hide();
             wsvc.Show();
             MessageBox.Show("Het lied is toegevoegd");
         }
     }
 }