Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Book book = new Book();

            book.Title    = textBox1Title.Text;
            book.Author   = (Author)comboBox1Author.SelectedItem;
            book.Genre    = comboBox2Genre.SelectedItem.ToString();
            book.Type     = comboBox1Type.SelectedItem.ToString();
            book.Year     = int.Parse(textBox4Year.Text);
            book.Isbn     = textBox5ISBN.Text;
            book.Reserved = false;
            //user = new User();
            //user.UserName = username;
            //book.User = user;
            //978-3-16-148410-0
            ISBNService.ISBNService oService = new ISBNService.ISBNService();
            bool res = oService.IsValidISBN13(textBox5ISBN.Text);

            if (!res)
            {
                MessageBox.Show("Invalid format of the 13 digit ISBN. Example: 978-3-16-148410-0, try again!!");
            }
            else
            {
                //MessageBox.Show("Result:  ISBN");
                bookmanage.AddBook(book);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            book.Book.Title  = txtTitle.Text;
            book.Book.Author = (Author)cmbAuthor.SelectedItem;
            book.Book.Genre  = cmbGenre.SelectedItem.ToString();
            book.Book.Type   = cmbType.SelectedItem.ToString();
            int year;

            if (!String.IsNullOrEmpty(txtYearPublished.Text) && int.TryParse(txtYearPublished.Text, out year))
            {
                book.Book.Year          = year;
                book.Book.YearSpecified = true;
            }
            book.Book.Isbn     = txtIsbn.Text;
            book.Book.Reserved = rbtnReservedYes.Checked ? true : false;
            //978-1-4028-9462-6
            bool res = false;

            try
            {
                ISBNService.ISBNService oService = new ISBNService.ISBNService();
                res = oService.IsValidISBN13(txtIsbn.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some internal error occured during validating book isbn.");
            }
            if (!res)
            {
                MessageBox.Show("Invalid format of the 13 digit ISBN. Example: 978-1-4028-9462-6, try again!!");
            }
            else
            {
                try
                {
                    OperationResult or = mainForm.WebServiceProxy.EditBook(book.Book, mainForm.UserName, mainForm.Guid);
                    if (or.Error.Equals(OperationResultErrorEnum.None))
                    {
                        MessageBox.Show("Book successfully edited!");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(or.ErrorString);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Some internal error occured during saving the edited book.");
                }
            }
        }
Exemple #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!ValidateAdd())
            {
                return;
            }
            Book book = new Book();

            book.Title  = txtTitle.Text;
            book.Author = (Author)cmbAuthor.SelectedItem;
            book.Genre  = (string)cmbGenre.SelectedItem;
            book.Type   = (string)cmbType.SelectedItem;
            int year;

            if (!String.IsNullOrEmpty(txtYearPublished.Text) && int.TryParse(txtYearPublished.Text, out year))
            {
                book.Year          = year;
                book.YearSpecified = true;
            }
            book.Isbn     = txtIsbn.Text;
            book.Reserved = false;
            User user = new User();

            user.UserName = mainForm.UserName;
            book.User     = user;
            //978-1-4028-9462-6
            ISBNService.ISBNService oService = new ISBNService.ISBNService();
            bool res = false;

            try
            {
                res = oService.IsValidISBN13(txtIsbn.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Some error occured while validating book ISBN");
            }
            if (!res)
            {
                MessageBox.Show("Invalid format of the 13 digit ISBN. Example: 978-1-4028-9462-6, try again!!");
            }
            else
            {
                try
                {
                    OperationResult or = mainForm.WebServiceProxy.AddBook(book, mainForm.UserName, mainForm.Guid);
                    if (or.Error.Equals(OperationResultErrorEnum.None))
                    {
                        MessageBox.Show("Book successfully added!");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(or.ErrorString);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Some error occured during adding a book.");
                }
            }
        }