예제 #1
0
        private List <string> getAuthors(int bookID)
        {
            List <string> list = new List <string>();

            try
            {
                foreach (Writing writing in dbDataContext.Writings.Where(x => x.BookID == bookID))
                {
                    Authors author = dbDataContext.Authors.Where(x => x.ID == writing.AuthorID).First();
                    list.Add(author.Name + " " + author.Surname);
                }
            }
            catch (Exception exc)
            {
                //MessageBox.Show(exc.Message);
            }
            return(list);
        }
예제 #2
0
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            List <string> errList = new List <string>();

            if (!Validation.validTitle(this.tbTitle.Text.ToString()))
            {
                errList.Add("Nieprawidłowy tytuł. Można używać tylko liter.");
            }

            /*else if (!Validation.validName(this.tbAuthorName.Text.ToString()))
             *  errList.Add("Nieprawidłowe imię");
             * else if (!Validation.validName(this.tbAuthorSurname.Text.ToString()))
             *  errList.Add("Nieprawidłowe nazwisko"); */
            else if (!Validation.validYear(this.comboBoxYears.Text.ToString()))
            {
                errList.Add("Nieprawidłowy rok. Należy wpisać rok od 1 do 2019. Należy używać tylko cyfr.");
            }
            else if (comboBoxYears.Text != "")
            {
                int yr = int.Parse(this.comboBoxYears.Text);
                if (yr > 2019)
                {
                    errList.Add("Rok nie może być większy niż 2019");
                }
                else if (yr < 1)
                {
                    errList.Add("Rok nie może być mniejszy niż 1");
                }
            }
            else if (!Validation.validName(this.comboBoxPublishers.Text.ToString()))
            {
                errList.Add("Nieprawidłowa nazwa wydawcy");
            }
            else if (!Validation.validCount(this.bcCount.Text.ToString()))
            {
                errList.Add("Nieprawidłowa ilość egzemplarzy");
            }

            if (errList.Count == 0)
            {
                Books   book   = new Books();
                Authors author = new Authors();

                book.Title = this.tbTitle.Text.ToString();

                /*author.Name = this.tbAuthorName.Text.ToString();
                 * author.Surname = this.tbAuthorSurname.Text.ToString(); */
                book.Year = int.Parse(this.comboBoxYears.Text.ToString());

                book.Description = this.tbDescription.Text.ToString();
                if (this.img != null)
                {
                    book.ImageLocation = "covers/" + img;
                }

                if (comboBoxPublishers.SelectedItem == null)
                {
                    book.Publishers      = new Publishers();
                    book.Publishers.Name = comboBoxPublishers.Text;
                }
                else
                {
                    book.Publishers = (Publishers)comboBoxPublishers.SelectedItem;
                }

                foreach (Types t in listBoxTypes.SelectedItems)
                {
                    BookTypes bt = new BookTypes();
                    bt.Books = book;
                    bt.Types = t;
                }

                foreach (Authors a in lbAuthors.SelectedItems)
                {
                    Writing writing = new Writing();
                    writing.Books   = book;
                    writing.Authors = a;
                }

                dbDataContext.Books.InsertOnSubmit(book);
                dbDataContext.SubmitChanges();
                addBookCopies(Convert.ToInt32(bcCount.Value), book.ID);
                //this.listBox1.Items.Add(book.Title.ToString());
                MessageBox.Show("Dodawanie książki zakończone sukcesem !");
                Close();
            }
            else
            {
                string errOutput = "";
                foreach (var errMsg in errList)
                {
                    errOutput += (errMsg.ToString() + "\n");
                }
                MessageBox.Show(errOutput);
            }
        }