Beispiel #1
0
        private void AddBookButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(BookTitleBox.Text) || string.IsNullOrWhiteSpace(BookTitleBox.Text) || string.IsNullOrEmpty(BookGenreBox.Text) ||
                string.IsNullOrWhiteSpace(BookGenreBox.Text) || string.IsNullOrEmpty(AuthorNameBox.Text) || string.IsNullOrWhiteSpace(AuthorNameBox.Text))
            {
                MessageBox.Show("Puste pola!", "Błąd przy dodawaniu do bazy danych", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                var title = BookTitleBox.Text;
                //imię + nazwisko
                var authorName = AuthorNameBox.Text;
                var genreName  = BookGenreBox.Text;

                var author = Autorzy.First(x => x.Nazwa == authorName);

                var książka = new BookModel()
                {
                    Tytuł      = title,
                    Autor      = author,
                    Gatunek    = GenresDatabaseConnectionController.GetGenreByName(genreName),
                    IsBorrowed = false,
                };
                DataInsertionController.InsertBookIntoDatabase(książka);
                UpdateDataGrid();

                AuthorNameBox.Text = "";
                BookTitleBox.Text  = "";
                BookGenreBox.Text  = "";
            }
        }
Beispiel #2
0
        private void UpdateDataGrid()
        {
            var authorNamesAndIds = new Dictionary <int, string>();
            var genreNamesAndIds  = new Dictionary <int, string>();

            Autorzy = AuthorsDatabaseConnectionController.GetAllAuthors();
            var autorzyString = new List <string>();

            foreach (var autor in Autorzy)
            {
                autorzyString.Add(autor.Imię + " " + autor.Nazwisko);
            }
            AuthorNameBox.ItemsSource = autorzyString;

            Gatunki = GenresDatabaseConnectionController.GetAllGenres();
            var gatunkiString = new List <string>();

            foreach (var gatunek in Gatunki)
            {
                gatunkiString.Add(gatunek.Nazwa);
            }
            BookGenreBox.ItemsSource = gatunkiString;

            foreach (var autor in Autorzy)
            {
                authorNamesAndIds.Add(autor.Id, autor.Imię + " " + autor.Nazwisko);
            }

            foreach (var gatunek in Gatunki)
            {
                genreNamesAndIds.Add(gatunek.Id, gatunek.Nazwa);
            }

            Książki = BookDatabaseConnectionController.GetAllBooks();

            WszystkieKsiążkiDataGrid.ItemsSource = Książki;
            WszystkieKsiążkiDataGrid.UpdateLayout();
        }
 private void UpdateDataGrid()
 {
     Gatunki = GenresDatabaseConnectionController.GetAllGenres();
     WszystkieGatunkiDataGrid.ItemsSource = Gatunki;
     WszystkieGatunkiDataGrid.UpdateLayout();
 }