private void Delete_Click(object sender, EventArgs e) { MusicAlbumsGuideDB context = new MusicAlbumsGuideDB(); Album albumToDelete = context.Albums.Include(p => p.ReleasingLabel).Include(p => p.Author).Include(p => p.Carrier).Include(p => p.Genre).Include(p => p.Type).Where(p => p.AlbumId == currentAlbum.AlbumId).Single(); ReleasingLabel currentReleasingLabel = albumToDelete.ReleasingLabel; string labelName = ""; string authName = ""; if (currentReleasingLabel != null) { if (context.Albums.Where(p => p.ReleasingLabel.ReleasingLabelId == currentReleasingLabel.ReleasingLabelId).ToList().Count == 1) { labelName = albumToDelete.ReleasingLabel.Name; } } // Author currentAuth = albumToDelete.Author; if (currentAuth != null) { if (context.Albums.Where(p => p.Author.AuthorId == currentAuth.AuthorId).ToList().Count == 1) { authName = currentAuth.Name; } } // context.Albums.Remove(albumToDelete); context.SaveChanges(); if (labelName != "") { context.ReleasingLabels.Remove(context.ReleasingLabels.Where(p => p.Name == labelName).Single()); } context.SaveChanges(); if (authName != "") { context.Authors.Remove(context.Authors.Where(p => p.Name == authName).Single()); } context.SaveChanges(); parentForm.HomeButton.PerformClick(); }
public void InitializeItems(List <object> objects) { if (objects.Count != 0) { if (objects[0] is Genre) { foreach (var item in objects) { Genre buf = (Genre)item; this.Items.Add(new CheckComboBoxItem(buf.Name, false)); } return; } if (objects[0] is Author) { foreach (var item in objects) { Author buf = (Author)item; this.Items.Add(new CheckComboBoxItem(buf.Name, false)); } return; } if (objects[0] is Carrier) { foreach (var item in objects) { Carrier buf = (Carrier)item; this.Items.Add(new CheckComboBoxItem(buf.Name, false)); } return; } if (objects[0] is ReleasingLabel) { foreach (var item in objects) { ReleasingLabel buf = (ReleasingLabel)item; this.Items.Add(new CheckComboBoxItem(buf.Name, false)); } return; } if (objects[0] is Database.Models.Type) { foreach (var item in objects) { Database.Models.Type buf = (Database.Models.Type)item; this.Items.Add(new CheckComboBoxItem(buf.Name, false)); } return; } if (objects[0] is string) { foreach (var item in objects) { string buf = (string)item; if (!Items.Contains(new CheckComboBoxItem(buf, false))) { this.Items.Add(new CheckComboBoxItem(buf, false)); } } return; } } }
private void InitializeComboBox(ComboBox box, List <object> objects) { if (objects.Count == 0) { return; } AutoCompleteStringCollection source = new AutoCompleteStringCollection(); if (objects[0] is Album) { for (int i = 0; i < objects.Count; i++) { Album buf = (Album)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is Author) { for (int i = 0; i < objects.Count; i++) { Author buf = (Author)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is Carrier) { for (int i = 0; i < objects.Count; i++) { Carrier buf = (Carrier)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is Genre) { for (int i = 0; i < objects.Count; i++) { Genre buf = (Genre)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is Database.Models.Type) { for (int i = 0; i < objects.Count; i++) { Database.Models.Type buf = (Database.Models.Type)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is ReleasingLabel) { for (int i = 0; i < objects.Count; i++) { ReleasingLabel buf = (ReleasingLabel)objects[i]; box.Items.Add(buf.Name); } return; } if (objects[0] is string) { for (int i = 0; i < objects.Count; i++) { string buf = (string)objects[i]; if (!box.Items.Contains(buf)) { box.Items.Add(buf); } } return; } }
private void InitializeTextBox(TextBox box, List <object> objects) { if (objects.Count == 0) { return; } AutoCompleteStringCollection source = new AutoCompleteStringCollection(); if (objects[0] is Album) { for (int i = 0; i < objects.Count; i++) { Album buf = (Album)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is Author) { for (int i = 0; i < objects.Count; i++) { Author buf = (Author)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is Carrier) { for (int i = 0; i < objects.Count; i++) { Carrier buf = (Carrier)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is Genre) { for (int i = 0; i < objects.Count; i++) { Genre buf = (Genre)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is Database.Models.Type) { for (int i = 0; i < objects.Count; i++) { Database.Models.Type buf = (Database.Models.Type)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is ReleasingLabel) { for (int i = 0; i < objects.Count; i++) { ReleasingLabel buf = (ReleasingLabel)objects[i]; source.Add(buf.Name); } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } if (objects[0] is string) { for (int i = 0; i < objects.Count; i++) { string buf = (string)objects[i]; if (!source.Contains(buf)) { source.Add(buf); } } box.AutoCompleteCustomSource = source; box.AutoCompleteMode = AutoCompleteMode.SuggestAppend; box.AutoCompleteSource = AutoCompleteSource.CustomSource; return; } }