private void btnDel_Click(object sender, EventArgs e) { DialogResult question = MessageBox.Show("Are you sure?", "All books for this author will be deleted!", MessageBoxButtons.YesNo); if (question == DialogResult.Yes) { //========================= Author-un silinmesi ==================================== // downcast edirik ve comboBoxda secilmish author ID nomresini authorID-ye veririk string authorID = ((AuthorComboBox)cmbAuthorList.SelectedItem).Value; // AuthorList-den secilmish author ID-ye gore tapib veririk Author tipinde authorToDeleted-e // bir nov apcast olunur ki Author-un icinden lazim olana catsin Author authorToDeleted = AuthorList.GetAuthorByID(authorID); // AuthorList-den Author classina girib Authors siyahisindan // ID-ci uyqun geleni silirik AuthorList.Authors.Remove(authorToDeleted); //================================================================================== //=========== Silinen Author-un Book siyahisinin silinmesi =====================// // silinen group-un icindeki studentleri yeni List massivine yiqiriq List <Book> bookToBedeleted = BookList.GetBookByGroup(authorToDeleted); // ve hemin massiv siralanir ve siyahidaki bookName-ler silinir foreach (Book bookName in bookToBedeleted) { BookList.Books.Remove(bookName); } UpdateAuthorList(); } else { MessageBox.Show("You are cancelled deletion!"); } }
private void btnAdd_Click(object sender, EventArgs e) { string bookName = txtBookName.Text; string bookGenre = txtBookGenre.Text; string bookPrice = txtPrice.Text; //string bookAuthor = txtAuthorName.Text; string bookDescript = txtBookDascript.Text; // secilmish qrupun ID nomresinin groupID-ye verilmesi string authorId = ((BookComboBox)cmbAuthor.SelectedItem).Value; // Author tipinden deyishen yaradiriq // ve author siyahisinin ID-lerinden secilmishini deyishene veririk Author selectedAuthor = AuthorList.GetAuthorByID(authorId); if (selectedAuthor == null) // eger secilmish author yoxdursa { MessageBox.Show("Author doesn't exist"); return; } if (string.IsNullOrEmpty(bookName)) { // ERROR mesajinin verilmersi MessageBox.Show("Book name is not valid", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(bookGenre)) { // ERROR mesajinin verilmersi MessageBox.Show("Book genre is not valid", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(bookDescript)) { // ERROR mesajinin verilmersi MessageBox.Show("Book description is not valid", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(bookPrice)) { // ERROR mesajinin verilmersi MessageBox.Show("Book price is not valid", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // eger AuthorListde bu ad varsa if (BookList.ContainsBookName(bookName)) { // ERROR mesaji verilir MessageBox.Show("Book name is duplicate", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } BookList.AddBook(new Book { BookName = bookName, BookJenre = bookGenre, Price = bookPrice, Description = bookDescript, Authors = selectedAuthor, }); txtBookName.Text = ""; txtBookGenre.Text = ""; txtBookDascript.Text = ""; txtPrice.Text = ""; }