Beispiel #1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         var books = booksRepository.SearchBooksByTitle(txtBookName.Text);
         if (books.Count > 1)
         {
             List <Books> foundBooks = new List <Books>();
             foreach (var item in books)
             {
                 if (txtAuthorName.Text == item.AuthorName && txtAuthorFname.Text == item.AuthorFName && txtSubject.Text == item.Price && cmbBoxPublishYear.SelectedItem.ToString() == item.PublishYear)
                 {
                     booksRepository.DeleteBook(item.Code);
                 }
             }
         }
         else if (books.Count == 1)
         {
             booksRepository.DeleteBook(books[0].Code);
         }
         else if (books.Count == 0)
         {
             MessageBox.Show("کتابی با این عنوان یافت نشد", "خطا");
         }
     }
     catch (Exception)
     {
     }
 }
Beispiel #2
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do usuwania książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            booksRepository.DeleteBook(dataGridViewBooks.CurrentRow.Index + 1);

            RefreshDataGridViewBooks();
            ClearTextBoxes();
            labelLastAction.Text = "Usunięto książkę";
        }
        public HttpResponseMessage DeleteBook(int id)
        {
            BooksRepository ctxBook = new BooksRepository();

            ctxBook.DeleteBook(id);
            HttpResponseMessage ms = Request.CreateResponse(HttpStatusCode.Accepted);

            return(ms);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine(Text.appWelcomeMessage);
            BooksRepository bookRepository = new BooksRepository();

            Console.WriteLine(Text.invitationToTheMainAction);
            string currentUserInput;

            while (true)
            {
                ShowWelcomeMenu();
                currentUserInput = Console.ReadLine();
                try
                {
                    if (currentUserInput == "1")
                    {
                        Console.WriteLine(Text.requestForTheBookInput);
                        string bookName = Console.ReadLine();
                        Console.WriteLine(Text.requestForTheYearOfBookPublishInput);
                        string year = Console.ReadLine();
                        Console.WriteLine(Text.requestForTheAuthorsInput);
                        var authorsString = Console.ReadLine();
                        var authors       = authorsString.Split(',');
                        bookRepository.AddBook(bookName, year, authors);
                    }
                    if (currentUserInput == "2")
                    {
                        bookRepository.ShowAuthors();
                    }
                    if (currentUserInput == "3")
                    {
                        bookRepository.ShowBooks();
                    }
                    if (currentUserInput == "4")
                    {
                        bookRepository.ShowAuthors();
                        bookRepository.ShowAuthorsBooks(Console.ReadLine());
                    }
                    if (currentUserInput == "5")
                    {
                        bookRepository.ShowBooks();
                        bookRepository.ShowBooksAuthors(Console.ReadLine());
                    }
                    if (currentUserInput == "6")
                    {
                        bookRepository.ShowBooks();
                        Console.WriteLine(Text.requestFortheBookIndexForDelete);
                        bookRepository.DeleteBook(Console.ReadLine());
                    }
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do usuwania książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            int bookId = int.Parse(textBoxId.Text);

            booksRepository.DeleteBook(bookId);

            RefreshDataGridViewBooks();
            ClearTextBoxes();
            labelLastAction.Text = "Usunięto książkę";
        }
Beispiel #6
0
        /// <summary>
        /// Przycisk odopowiadający za usunięcie książki z bazy biblioteki
        /// po jej ID
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            int bookId = int.Parse(textBoxId.Text);

            // Funkcja usuwająca książkę z bazy
            booksRepository.DeleteBook(bookId);

            // Odświeżenie tabel
            RefreshDataGridViewBooks();
            // Wyczyszczenie okien
            ClearTextBoxes();
        }
Beispiel #7
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     try
     {
         Guid bookcode = Guid.Parse(lblCodeBook.Text);
         booksRepository.DeleteBook(bookcode);
         MessageBox.Show("کتاب حذف گردید", "Success");
     }
     catch (Exception)
     {
     }
 }
Beispiel #8
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do usuwania książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            int id = int.Parse(textBoxId.Text);

            bool isDeleted = booksRepository.DeleteBook(id);

            if (isDeleted)
            {
                RefreshDataGridViewBooks();
                ClearTextBoxes();
                labelLastAction.Text = "Usunięto książkę";
            }
            else
            {
                MessageBox.Show("Ksiązka nie została usunięta sprawdź poprawność paretremów");
            }
        }
Beispiel #9
0
        /// <summary>
        /// Metoda wywoływana po naciśnięciu przycisku do usuwania książki
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            // Pobranie id książki
            int id = int.Parse(textBoxId.Text);
            // Usunięcie książki z bazy
            bool isDeleted = booksRepository.DeleteBook(id);

            // Jeżeli książka została usunięta
            if (isDeleted)
            {
                // Odświeżamy tabelę użytkownika
                RefreshDataGridViewBooks();
                // Czyścimy textboxy
                ClearTextBoxes();
            }
            // Jeżeli nie został, wyświetlamy odpowiedni komunikat
            else
            {
                MessageBox.Show("Ksiązka nie została usunięta sprawdź poprawność parametrów");
            }
        }
Beispiel #10
0
        public MainViewController(string connectionString)
        {
            booksRepo   = new BooksRepository(connectionString);
            readersRepo = new ReadersRepository(connectionString);
            authorsRepo = new AuthorsRepository(connectionString);


            CommandsHandler = new Dictionary <string, Func <MainViewArgs, object> >
            {
                #region booksCRUD
                {
                    "get_books",
                    x =>
                    {
                        string res = "";
                        foreach (var book in booksRepo.GetAllBooks())
                        {
                            res += (book.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                {
                    "get_book",
                    x =>
                    {
                        return(booksRepo.GetBook(x.BookId).ToString());
                    }
                },
                {
                    "delete_book",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.DeleteBook(x.BookId)));
                    }
                },
                {
                    "insert_book",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.InsertBook(x.Book)));
                    }
                },
                {
                    "update_book",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.UpdateBook(x.Book)));
                    }
                },
                #endregion
                #region booksAuthors
                {
                    "AddAuthorToBook",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.AddAuthorToBook(x.AuthorId, x.BookId)));
                    }
                },
                {
                    "DeleteAuthorFromBook",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.DeleteAuthorFromBook(x.AuthorId, x.BookId)));
                    }
                },
                {
                    "GetAuthorsOfBook",
                    x =>
                    {
                        string res = "";
                        foreach (var author in booksRepo.GetAuthorsOfBook(x.BookId))
                        {
                            res += (author.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                #endregion
                #region booksReaders
                {
                    "AddReaderToBook",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.AddReaderToBook(x.ReaderId, x.BookId)));
                    }
                },
                {
                    "DeleteReaderFromBook",
                    x =>
                    {
                        return(GetBooLReturnMessage(booksRepo.DeleteReaderFromBook(x.ReaderId, x.BookId)));
                    }
                },
                {
                    "GetReadersOfBook",
                    x =>
                    {
                        string res = "";
                        foreach (var reader in booksRepo.GetReadersOfBook(x.BookId))
                        {
                            res += (reader.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                #endregion
                #region authorsCRUD
                {
                    "get_authors",
                    x =>
                    {
                        string res = "";
                        foreach (var author in authorsRepo.GetAllAuthors())
                        {
                            res += (author.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                {
                    "get_author",
                    x =>
                    {
                        return(authorsRepo.GetAuthor(x.AuthorId).ToString());
                    }
                },
                {
                    "delete_author",
                    x =>
                    {
                        return(GetBooLReturnMessage(authorsRepo.DeleteAuthor(x.AuthorId)));
                    }
                },
                {
                    "insert_author",
                    x =>
                    {
                        return(GetBooLReturnMessage(authorsRepo.InsertAuthor(x.Author)));
                    }
                },
                {
                    "update_author",
                    x =>
                    {
                        return(GetBooLReturnMessage(authorsRepo.UpdateAuthor(x.Author)));
                    }
                },
                {
                    "get_authorsbooks",
                    x =>
                    {
                        string res = "";
                        foreach (var book in authorsRepo.GetAuthorsBooks(x.AuthorId))
                        {
                            res += (book.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                #endregion
                #region readersCRUD
                {
                    "get_readers",
                    x =>
                    {
                        string res = "";
                        foreach (var reader in readersRepo.GetAllReaders())
                        {
                            res += (reader.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                {
                    "get_reader",
                    x =>
                    {
                        return(readersRepo.GetReader(x.ReaderId).ToString());
                    }
                },
                {
                    "delete_reader",
                    x =>
                    {
                        return(GetBooLReturnMessage(readersRepo.DeleteReader(x.ReaderId)));
                    }
                },
                {
                    "insert_reader",
                    x =>
                    {
                        return(GetBooLReturnMessage(readersRepo.InsertReader(x.Reader)));
                    }
                },
                {
                    "update_reader",
                    x =>
                    {
                        return(GetBooLReturnMessage(readersRepo.UpdateReader(x.Reader)));
                    }
                },
                {
                    "get_readersbooks",
                    x =>
                    {
                        string res = "";
                        foreach (var book in readersRepo.GetReadersBooks(x.ReaderId))
                        {
                            res += (book.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                #endregion
                {
                    "add_random_authors",
                    x =>
                    {
                        return(GetBooLReturnMessage(authorsRepo.AddRandomAuthorsToDB(x.RandomCount)));
                    }
                },
                {
                    "search_books",
                    x =>
                    {
                        string res = "";
                        foreach (var book in booksRepo.SearchBooks(x.SearchBookParameters.title, x.SearchBookParameters.minPagesCount, x.SearchBookParameters.maxPagesCount))
                        {
                            res += (book.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                {
                    "search_authors",
                    x =>
                    {
                        string res = "";
                        foreach (var author in authorsRepo.SearchAuthors(x.SearchAuthorParameters.Signature, x.SearchAuthorParameters.Name, x.SearchAuthorParameters.MinDate))
                        {
                            res += (author.ToString() + "\n");
                        }
                        return(res);
                    }
                },
                {
                    "search_readers",
                    x =>
                    {
                        string res = "";
                        foreach (var reader in readersRepo.SearchReaders(x.SearchReaderParameters.Favouritegenre, x.SearchReaderParameters.Name, x.SearchReaderParameters.Surname))
                        {
                            res += (reader.ToString() + "\n");
                        }
                        return(res);
                    }
                },
            };
        }
Beispiel #11
0
        public IActionResult Delete(int id)
        {
            var newBookId = _booksRepository.DeleteBook(id);

            return(RedirectToAction("Index"));
        }
Beispiel #12
0
 public IActionResult Delete(Book book)
 {
     _booksRepository.DeleteBook(book.Id);
     return(RedirectToAction("index"));
 }
Beispiel #13
0
 public void Delete(int?id)
 {
     _BooksRepository.DeleteBook(id);
 }