private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length == 0) { MessageBox.Show("Введите ФИО!"); return; } using (var db = new LibraryContainer()) { var newAuthor = new Authors(); newAuthor.Name = textBox1.Text; foreach (var item in checkedListBox1.SelectedItems) { var book = db.BooksSet.ToList().Find(p => p.Id == (item as Books).Id); newAuthor.Books.Add(book); } db.AuthorsSet.Add(newAuthor); db.SaveChanges(); } this.Close(); }
public AuthorsPanel(Authors authors) { InitializeComponent(); this.Dock = DockStyle.Top; this.BringToFront(); this.BackColor = Flag ? Color.DarkGray : Color.Black; Flag = !Flag; labelName.Text = authors.Name; foreach (var item in authors.Books) { var label = new Label(); label.Font = new Font("Century Gothic", 10f); label.Text = item.Name; label.AutoSize = true; label.ForeColor = Color.White; label.Dock = DockStyle.Top; panelAuthors.Controls.Add(label); label.BringToFront(); } this.authors = authors; ToolTip t = new ToolTip(); t.SetToolTip(buttonDelete, "Удалить книгу"); }