public void Delete_Book_from_List(int book_id, bool delete_picture) { book_node iterator = root; if (root == null) { return; } if (root.book.Book_id == book_id) { root.book.Delete(); if (delete_picture == true) { Picture_Events.Delete_The_Picture(root.book.Cover_path_file); } root.book = null; root = root.next; return; } while (iterator.next.book.Book_id != book_id) { iterator = iterator.next; if (iterator.next == null) { MessageBox.Show("CANT FOUND"); return; } } iterator.next.book.Delete(); if (delete_picture == true) { Picture_Events.Delete_The_Picture(iterator.next.book.Cover_path_file); } iterator.next.book = null; iterator.next = iterator.next.next; return; }
private void Add_Click_Func(bool is_edit) { description = tb_description.Text.Replace('\'', ' '); name = (tb_name.Text.Trim()).Replace('\'', ' '); author = cb_author.SelectedItem.ToString(); publisher = cb_publisher.SelectedItem.ToString(); category = cb_category.SelectedItem.ToString(); shelf = cb_shelf.SelectedItem.ToString(); count = (int)numUpDown_count.Value; date = DateTime.Now.ToString(); pic_new_source_path = picture_event.Pic_source_file; lbl_message.Text = ""; // Validations if (tb_name.Text.Trim() == "Book's Name" || tb_name.Text.Trim() == "") { lbl_message.Text = "* Please enter book's name."; lbl_message.ForeColor = Color.Red; tb_name.Focus(); return; } if (cb_author.SelectedIndex == 0) { lbl_message.Text = "* Please choose an author."; lbl_message.ForeColor = Color.Red; cb_author.Focus(); return; } if (cb_publisher.SelectedIndex == 0) { lbl_message.Text = "* Please choose a publisher."; lbl_message.ForeColor = Color.Red; cb_publisher.Focus(); return; } if (cb_category.SelectedIndex == 0) { lbl_message.Text = "* Please choose a category."; lbl_message.ForeColor = Color.Red; cb_category.Focus(); return; } if (tb_description.Text == "Description..." || tb_description.Text == "") { lbl_message.Text = "* Please enter description."; lbl_message.ForeColor = Color.Red; tb_description.Focus(); return; } if (cb_shelf.SelectedIndex == 0) { lbl_message.Text = "* Please choose a shelf."; lbl_message.ForeColor = Color.Red; cb_shelf.Focus(); return; } if (pic_new_source_path == null || pic_new_source_path == pic_default_file) { lbl_message.Text = "* Please choose a picture."; lbl_message.ForeColor = Color.Red; tb_description.Focus(); picture_event.Choose_Image(); return; } Join_Tables(); if (is_edit == false) { picture_event.Copy_The_Picture(name); pic_new_source_path = picture_event.Pic_source_file; Book book = new Book(0, author_id, publisher_id, category_id, main_page.Manager.Employee_id, shelf_id, name, count, date, description, pic_new_source_path, 0, 0); book.Add(); Clear(); } else { if (change_image) { Picture_Events.Delete_The_Picture(book_to_edit.Cover_path_file); picture_event.Copy_The_Picture(name); main_page.Remove_Image_From_Cover_List(book_to_edit.Book_id); book_to_edit.Cover_path_file = picture_event.Pic_source_file; book_to_edit.Cover_Pic_to_Image_List(); change_image = false; } lbl_message.Text = "*Book changed successfully"; lbl_message.ForeColor = Color.LightGreen; book_to_edit.Author_id = author_id; book_to_edit.Publisher_id = publisher_id; book_to_edit.Category_id = category_id; book_to_edit.Shelf_id = shelf_id; book_to_edit.Count = count; book_to_edit.Name = name; book_to_edit.Description = description; book_to_edit.Edit(); main_page.Pnl_book_list.VerticalScroll.Value = 0; main_page.Book_search_list.Delete_All_List(); main_page.Main_book_list.Draw_All_Books(); main_page.Book_searched_already = false; main_page.Main_shelf_list.Delete_All_List(); Shelf.Show_All_Shelf(main_page); } }