Example #1
0
        public void SetUp()
        {
            booksList = new BooksList();

            booksList.Add(new Book("Author3", "Title1", "Publisher2", 2001, 99.99, "byn", "978-3-16-148410-0"));
            booksList.Add(new Book("Author2", "Title2", "Publisher3", 2002, 199.99, "byn", "978-1-56619-909-4"));
            booksList.Add(new Book("Author1", "Title3", "Publisher1", 2000, 9.99, "byn", "978-1-4028-9462-6"));
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the MainViewModel class.
 /// </summary>
 public MainViewModel()
 {
     RingVisibility = Visibility.Visible;
     Task.Factory.StartNew(() =>
     {
         DatabaseHelper.Open();
         try
         {
             var reader = DatabaseHelper.Select <BookItem>("*", "ORDER BY Time DESC");
             while (reader.Read())
             {
                 if (reader.HasRows)
                 {
                     var item = new BookItem(reader);
                     Application.Current.Dispatcher.Invoke(() =>
                     {
                         BooksList.Add(item);
                     });
                 }
             }
             reader.Close();
         }
         catch (Exception)
         {
             DatabaseHelper.Init();
         }
         DatabaseHelper.Close();
         RingVisibility = Visibility.Collapsed;
     });
 }
Example #3
0
        private void AddABook()
        {
            Console.Clear();
            Console.WriteLine("Please, print the book's name.");
            var name = Console.ReadLine();

            Console.WriteLine("Please, print the book's author.");
            var author = Console.ReadLine();

            var isAnyAuthorBookWithTheName = BooksList.Any(book => book.Name == name && book.Author == author);

            if (isAnyAuthorBookWithTheName)
            {
                var bookIndex = BooksList.FindIndex(book => book.Name == name && book.Author == author);
                BooksList[bookIndex].Count++;
                Console.WriteLine("Thank you for adding one more exemplar.");
            }
            else
            {
                var generes = Enum.GetNames(typeof(Genere));
                Console.WriteLine("Please, choose the book's genere.");
                for (int i = 0; i < generes.Length; i++)
                {
                    Console.WriteLine("{0} : {1}", (i + 1), generes[i]);
                }

                var genere = Genere.Detective;

                switch (Console.ReadLine())
                {
                case "1":
                    genere = Genere.Fantasy;
                    break;

                case "2":
                    genere = Genere.Detective;
                    break;

                case "3":
                    genere = Genere.Romance;
                    break;
                }

                Console.WriteLine("Please, print the book's year of publication.");
                var yearOfPublication = int.Parse(Console.ReadLine());
                Console.WriteLine("Please, print the book's number of pages.");
                var numberOfPages = int.Parse(Console.ReadLine());

                var newBook = new Book(name, author, genere, yearOfPublication, numberOfPages, 1, 1);
                BooksList.Add(newBook);
            }

            Console.WriteLine("Thank you for adding the book!");
            Console.WriteLine("Please, press any key to continue...");
            Console.ReadLine();
        }
Example #4
0
 private void ExecuteAddCommand()
 {
     new AddBookView().Show();
     Messenger.Default.Send(new NotificationMessageAction <BookItem>(null, item =>
     {
         Application.Current.Dispatcher.Invoke(() =>
         {
             BooksList.Add(item);
         });
     }), "book");
 }
Example #5
0
 public void BookUpdated(Book book)
 {
     if (book.Id == -1)
     {
         book.Id = DatabaseManager.Instance.AddBook(book);
         BooksList.Add(book);
     }
     else
     {
         DatabaseManager.Instance.EditBook(book);
     }
 }
Example #6
0
        public Book TakeBook(string bookName)
        {
            Book currentBook = null;
            for (int i = 0; i < booksList.ElementsCount; i++)
            {
                if (booksList[i].BookName.Equals(bookName)) currentBook = booksList[i];
            }
            Book[] books = booksList.Remove(currentBook);

            booksList = new BooksList<Book>();
            for (int i = 0; i < books.Length; i++)
            {
                booksList.Add(books[i]);
            }

            Console.WriteLine(bookName + " is already taken!");

            if (evt != null)
                evt(currentBook, false);
            return currentBook;
        }
Example #7
0
        //Load the parameter and/or the whole list.
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var arg = e.Parameter as Book;

            //If we have to load a book
            if (arg != null)
            {
                LoadingRing.IsActive = true;
                showBookInfo(arg);
                LoadingRing.IsActive = false;
            }
            //After that, load the whole list if has not been loaded yet
            if (BooksList.Count() == 0)
            {
                Books_Searchbox.IsEnabled = false;
                var service = new GoTService();
                LoadingRing.IsActive = true;
                var books = await service.GetBooksAsync(1);

                int page = 2;
                while (books.Count() != 0)
                {
                    foreach (var item in books)
                    {
                        if (item.name != "")
                        {
                            BooksList.Add(item);
                        }
                    }
                    books = await service.GetBooksAsync(page);

                    page++;
                }
                LoadingRing.IsActive      = false;
                Books_Searchbox.IsEnabled = true;
            }
            BooksListBox.ItemsSource = BooksList;
        }
Example #8
0
        //methods

        /// <summary>
        /// Adding book to author's books' list
        /// </summary>
        /// <param name="book">book to add</param>
        public void AddBook(Book book)
        {
            BooksList.Add(book);
        }
        //'" + selectedTitleList + "'
        #endregion
        private void DataGrid_Loaded()
        {
            string typeTemp = "*";

            if (SelectedTypeBook != null)
            {
                typeTemp = typeBookDictionaryList[SelectedTypeBook];
            }


            DBClass.openConnection();
            if (SelectedAuthorList == null && SelectedTypeBook == null)
            {
                DBClass.sql = "select distinct bookId, titileBook, nameTypeBook, publisher, authors.firstName, authors.lastName, releaseDate " +
                              "from authors, typeBook, books " +
                              "where  " +
                              "(  authors.firstName in (select distinct  authors.firstName from authors where authorId = books.authorId) " +
                              "and authors.lastName in (select distinct  authors.lastName from authors where authorId = books.authorId) " +
                              "and typeBook.nameTypeBook in (select distinct  nameTypeBook from typeBook where typeBookId = books.typeBookId))";
            }
            else if (SelectedAuthorList == null && SelectedTypeBook != null)
            {
                DBClass.sql = "select distinct bookId, titileBook , nameTypeBook, publisher, authors.firstName, authors.lastName,  releaseDate " +
                              "FROM books " +
                              "inner join authors on authors.authorId = books.authorId " +
                              "inner join typeBook on typeBook.typeBookId = '" + typeTemp + "' " +
                              "where books.authorId = books.authorId " +
                              "and books.typeBookID = '" + typeTemp + "'";
            }
            else if (SelectedAuthorList != null && SelectedTypeBook == null)
            {
                DBClass.sql = "select distinct bookId, titileBook , nameTypeBook, publisher, authors.firstName, authors.lastName,  releaseDate " +
                              "from authors, typeBook, books " +
                              "where  " +
                              "(  authors.firstName in (select distinct  authors.firstName from authors where authorId = books.authorId) " +
                              "and authors.lastName in (select distinct  authors.lastName from authors where authors.lastName = '" + selectedAuthorList + "') " +
                              "and typeBook.nameTypeBook in (select distinct  nameTypeBook from typeBook where typeBookId = books.typeBookId))";
            }
            else
            {
                DBClass.sql = "SELECT DISTINCT bookId, titileBook , nameTypeBook, publisher, authors.firstName, authors.lastName,  releaseDate " +
                              "FROM books " +
                              "inner join authors on authors.lastName = '" + selectedAuthorList + "' " +
                              "inner join typeBook on typeBook.typeBookId = '" + typeTemp + "'  " +
                              "where books.authorId = (select distinct  authors.authorId from authors where authors.lastName = '" + selectedAuthorList + "') " +
                              "and books.typeBookID = '" + typeTemp + "' ";
            }

            DBClass.cmd.CommandType = CommandType.Text;
            DBClass.cmd.CommandText = DBClass.sql;

            DBClass.da = new SqlDataAdapter(DBClass.cmd);
            DBClass.dt = new DataTable();
            DBClass.da.Fill(DBClass.dt);

            // wyciągamy dane
            int i = 0;
            int j = 0;

            BooksList.Clear();
            using (SqlDataReader reader = DBClass.cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    for (j = 0; j <= reader.FieldCount - 1; j++) // Looping throw colums
                    {
                        data[j] = reader.GetValue(j).ToString();
                    }
                    BooksList.Add(new BookModel
                    {
                        Id              = Int32.Parse(data[0]),
                        titleBook       = data[1],
                        typeBook        = data[2],
                        publisher       = data[3],
                        firstNameAuthor = data[4],
                        lastNameAuthor  = data[5],
                        releaseDate     = data[6]
                    });
                }
            }
            DBClass.closeConnection();

            try
            {
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
            }
        }