private void buttonBonusAdd_Click(object sender, EventArgs e)
        {
            int      score = 0;
            DateTime start;
            DateTime end;

            try
            {
                score = Convert.ToInt32(textBoxBonusScore.Text);
                start = dateTimeBonusStart.Value;
                end   = dateTimeBonusEnd.Value;
            }
            catch (Exception)
            {
                MessageBox.Show("Incorrect data passed to the UI");
                return;
            }
            Bonus bonus = new Bonus();

            bonus.id        = 0;
            bonus.score     = score;
            bonus.startDate = start;
            bonus.endDate   = end;
            if (!bonus.correct())
            {
                MessageBox.Show("Incorrect data while creating bonus");
                return;
            }
            ContainerBonus container = new ContainerBonus(bonus);

            listBoxThisBookBonuses.Items.Add(container);
        }
Ejemplo n.º 2
0
 private void fillBonusesListBox(Book selectedBook)
 {
     listBoxBonuses.Items.Clear();
     foreach (Bonus b in selectedBook.bonuses)
     {
         ContainerBonus cb = new ContainerBonus(b);
         listBoxBonuses.Items.Add(cb);
     }
 }
        private void prepareCategoriesAuthorsAndBonuses(Book book)
        {
            //fill listboxes
            LinkedList <Author> otherAuthors = bookFunctions.getAllAuthorsMinuBookAuthors(book);

            listBoxThisBookAuthors.Items.Clear();
            foreach (Author authorThisBook in book.authors)
            {
                listBoxThisBookAuthors.Items.Add(authorThisBook);
            }
            listBoxOtherAuthors.Items.Clear();
            foreach (Author otherAuthor in otherAuthors)
            {
                listBoxOtherAuthors.Items.Add(otherAuthor);
            }


            LinkedList <Category> otherCategories = bookFunctions.getCategriesBookDoesntbelongTo(book);

            listBoxThisBookCategories.Items.Clear();
            foreach (Category category in book.categories)
            {
                listBoxThisBookCategories.Items.Add(category);
            }
            listBoxOtherCategories.Items.Clear();
            foreach (Category otherCategory in otherCategories)
            {
                listBoxOtherCategories.Items.Add(otherCategory);
            }

            listBoxThisBookBonuses.Items.Clear();
            foreach (Bonus thisBookBonus in book.bonuses)
            {
                ContainerBonus container = new ContainerBonus(thisBookBonus);
                listBoxThisBookBonuses.Items.Add(container);
            }

            //fill general data panel
            if (book.Id == Book.newBookId)
            {
                labelID.Text = "new book";
            }
            else
            {
                labelID.Text = book.Id.ToString();
            }
            textBoxTitle.Text          = book.Title;
            textBoxPrice.Text          = book.Price.ToString();
            textBoxDiscount.Text       = book.priceMinusDiscountInProcent.ToString();
            textBoxQuantity.Text       = book.quantity.ToString();
            dateTimeStartSelling.Value = book.startSellingDate;
            checkBoxDeleted.Checked    = book.deleted;
        }
        private bool fillBookWithUIData()
        {
            try
            {
                string              title    = textBoxTitle.Text;
                decimal             price    = Convert.ToDecimal(textBoxPrice.Text);
                int                 discount = Convert.ToInt32(textBoxDiscount.Text);
                int                 quantity = Convert.ToInt32(textBoxQuantity.Text);
                DateTime            date     = dateTimeStartSelling.Value;
                bool                deleted  = checkBoxDeleted.Checked;
                LinkedList <Author> authors  = new LinkedList <Author>();
                foreach (Object objAuthor in listBoxThisBookAuthors.Items)
                {
                    Author a = ((Author)objAuthor).clone();
                    authors.AddLast(a);
                }
                LinkedList <Category> categories = new LinkedList <Category>();
                foreach (Object objCateg in listBoxThisBookCategories.Items)
                {
                    Category c = ((Category)objCateg).clone();
                    categories.AddLast(c);
                }
                LinkedList <Bonus> bonuses = new LinkedList <Bonus>();
                foreach (Object objBon in listBoxThisBookBonuses.Items)
                {
                    ContainerBonus contBonus = ((ContainerBonus)objBon);
                    Bonus          bonus     = contBonus.StoredBonus;
                    bonuses.AddLast(bonus.clone());
                }

                editAddBook.Title = title;
                editAddBook.Price = price;
                editAddBook.priceMinusDiscountInProcent = discount;
                editAddBook.quantity         = quantity;
                editAddBook.startSellingDate = date;
                editAddBook.deleted          = deleted;
                editAddBook.authors          = authors;
                editAddBook.categories       = categories;
                editAddBook.bonuses          = bonuses;
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }