private void btnAddBook_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNameBook.Text)) { MessageBox.Show("Kitab adi daxil edin"); return; } if (string.IsNullOrEmpty(cmbAuthorBook.Text)) { MessageBox.Show("Yazici secin"); return; } if (string.IsNullOrEmpty(cmbJanraBook.Text)) { MessageBox.Show("Janr secin"); return; } if (string.IsNullOrEmpty(dtpDateBook.Text)) { MessageBox.Show("Tarix secin"); return; } if (txtPriceBook.Text == "0") { MessageBox.Show("Kitab Qiymetini daxil edin"); return; } if (txtQuantityBook.Text == "0") { MessageBox.Show("Kitab sayi daxil edin"); return; } BookJanra janraid = _context.BookJanras.FirstOrDefault(u => u.Name == cmbJanraBook.Text); BookAuthor authorId = _context.BookAuthors.FirstOrDefault(u => u.Name == cmbAuthorBook.Text); Book book = new Book() { Name = txtNameBook.Text, AuthorId = Convert.ToInt32(authorId.Id), JanraId = Convert.ToInt32(janraid.Id), PurchaseDate = dtpDateBook.Value, Prise = txtPriceBook.Value, Quantity = Convert.ToInt32(txtQuantityBook.Value), AvaliableQuantity = Convert.ToInt32(txtQuantityBook.Value) }; _context.Books.Add(book); _context.SaveChanges(); MessageBox.Show("Kitab Elave olundu"); }
private void btnJanraAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtJanra.Text)) { MessageBox.Show("Janr Elave Edin"); return; } BookJanra bookJanra = new BookJanra { Name = txtJanra.Text }; _context.BookJanras.Add(bookJanra); _context.SaveChanges(); dgvJanras.Rows.Clear(); FillJanras(); }