private void SaveToDatabase() { MusicAlbumsGuideDB context = new MusicAlbumsGuideDB(); Album newAlbum = new Album(); newAlbum.Name = NameTextBox.Text; Genre currentGenre = context.Genres.Where(p => p.Name == GenreComboBox.Text).Single(); newAlbum.GenreId = currentGenre.GenreId; newAlbum.ReleaseYear = Convert.ToInt32(ReleaseYearTextBox.Text); Carrier currentCarrier = context.Carriers.Where(p => p.Name == CarrierComboBox.Text).Single(); newAlbum.CarrierId = currentCarrier.CarrierId; // Database.Models.Type currentType = context.Types.Where(p => p.Name == TypeComboBox.Text).Single(); newAlbum.TypeId = currentType.TypeId; Author author; try { author = context.Authors.Where(p => p.Name == AuthorTextBox.Text).Single(); } catch (Exception) { context.Authors.Add(new Author() { Name = AuthorTextBox.Text }); context.SaveChanges(); author = context.Authors.Where(p => p.Name == AuthorTextBox.Text).Single(); } newAlbum.AuthorId = author.AuthorId; newAlbum.TrackCount = Convert.ToInt32(TrackCountTextBox.Text); // ReleasingLabel releasingLabel; try { releasingLabel = context.ReleasingLabels.Where(p => p.Name == ReleaseLabelTextBox.Text).Single(); } catch (Exception) { context.ReleasingLabels.Add(new ReleasingLabel() { Name = ReleaseLabelTextBox.Text }); context.SaveChanges(); releasingLabel = context.ReleasingLabels.Where(p => p.Name == ReleaseLabelTextBox.Text).Single(); } newAlbum.ReleasingLabelId = releasingLabel.ReleasingLabelId; newAlbum.CoverPhoto = ImageMethods.ConvertImageToByteArray(CoverAlbum.Image); context.Albums.Add(newAlbum); context.SaveChanges(); }
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; } }