示例#1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (EmptyChecker.TryTextFieldsEmpty(Controls))
     {
         MessageBox.Show("Please make sure you enter a value for all text fields", "Value empty error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     TextBoxParser.TextBoxChecker(Controls);
     if (genreCombo.Text == "" || authorCombo.Text == "" || publisherCombo.Text == "")
     {
         MessageBox.Show("Please choose an value for all drop down menus before clicking save",
                         "Combobox empty error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (!_typeBookRepo.AddBooks(titleTextBox.Text, numberTextBox.Text,
                                 _genreRepo.GetGenreByText(genreCombo.Text),
                                 _authorRepo.GetAuthorByName(authorCombo.Text),
                                 _publisherRepo.GetPublisherByName(publisherCombo.Text), int.Parse(copiesTextBox.Text)))
     {
         MessageBox.Show("There is already an book with this title from this publisher.", "Type of book exists error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
         return;
     }
     StartingPoint();
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (EmptyChecker.TryTextFieldsEmpty(Controls))
            {
                MessageBox.Show("Please make sure you enter a value for all text fields", "Value empty error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            TextBoxParser.TextBoxChecker(Controls);
            var returnValue = _typeBook.EditBook(_typeBook.GetAllBookTypes()[_index].TypeBookId, titleTextBox.Text,
                                                 numberTextBox.Text,
                                                 _genreRepo.GetGenreByText(genreCombo.Text),
                                                 _authorRepo.GetAuthorByName(authorCombo.Text), _publisherRepo.GetPublisherByName(publisherCombo.Text),
                                                 int.Parse(copiesTextBox.Text));

            switch (returnValue)
            {
            case -1:
                MessageBox.Show("Book with same title and publisher already exists", "Book exists error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            case -2:
                MessageBox.Show("Number of copies cannot be negative", "Book copies negative error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            case -4:
                MessageBox.Show("There's no available copies to remove they're rented or in an different state.",
                                "Book unavailable to remove error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                copiesTextBox.Text = _typeBook.GetAllBookTypes()[_index].PhysicalBooks
                                     .Count(bk => bk.BookInfo.TypeBookId == _typeBook.GetAllBookTypes()[_index].TypeBookId).ToString();
                return;

            default:
                SetData();
                return;
            }
        }