Пример #1
0
 public Book GetBookById(int id)
 {
     foreach (Book book in books.Value)
     {
         bookCollection.Add(book);
     }
     return(bookCollection[id]);
 }
Пример #2
0
        public void MakeClone()
        {
            books.Clear();
            editions.Clear();
            genres.Clear();
            companies.Clear();

            foreach (Book b in database.bookManager.books)
            {
                books.Add(new Book(b.Title, b.Author, b.edition, b.genre, b.PublishYear, b.PublishLocation, b.Publisher, b.Isbn, b.PagesNumber, b.Note));
            }
            foreach (EGC e in database.egcManager.editions)
            {
                editions.Add(new EGC(e.Name));
            }
            foreach (EGC g in database.egcManager.genres)
            {
                genres.Add(new EGC(g.Name));
            }

            settings.SortBy = database.settings.SortBy;
            settings.SortUp = database.settings.SortUp;

            settings.SortUpEditions = database.settings.SortUpEditions;
            settings.SortUpGenres   = database.settings.SortUpGenres;

            settings.SortBooks    = database.settings.SortBooks;
            settings.SortEditions = database.settings.SortEditions;
            settings.SortGenres   = database.settings.SortGenres;
        }
Пример #3
0
 public void AddBook(Book Book, int Copies)
 {
     if (BookCollection.ContainsKey(Book))
     {
         Console.WriteLine($"Book {Book} is allready in the collection of {Name}.");
         return;
     }
     BookCollection.Add(Book, new BookStock(Copies));
 }
Пример #4
0
        /*
         * Method for synchronization if the collection of the ViewModels changed with the
         * cases add, remove and reset.
         */
        private void ViewModelCollectionChanged(object bookCollectionVM, NotifyCollectionChangedEventArgs e)
        {
            if (synchDisabled)
            {
                return;
            }

            // Disable synchronization
            synchDisabled = true;

            switch (e.Action)
            {
            //add a new book to the model collection
            case NotifyCollectionChangedAction.Add:
                foreach (var newBook in e.NewItems.OfType <BookViewModel>().Select(v => v.wrappedBook).OfType <Book>())
                {
                    bookCollection.Add(newBook);
                }
                break;

            //remove a book from the model collection
            case NotifyCollectionChangedAction.Remove:
                foreach (var oldBook in e.OldItems.OfType <BookViewModel>().Select(v => v.wrappedBook).OfType <Book>())
                {
                    bookCollection.Remove(oldBook);
                }
                break;

            /*
             * reset the model collection by clearing the collection and adding the models of the
             * saved viewmodels.
             */
            case NotifyCollectionChangedAction.Reset:
                bookCollection.Clear();
                foreach (var book in e.NewItems.OfType <BookViewModel>().Select(v => v.wrappedBook).OfType <Book>())
                {
                    bookCollection.Add(book);
                }
                break;
            }

            //Enable synchronization
            synchDisabled = false;
        }
        private async void GetBooks()
        {
            Task <List <BookModel> > task = Task.Run <List <BookModel> >(() => {
                var t = _bookDataAccess.GetAllData(Properties.Resources.GetAllBooks);
                return(t);
            });

            BookCollection.Clear();
            _log.Message("Getting All books from the database");
            var booksCollection = await task;

            booksCollection.ForEach(t => BookCollection.Add(t));
        }
Пример #6
0
        public MainWindowViewModel()
        {
            /*
             * create book collection and add three example books
             */
            BookCollection MyBookCollection = new BookCollection();

            MyBookCollection.Add(new Book());
            MyBookCollection.ElementAt <Book>(0).Author    = "Lars Raschke";
            MyBookCollection.ElementAt <Book>(0).Title     = "How to program last minute";
            MyBookCollection.ElementAt <Book>(0).Edition   = 1;
            MyBookCollection.ElementAt <Book>(0).PubYear   = 2018;
            MyBookCollection.ElementAt <Book>(0).Available = true;

            MyBookCollection.Add(new Book());
            MyBookCollection.ElementAt <Book>(1).Author    = "Dieter Bohlen";
            MyBookCollection.ElementAt <Book>(1).Title     = "Weg zum Erfolg";
            MyBookCollection.ElementAt <Book>(1).Edition   = 3;
            MyBookCollection.ElementAt <Book>(1).PubYear   = 1995;
            MyBookCollection.ElementAt <Book>(1).Available = false;

            MyBookCollection.Add(new Book());
            MyBookCollection.ElementAt <Book>(2).Author    = "Beate Uhse";
            MyBookCollection.ElementAt <Book>(2).Title     = "Gummibaum statt Gummifrauen";
            MyBookCollection.ElementAt <Book>(2).Edition   = 2;
            MyBookCollection.ElementAt <Book>(2).PubYear   = 2010;
            MyBookCollection.ElementAt <Book>(2).Available = true;

            // create a wrapped book collection of the book collection
            MyWrappedBookCollection = new BookCollectionViewModel(MyBookCollection);

            // creating RelayCommands with the given methods
            openFileDialogCommand  = new RelayCommand(OpenNewFileDialog);
            exitApplicationCommand = new RelayCommand(ExitCurrentApplication);

            addNewBookCommand = new RelayCommand(() =>
                                                 Messenger.Instance.Send <OpenNewBookWindowMessage>(new OpenNewBookWindowMessage()));
        }
Пример #7
0
        private async void GetBooks()
        {
            ErrorMsgVisibility = Visibility.Collapsed;
            BookCollection.Clear();

            Task <List <BookModel> > task = Task.Run <List <BookModel> >(() => {
                var t = _dataAccess.GetAllData(Properties.Resources.GetAllBooks);
                return(t);
            });

            _log.Message("Getting All the bok from Database");
            var booksCollection = await task;

            booksCollection.ForEach(t => BookCollection.Add(t));
        }
Пример #8
0
    public BookCollection GetBookCollection(string query, int page)
    {
        BookCollection returnCollection = new BookCollection();

        for(int i = 0; i < 25; i++)
        {
            Book newBook = new Book();
            newBook.Title = "Buch " + i.ToString();
            newBook.Description = "Beschreibung" + i.ToString();
            newBook.PicUrl = "PicUrl " + i.ToString();

            returnCollection.Add(newBook);
        }

        return returnCollection;
    }
    public BookCollection GetBookCollection(string query, int page)
    {
        BookCollection returnCollection = new BookCollection();

        for (int i = 0; i < 25; i++)
        {
            Book newBook = new Book();
            newBook.Title       = "Buch " + i.ToString();
            newBook.Description = "Beschreibung" + i.ToString();
            newBook.PicUrl      = "PicUrl " + i.ToString();

            returnCollection.Add(newBook);
        }

        return(returnCollection);
    }
Пример #10
0
    protected void HandlerUpdateBook(object sender, EventArgs e)
    {
        var bookCollection = new BookCollection();
        var book           = bookCollection.Book;

        book.Isbn      = txtIsbn.Text;
        book.Title     = txtTitle.Text;
        book.Author    = txtAuthor.Text;
        book.Publisher = txtPublisher.Text;
        book.PubYear   = txtPubYear.Text;
        book.ShelfNo   = txtShelfNo.Text;
        book.Edition   = Convert.ToInt32(txtEdition.Text);
        book.GenreCode = ddlGenre.SelectedValue;

        bool isThere = book.Find(book.Isbn);

        if (_isNew && !isThere)
        {
            bookCollection.Add();
        }
        else if (isThere && _isNew)
        {
            //Display Error
            ScriptManager.RegisterStartupScript(
                this,
                typeof(Page),
                "Alert",
                "<script>alert('Isbn already exists.');</script>",
                false);
        }
        else
        {
            bookCollection.Update();
            Response.Redirect("BookManagement.aspx");
        }
    }
Пример #11
0
        void ParseResponse(string responseXml, ref BookCollection books)
        {
            // get rid of namespaces
            responseXml = responseXml.Replace(" xmlns=\"", " whocares=\"");

            var xml = new XmlDocument();

            xml.LoadXml(responseXml);

            // trap API error
            var errors = GetErrors(xml, "errorMessage/error/message");

            if (errors.Count > 0)
            {
                _errorMessages = errors;
                _status        = SearchStatus.Failed;
                return;
            }

            // trap API method call failure error
            var isComplete = xml.SelectSingleNode("findItemsAdvancedResponse/ack").InnerText.Equals("Success");

            if (!isComplete)
            {
                _errorMessages = GetErrors(xml, "findItemsAdvancedResponse/errorMessage/error/message");
                _status        = SearchStatus.Failed;
                return;
            }

            foreach (XmlNode itemNode in xml.SelectNodes("findItemsAdvancedResponse/searchResult/item"))
            {
                var book = new BookModel();
                book.Status = _status;

                try
                {
                    book.Code     = itemNode.SelectSingleNode("itemId").InnerText;
                    book.Title    = itemNode.SelectSingleNode("title").InnerText;
                    book.Url      = new Uri(itemNode.SelectSingleNode("viewItemURL").InnerText);
                    book.Isbn     = _isbn;
                    book.Location = itemNode.SelectSingleNode("location").InnerText;
                    book.Country  = itemNode.SelectSingleNode("country").InnerText;
                    book.Seller   = new SellerModel
                    {
                        Name            = itemNode.SelectSingleNode("sellerInfo/sellerUserName").InnerText,
                        FeedbackScore   = long.Parse(itemNode.SelectSingleNode("sellerInfo/feedbackScore").InnerText),
                        FeedbackPercent = decimal.Parse(itemNode.SelectSingleNode("sellerInfo/positiveFeedbackPercent").InnerText)
                    };
                    book.Price = decimal.Parse(itemNode.SelectSingleNode("sellingStatus/convertedCurrentPrice").InnerText);

                    var condition = itemNode.SelectSingleNode("condition/conditionId");
                    if (condition == null)
                    {
                        book.Condition = BookCondition.Unknown;
                    }
                    else
                    {
                        // exceptional conditions
                        var conditionNumber = int.Parse(condition.InnerText);
                        if (conditionNumber == 2750)
                        {
                            conditionNumber = (int)BookCondition.LikeNew;
                        }

                        book.Condition = (BookCondition)conditionNumber;
                    }

                    book.Status = SearchStatus.Complete;
                }
                catch (XmlException ex)
                {
                    book.Status = SearchStatus.Failed;
                }

                if (book.Status == SearchStatus.Complete && IncludeBook(book, _filter))
                {
                    books.Add(book);
                }
            }

            _status = SearchStatus.Complete;
        }
        protected void btnReadXML_Click(object sender, EventArgs e)
        {
            string    path     = Server.MapPath("App_Data/books.xml");
            XDocument booksXml = XDocument.Load(path);

            #region Fetching first book

            var     firstBook       = booksXml.Descendants("book").First();
            string  firstBookId     = firstBook.Attribute("id").Value;
            string  firstBookAuthor = firstBook.Element("author").Value;
            string  firstBookTitle  = firstBook.Element("title").Value;
            string  firstBookGenre  = firstBook.Element("genre").Value;
            decimal firstBookPrice  = firstBook.Element("price").Value.ParseToDecimal();

            DateTime firstBookPublishDate =
                DateTime.Parse(firstBook.Element("publish_date").Value);

            string firstBookDescription = firstBook.Element("description").Value;

            string str      = "myBOOK";
            bool   contains = str.ContainsIgnoreCase("book");

            #endregion

            #region foreach version

            List <string> names = new List <string>();
            foreach (XElement node in booksXml.Descendants("book"))
            {
                if (node.Element("price").Value.ParseToDecimal() > 30)
                {
                    names.Add(node.Element("title").Value);
                }
            }

            #endregion

            #region Linq To XML version

            var booksMoreThan30 = from b in booksXml.Descendants("book").AsParallel()
                                  where b.Element("price").Value.ParseToDecimal() > 30
                                  select new Book(b.Element("title").Value);

            decimal mostExpensivePrice = booksXml
                                         .Descendants("book")
                                         .Max(book => book.Element("price").Value.ParseToDecimal());

            Decimal cheapestPrice = booksXml
                                    .Descendants("book")
                                    .Min(book => book.Element("price").Value.ParseToDecimal());

            #endregion

            #region Indexers Sample

            //List<string> d = null;
            //d[78] = "oi"; //set
            //string v = d[5]; //get
            BookCollection myBookCollection = new BookCollection();
            myBookCollection.Add(new Book("Game of Thrones"));
            string name = myBookCollection[0].Name;

            Book hp = myBookCollection["Game of Thrones"];

            #endregion
        }