public HistoryPage() { InitializeComponent(); var entities = new LibraryEntities(); var query = from lend in entities.LendHistories select new { DataWypozyczenia = lend.LendingDate, DataZwrotu = lend.ReturnDate, Nazwisko = lend.Reader.LastName, Imie = lend.Reader.FirstName, Autor = lend.Book.Author.LastName, Tytul = lend.Book.Title }; historyDataGrid.ItemsSource = query.ToList(); }
private void returnBookBtn_Click(object sender, RoutedEventArgs e) { LibraryEntities entities = new LibraryEntities(); ReturnGridRow selectedItem = returnDataGrid.SelectedItem as ReturnGridRow; var lendHistory = entities.LendHistories.Find(selectedItem.LendId); lendHistory.ReturnDate = DateTime.Now; entities.SaveChanges(); showLends(); }
private void lendButton_Click(object sender, RoutedEventArgs e) { wrongDataText.Text = ""; var db = new LibraryEntities(); if (peselInput.Text.Length < 11 || !(peselInput.Text.All(char.IsDigit))) { wrongDataText.Text = "Niepoprawny pesel. Wpisz ponownie."; } var queryInputReader = from reader in db.Readers where reader.Pesel == peselInput.Text & reader.Active == true select reader; var readers = queryInputReader.ToList <Reader>(); foreach (Reader reader in readers) { LendHistory lendHistory = new LendHistory(); LendGridRow selectedItem = lendDataGrid.SelectedItem as LendGridRow; if (selectedItem != null) { if (!selectedItem.Wypozyczono) { lendHistory.ReaderID = reader.ID; lendHistory.BookID = selectedItem.ISBN; lendHistory.LendingDate = DateTime.Now; db.LendHistories.Add(lendHistory); db.SaveChanges(); wrongDataText.Text = ""; correctDataText.Text = "Wypożyczono."; } else { wrongDataText.Text = "Książka jest już wypożyczona."; } } else { wrongDataText.Text = "Wybierz książkę."; } } showBooks(); }
private void showBooks() { var db = new LibraryEntities(); var query = from book in db.Books where book.InStock join lend in db.LendHistories on book.ISBN equals lend.BookID into j from lend in j.DefaultIfEmpty() where lend == null | lend.ReturnDate == null select new LendGridRow { ISBN = book.ISBN, Imie_Autora = book.Author.FirstName, Nazwisko_Autora = book.Author.LastName, Tytul = book.Title, Wypozyczono = lend != null && lend.ReturnDate == null }; lendDataGrid.ItemsSource = query.ToList(); lendDataGrid.Items.Refresh(); }
private void showLends() { LibraryEntities entities = new LibraryEntities(); var pesel = peselBox.Text; var query = from lend in entities.LendHistories where (lend.Reader.Pesel == pesel) && lend.ReturnDate == null && lend.Book.InStock == true select new ReturnGridRow { LendId = lend.ID, Imie = lend.Reader.FirstName, Nazwisko = lend.Reader.LastName, Tytul = lend.Book.Title, DataWypozyczenia = lend.LendingDate, DataZwrotu = lend.ReturnDate, ISBN = lend.BookID }; returnDataGrid.ItemsSource = query.ToList(); returnDataGrid.Columns[0].Visibility = Visibility.Collapsed; returnDataGrid.Items.Refresh(); }