public void BorrowBook() { var borrowbookwindow = new BorrowBooksWindow(); borrowbookwindow.DataContext = this; var result = borrowbookwindow.ShowDialog(); if (result == true) { SelectedBook.BookAvailability = Availability.UNAVAILABLE.ToString(); SelectedBook.BookDateBorrowed = bookdateborrowed; if (SelectedBorrower.BorrowerType == "Student") { SelectedBook.BookDateDeadline = SelectedBook.BookDateBorrowed.AddDays(7); MessageBox.Show("Date Borrowed: " + SelectedBook.BookDateBorrowed.ToString("MMMM dd, yyyy") + "\n" + "Date Deadline: " + SelectedBook.BookDateDeadline.ToString("MMMM dd, yyyy")); } else { SelectedBook.BookDateDeadline = SelectedBook.BookDateBorrowed.AddDays(14); MessageBox.Show("Date Borrowed: " + SelectedBook.BookDateBorrowed.ToString("MMMM dd, yyyy") + "\n" + "Date Deadline: " + SelectedBook.BookDateDeadline.ToString("MMMM dd, yyyy")); } SelectedBorrower.BORROWERBOOKSBORROWED.Add(SelectedBook); if (SelectedBorrower.BORROWERBOOKSBORROWED.Count > 0) { SelectedBorrower.BorrowerCheckBorrowingBooks = CheckBorrowedBook.BORROWING.ToString(); } SelectedBook = null; } }
public void BorrowBook() { var borrowbookwindow = new BorrowBooksWindow(); borrowbookwindow.DataContext = this; var result = borrowbookwindow.ShowDialog(); if (result == true) { SelectedBorrower.BORROWERBOOKSBORROWED.Add(SelectedBook); con.Open(); SqlCommand command_borrower = new SqlCommand("UPDATE [BORROWER] SET BorrowStatus=@BorrowStatus WHERE BorrowerID=@BorrowerID", con); SqlCommand command_book = new SqlCommand("UPDATE [BOOK] SET Availability=@Availability WHERE BookID=@BookID", con); //SqlCommand command_process = new SqlCommand("INSERT INTO [PROCESS](LastName,FirstName) VALUES(@LastName,@FirstName)", con); for (int i = 0; i < dt_book.Rows.Count; i++) { if (SelectedBook.BookIDNumber == int.Parse(dt_book.Rows[i]["BookID"].ToString())) { command_book.Parameters.Add("@BookID", SelectedBook.BookIDNumber); command_book.Parameters.Add("@Availability", Availability.UNAVAILABLE.ToString()); break; } } for (int i = 0; i < dt_book.Rows.Count; i++) { if (SelectedBook.BookIDNumber == BOOKSLIST[i].BookIDNumber) { BOOKSLIST[i].BookAvailability = Availability.UNAVAILABLE.ToString(); break; } } for (int i = 0; i < dt_borrower.Rows.Count; i++) { if (SelectedBorrower.BorrowerIDNumber == int.Parse(dt_borrower.Rows[i]["BorrowerID"].ToString())) { command_borrower.Parameters.Add("@BorrowerID", SelectedBorrower.BorrowerIDNumber); command_borrower.Parameters.Add("@BorrowStatus", CheckBorrowedBook.BORROWING.ToString()); break; } } for (int i = 0; i < dt_borrower.Rows.Count; i++) { if (SelectedBorrower.BorrowerIDNumber == BORROWERSLIST[i].BorrowerIDNumber) { BORROWERSLIST[i].BorrowerCheckBorrowingBooks = CheckBorrowedBook.BORROWING.ToString(); break; } } command_book.ExecuteNonQuery(); command_borrower.ExecuteNonQuery(); con.Close(); MessageBox.Show("Successfully borrowed the book"); //SelectedBook.BookAvailability = Availability.UNAVAILABLE.ToString(); //SelectedBook.BookDateBorrowed = bookdateborrowed; //if(SelectedBorrower.BorrowerType == "Student") //{ // SelectedBook.BookDateDeadline = SelectedBook.BookDateBorrowed.AddDays(7); // MessageBox.Show("Date Borrowed: " + SelectedBook.BookDateBorrowed.ToString("MMMM dd, yyyy") + "\n" + "Date Deadline: " + SelectedBook.BookDateDeadline.ToString("MMMM dd, yyyy")); //} //else //{ // SelectedBook.BookDateDeadline = SelectedBook.BookDateBorrowed.AddDays(14); // MessageBox.Show("Date Borrowed: " + SelectedBook.BookDateBorrowed.ToString("MMMM dd, yyyy") + "\n" + "Date Deadline: " + SelectedBook.BookDateDeadline.ToString("MMMM dd, yyyy")); //} //SelectedBorrower.BORROWERBOOKSBORROWED.Add(SelectedBook); //if(SelectedBorrower.BORROWERBOOKSBORROWED.Count>0) //{ // SelectedBorrower.BorrowerCheckBorrowingBooks = CheckBorrowedBook.BORROWING.ToString(); //} //SelectedBook = null; } }