public void CheckBookYear_isEngLetters_FalseReturned()
        {
            //Arrange
            string stringBookYear = "dfgdfgdfg";
            //Act
            StringCheck isBookYear  = new StringCheck();
            bool        correctYear = isBookYear.CheckBookYear(stringBookYear);

            //Assert
            Assert.IsFalse(correctYear);
        }
        public void CheckBookYear_isTooMuchNumbers_FalseReturned()
        {
            //Arrange
            string stringBookYear = "222222222";
            //Act
            StringCheck isBookYear  = new StringCheck();
            bool        correctYear = isBookYear.CheckBookYear(stringBookYear);

            //Assert
            Assert.IsFalse(correctYear);
        }
        public void CheckBookYear_isCorrect_TrueReturned()
        {
            //Arrange
            string stringBookYear = "1994";
            //Act
            StringCheck isBookYear  = new StringCheck();
            bool        correctYear = isBookYear.CheckBookYear(stringBookYear);

            //Assert
            Assert.IsTrue(correctYear);
        }
Beispiel #4
0
        /// <summary>
        /// Событие при вводе текста в поле "YearInput"
        /// </summary>
        private void YearInput_TextChanged(object sender, TextChangedEventArgs e)
        {
            StringCheck check = new StringCheck();

            bool trigger = check.CheckBookYear(YearInput.Text);

            if (!trigger || Convert.ToInt32(YearInput.Text) < 1500 || Convert.ToInt32(YearInput.Text) > DateTime.Now.Year)
            {
                YearWarningBtn.Visibility = Visibility.Visible;
            }
            else
            {
                YearWarningBtn.Visibility = Visibility.Collapsed;
            }
        }
        /// <summary>
        /// Событие при вводе текста в поле "NewYearInput"
        /// </summary>
        private void NewYearInput_TextChanged(object sender, TextChangedEventArgs e)
        {
            StringCheck check = new StringCheck();

            bool   trigger = check.CheckBookYear(NewYearInput.Text);
            string word    = NewYearInput.Text;

            foreach (var item in booksController.GetBookWithId(Settings.Default.selectBook))
            {
                if (word != Convert.ToString(item.year) && word != "" && trigger)
                {
                    SaveBtn.IsEnabled = true;
                }
                else
                {
                    SaveBtn.IsEnabled = false;
                }
            }

            if (NewAuthorInput.Text == "" || NewNameInput.Text == "" || NewBBkInputComboBox.Text == "" || NewIsbnInput.Text == "" || NewYearInput.Text == "" || NewInterpreterComboBox.Text == "" || NewChamberComboBox.Text == "")
            {
                SaveBtn.IsEnabled = false;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Добавление новой книги
        /// </summary>
        /// <param name="bookAuthor" - имя автора></param>
        /// <param name="bookKnowledgeField" - идентификатор ббк></param>
        /// <param name="bookName" - название книги></param>
        /// <param name="bookISBN" - шифр isbn></param>
        /// <param name="bookPlace" - место издания книги></param>
        /// <param name="bookYear" - год издания книги></param>
        /// <param name="bookInterpreter" - идентификатор издательства></param>
        /// <param name="bookChamber" - идентификатор отсека></param>
        /// <returns>
        /// true - в случае выполнения метода
        /// false - в случае не выполения метода
        /// </returns>
        public bool AddNewBook(string bookAuthor, int bookKnowledgeField, string bookName, string bookISBN, string bookPlace, int bookYear, int bookInterpreter, int bookChamber)
        {
            try
            {
                StringCheck check = new StringCheck();

                if ((!check.CheckName(bookAuthor) || bookAuthor == "") || (!check.CheckBookName(bookName) || bookName == "") || (!check.CheckBookIsbn(bookISBN) || bookISBN == "") || (!check.CheckBookYear(Convert.ToString(bookYear)) || bookYear > DateTime.Now.Year || bookYear < 1500) ||
                    (bookInterpreter == 0))
                {
                    return(false);
                }
                else
                {
                    dbHelper.context.books.Add(new books
                    {
                        author             = bookAuthor,
                        field_knowledge_id = bookKnowledgeField,
                        name           = bookName,
                        isbn           = bookISBN,
                        place          = bookPlace,
                        year           = bookYear,
                        quantity_id    = null,
                        interpreter_id = bookInterpreter,
                        chamber_id     = bookChamber,
                        trading_id     = null
                    });

                    dbHelper.context.SaveChanges();
                    Settings.Default.bookId = dbHelper.context.books.OrderByDescending(t => t.book_id).FirstOrDefault().book_id;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Обновление данных выбранной книги
        /// </summary>
        /// <param name="newAuthor" - новое имя автора></param>
        /// <param name="newfFieldKnowledgeId" - новый идентификатор ббк></param>
        /// <param name="newName" - новое имя></param>
        /// <param name="newIsbn" - новый шифр isbn></param>
        /// <param name="newPlace" - новое место издания></param>
        /// <param name="newYear" - новый год издания></param>
        /// <param name="newInterpretorId" - новый идентификатор издательства></param>
        /// <param name="newChamberId" - новый иднетификатор отсека></param>
        /// <param name="oldBook" - лист со старыми данными книги></param>
        /// <returns>
        /// true - в случае выполнения метода
        /// false - в случае не выполения метода
        /// </returns>
        public bool UpdateBookInfo(string newAuthor, int newfFieldKnowledgeId, string newName, string newIsbn, string newPlace, int newYear, int newInterpretorId, int newChamberId, List <books> oldBook)
        {
            try
            {
                StringCheck check = new StringCheck();

                if (!check.CheckName(newAuthor) || !check.CheckBookName(newName) || !check.CheckBookIsbn(newIsbn) || !check.CheckBookYear(Convert.ToString(newYear)) ||
                    newInterpretorId == 0)
                {
                    return(false);
                }
                else
                {
                    foreach (var item in oldBook)
                    {
                        item.author             = newAuthor;
                        item.field_knowledge_id = newfFieldKnowledgeId;
                        item.name           = newName;
                        item.isbn           = newIsbn;
                        item.place          = newPlace;
                        item.year           = newYear;
                        item.interpreter_id = newInterpretorId;
                        item.chamber_id     = newChamberId;
                        item.trading_id     = null;
                        item.quantity_id    = null;
                    }

                    dbHelper.context.SaveChanges();
                    if (dbHelper.context.SaveChanges() == 0)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Событие при клике на кнопку "Продолжить"
        /// </summary>
        private void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            StringCheck check        = new StringCheck();
            string      resultString = "";

            bool resultAuthor = check.CheckName(AuthorInput.Text);

            if (!resultAuthor || AuthorInput.Text == "")
            {
                resultString += "Неправильно введено имя Автора\n";
            }

            bool resultName = check.CheckBookName(NameInput.Text);

            if (!resultName || NameInput.Text == "")
            {
                resultString += "Неправильно введено название\n";
            }

            string resultBbk       = BBkInputComboBox.Text;
            string resultDirectBbk = DirectInputTextBox.Text;

            if (resultBbk == "" && resultDirectBbk == "")
            {
                resultString += "Неправильно введено BBK\n";
            }

            bool resultIsbn = check.CheckBookIsbn(ISBNInput.Text);

            if (!resultIsbn || ISBNInput.Text == "")
            {
                resultString += "Неправильно введен ISBN\n";
            }

            bool resultYear = check.CheckBookYear(YearInput.Text);

            if (!resultYear || YearInput.Text == "" || Convert.ToInt32(YearInput.Text) < 1500 || Convert.ToInt32(YearInput.Text) > DateTime.Now.Year)
            {
                resultString += "Неправильно введен год\n";
            }

            string resultInterpretor = InterpreterComboBox.Text;

            if (resultInterpretor == "")
            {
                resultString += "Неправильно введено имя Издания\n";
            }

            string resultChamber = ChamberComboBox.Text;

            if (resultChamber == "")
            {
                resultString += "Неправильно введен номер отсека\n";
            }

            if (resultString == "")
            {
                int userBbk = 0;

                if (SelectInputBtn.Visibility == Visibility.Collapsed)
                {
                    BbkWarningBtn.Visibility = Visibility.Collapsed;
                    userBbk = Convert.ToInt32(BBkInputComboBox.SelectedValue);
                }
                else if (SelectInputBtn.Visibility == Visibility.Visible)
                {
                    userBbk = fieldsController.GetBbkId(DirectInputTextBox.Text);
                }

                if (booksController.AddNewBook(AuthorInput.Text, userBbk, NameInput.Text, ISBNInput.Text, PlaceInput.Text, Convert.ToInt32(YearInput.Text), interpretorsController.GetInterpretorId(InterpreterComboBox.Text), Convert.ToInt32(ChamberComboBox.Text)))
                {
                    if (quantityController.AddNewQuantity(Settings.Default.bookId))
                    {
                        if (booksController.UpdateBookQuantity(Settings.Default.quantityId))
                        {
                            MessageBox.Show("Книга добавлена");
                            if (Settings.Default.role == 1)
                            {
                                this.NavigationService.Navigate(new MenuAdminPage());
                            }
                            if (Settings.Default.role == 2)
                            {
                                this.NavigationService.Navigate(new MenuLibrarianPage());
                            }
                        }
                        else
                        {
                            MessageBox.Show("Ошибка базы данных, попробуйте позже.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ошибка базы данных, попробуйте позже.");
                    }
                }
            }
            else
            {
                MessageBox.Show(resultString);
            }
        }