private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox3.Text != "" && textBox3.Text != "") { if (textBox4.Text != "") { ScienceBook scienceBook = new ScienceBook(); scienceBook.Name = textBox1.Text; scienceBook.Author = textBox2.Text; scienceBook.Price = Convert.ToDouble(textBox3.Text); scienceBook.Description = textBox4.Text; scienceBook.isBought = false; scienceBook.isBought = false; result = scienceBook; } else { Book book = new Book(); book.Name = textBox1.Text; book.Author = textBox2.Text; book.Price = Convert.ToDouble(textBox3.Text); book.isBought = false; result = book; } DialogResult = DialogResult.OK; this.Close(); } else { statusStrip1.Items.Add("Fill all fields"); } }
private void button4_Click(object sender, EventArgs e) { ChangeEL c = new ChangeEL(); if (c.ShowDialog() == DialogResult.OK) { ScienceBook sb = new ScienceBook() { Name = c.BookName, AmountOfPages = int.Parse(c.Page), Author = c.Author }; libraries.Add(sb); listBox1.Items.Add(sb); } }
private void button3_Click(object sender, EventArgs e) { Book b = libraries[listBox1.SelectedIndex]; ChangeEL c; if (b is ScienceBook) { ScienceBook sb = b as ScienceBook; c = new ChangeEL(sb.Name, sb.AmountOfPages.ToString(), sb.Author); } else { c = new ChangeEL(b.Name, b.AmountOfPages.ToString()); } if (c.ShowDialog() == DialogResult.OK) { b.Name = c.BookName; b.AmountOfPages = int.Parse(c.Page); } }
/// <summary> /// Инициализация авторов и их книг в бд, настройка связей между ними. /// </summary> /// <param name="modelBuilder"></param> public static void Seed(this ModelBuilder modelBuilder) { Author author1 = new Author() { Id = 1, FirstName = "Иван", SurnameName = "Иванов" }; Author author2 = new Author() { Id = 2, FirstName = "Андрей", SurnameName = "Попов" }; Author author3 = new Author() { Id = 3, FirstName = "Елена", SurnameName = "Наумова" }; Book book1 = new Book() { Id = 1, Name = "Book1" }; Book book2 = new Book() { Id = 2, Name = "Book2" }; Book book3 = new Book() { Id = 3, Name = "Book3" }; ScienceBook mkb1 = new ScienceBook() { Id = 4, Name = "МКБ1", Type = "Справочник" }; ScienceBook mkb2 = new ScienceBook() { Id = 5, Name = "МКБ2", Type = "Справочник" }; ScienceBook mkb3 = new ScienceBook() { Id = 6, Name = "МКБ3", Type = "Справочник" }; Magazine magazine1 = new Magazine() { Id = 7, Name = "Чистый дом1", ReaderType = "Для домохозяек" }; Magazine magazine2 = new Magazine() { Id = 8, Name = "Чистый дом2", ReaderType = "Для домохозяек" }; Magazine magazine3 = new Magazine() { Id = 9, Name = "Чистый дом3", ReaderType = "Для домохозяек" }; modelBuilder.Entity <Author>().HasData( author1, author2, author3 ); modelBuilder.Entity <Book>().HasData( book1, book2, book3 ); modelBuilder.Entity <ScienceBook>().HasData( mkb1, mkb2, mkb3 ); modelBuilder.Entity <Magazine>().HasData( magazine1, magazine2, magazine3 ); modelBuilder.Entity <AuthorBook>().HasData( new AuthorBook() { AuthorId = 1, BookId = 1 }, new AuthorBook() { AuthorId = 1, BookId = 2 }, new AuthorBook() { AuthorId = 1, BookId = 3 }, new AuthorBook() { AuthorId = 2, BookId = 4 }, new AuthorBook() { AuthorId = 2, BookId = 5 }, new AuthorBook() { AuthorId = 2, BookId = 6 }, new AuthorBook() { AuthorId = 3, BookId = 7 }, new AuthorBook() { AuthorId = 3, BookId = 8 }, new AuthorBook() { AuthorId = 3, BookId = 9 } ); }
/// <summary> /// Интерактивное меню для добавления книги /// </summary> /// <param name="db"></param> static void AddBookMenu(BookStoreContext db) { Console.WriteLine("1) Обычная книга"); Console.WriteLine("2) Научная книга"); Console.WriteLine("3) Журнал"); Console.Write("Выберите тип книги, который хотите добавить: "); byte menuChoice; if (Byte.TryParse(Console.ReadLine(), out menuChoice)) { Console.WriteLine(); PrintAuthorsList(db); Console.Write("Введите идентификатор его автора: "); Console.WriteLine(); int authorId; if (Int32.TryParse(Console.ReadLine(), out authorId)) { var author = db.Authors.Find(authorId); if (author != null) { Console.Write("Введите название: "); string name = Console.ReadLine(); Book book = null; if (menuChoice == 1) { book = new Book() { Name = name }; } else if (menuChoice == 2) { Console.Write("Введите тип книги (учебник, справочник): "); string type = Console.ReadLine(); book = new ScienceBook() { Name = name, Type = type }; } else if (menuChoice == 3) { Console.Write("Для кого предназначен журнал? "); string reader = Console.ReadLine(); book = new Magazine() { Name = name, ReaderType = reader }; } db.Books.Add(book); author.AuthorBooks.Add(new AuthorBook() { Book = book }); db.SaveChanges(); } else { Console.WriteLine("Автора с таким идентификатором нет в базе"); } } else { Console.WriteLine("Ожидалось целое число"); } } }