Ejemplo n.º 1
0
        public void Check()
        {
            if (Database.LibraryFilePath != "" && Database.LibraryFilePathSB != "")
            {
                // B O O K
                StreamReader reader      = new StreamReader(Database.LibraryFilePath);
                int          librarySize = Convert.ToInt32(reader.ReadLine());

                for (int i = 0; i < librarySize; i++)
                {
                    Book new_book = new Book("", "", "", "");
                    new_book.ExractFromFile(reader);
                }
                reader.Close();

                //  S T U D E N T B O O K
                StreamReader reader1 = new StreamReader(Database.LibraryFilePathSB);

                int studentsbookSize = Convert.ToInt32(reader1.ReadLine());

                for (int i = 0; i < studentsbookSize; i++)
                {
                    SBook new_studentbook = new SBook("", "", "", "", "", "");
                    new_studentbook.ExractFromFile(reader1);
                }
                reader1.Close();

                button_AddBook.Enabled = true;
                buttonLibrary.Enabled  = true;
            }
        }
Ejemplo n.º 2
0
        //Создание новой книги
        private void buttonConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (checkBoxBook.Checked == true)
                {
                    if (textboxTitle.Text != "" && textBoxAuthor.Text != "" && textBoxCount.Text != "" && textBoxPublishing.Text != "")
                    {
                        if (int.TryParse(textBoxCount.Text, out int check))
                        {
                            Book newBook = new Book(
                                title: textboxTitle.Text,
                                author: textBoxAuthor.Text,
                                pages: textBoxCount.Text,
                                publisher: textBoxPublishing.Text
                                );
                            Database.Library.Add(newBook);

                            MessageBox.Show("Книга успешно добавлена!", "Добавление", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                            textboxTitle.Text      = "";
                            textBoxAuthor.Text     = "";
                            textBoxCount.Text      = "";
                            textBoxPublishing.Text = "";
                        }
                        else
                        {
                            throw new FormatException();
                        }
                    }
                }
                if (checkBoxStudybook.Checked == true)
                {
                    if (textboxTitle.Text != "" && textBoxAuthor.Text != "" && textBoxCount.Text != "" && textBoxPublishing.Text != "" && textBoxSphere.Text != "")
                    {
                        SBook newBook = new SBook(
                            title: textboxTitle.Text,
                            author: textBoxAuthor.Text,
                            pages: textBoxCount.Text,
                            publisher: textBoxPublishing.Text,
                            coathors: textBoxCoAuthor.Text,
                            sphere: textBoxSphere.Text
                            );
                        Database.Studentbooks.Add(newBook);

                        MessageBox.Show("Учебник успешно добавлен!", "Добавление", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        textboxTitle.Text      = "";
                        textBoxAuthor.Text     = "";
                        textBoxCount.Text      = "";
                        textBoxPublishing.Text = "";
                        textBoxCoAuthor.Text   = "";
                        textBoxSphere.Text     = "";
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Количество страниц - не числовое значение", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch
            {
                MessageBox.Show("Некорректные данные", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }