Exemplo n.º 1
0
        private void deleteData_Click(object sender, EventArgs e)
        {
            if (BooksList.CurrentCell.ContextMenuStrip == changeData)
            {
                if (BooksList[0, BooksList.CurrentCell.RowIndex].Value == null)
                {
                    return;
                }

                bookName = BooksList[0, BooksList.CurrentCell.RowIndex].Value.ToString();
                BooksList.Rows.Remove(BooksList.CurrentRow);
                BooksBase.getBooksBase().deleteBook(bookName);
                BooksList.SelectionChanged += BooksList_SelectionChanged_1;
            }
            if (UsersList.CurrentCell.ContextMenuStrip == changeData)
            {
                if (UsersList[0, UsersList.CurrentCell.RowIndex].Value == null)
                {
                    return;
                }

                userName = UsersList[0, UsersList.CurrentCell.RowIndex].Value.ToString();
                UsersList.Rows.Remove(UsersList.CurrentRow);
                UsersBase.getUserBase().deleteUser(userName);
                UsersList.SelectionChanged += UsersList_SelectionChanged_1;
            }
        }
Exemplo n.º 2
0
        private void SetLists()
        {
            allBooks = new List <Book>();
            allUsers = new List <User>();
            allBooks = BooksBase.getBooksBase().getAllBooks();
            allUsers = UsersBase.getUserBase().getAllUsers();

            BooksList.Rows.Clear();
            if (allBooks.Count != 0)
            {
                BooksList.RowCount = allBooks.Count + 1;
                for (int i = 0; i < BooksList.RowCount - 1; i++)
                {
                    BooksList[0, i].Value = allBooks[i].name;
                    BooksList[1, i].Value = allBooks[i].author;
                    BooksList[2, i].Value = allBooks[i].genre;
                    BooksList[3, i].Value = allBooks[i].cost;
                }
            }

            UsersList.Rows.Clear();
            if (allUsers.Count != 0)
            {
                UsersList.RowCount = allUsers.Count + 1;
                for (int i = 0; i < UsersList.RowCount - 1; i++)
                {
                    UsersList[0, i].Value = allUsers[i].login;
                    UsersList[1, i].Value = allUsers[i].type;
                }
            }
        }
Exemplo n.º 3
0
        private void setInfo()
        {
            if (AdminBaseForm.bookName.Length != 0)
            {
                Book currentBook = new Book();
                currentBook = BooksBase.getBooksBase().getBook(AdminBaseForm.bookName);

                authorInfo.Text      = currentBook.author;
                nameInfo.Text        = currentBook.name;
                genreInfo.Text       = currentBook.genre;
                costInfo.Text        = currentBook.cost.ToString();
                bookDescription.Text = currentBook.description;

                DirectoryInfo directoryInfo = new DirectoryInfo("G:\\LovelyLibDataFiles\\booksImages\\");
                foreach (var item in directoryInfo.GetFiles())
                {
                    if (item.Name == currentBook.name + ".jpg")
                    {
                        pictureBook.Image = Image.FromFile("G:\\LovelyLibDataFiles\\booksImages\\" + currentBook.name + ".jpg");

                        break;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static BooksBase getBooksBase()
        {
            if (instance == null)
            {
                instance = new BooksBase();
            }

            return(instance);
        }
Exemplo n.º 5
0
        private void UpdateListBooks()
        {
            if (booksButton.Checked == true)
            {
                booksList.Items.Clear();
                List <Book> currentBooks = new List <Book>();
                currentBooks.AddRange(BooksBase.getBooksBase().getUserBooks(MainWindow.selectedUserLib.lib.id));

                foreach (var i in currentBooks)
                {
                    if (!booksList.Items.Contains(i.name) && (dataFilter.Checked == true && i.date == dataBox.Value.ToShortDateString() ||
                                                              dataFilter.Checked == false))
                    {
                        booksList.Items.Add(i.name);
                    }
                }

                currentSumText.Text = "Всего: " + booksList.Items.Count.ToString();
            }

            if (authorsButton.Checked == true)
            {
                booksList.Items.Clear();
                List <Book> currentBooks = new List <Book>();
                currentBooks.AddRange(BooksBase.getBooksBase().getUserBooks(MainWindow.selectedUserLib.lib.id));

                foreach (var i in currentBooks)
                {
                    if (!booksList.Items.Contains(i.author) && (dataFilter.Checked == true && i.date == dataBox.Value.ToShortDateString() ||
                                                                dataFilter.Checked == false))
                    {
                        booksList.Items.Add(i.author);
                    }
                }

                currentSumText.Text = "Всего: " + booksList.Items.Count.ToString();
            }

            if (genresButton.Checked == true)
            {
                booksList.Items.Clear();
                List <Book> currentBooks = new List <Book>();
                currentBooks.AddRange(BooksBase.getBooksBase().getUserBooks(MainWindow.selectedUserLib.lib.id));

                foreach (var i in currentBooks)
                {
                    if (!booksList.Items.Contains(i.genre) && (dataFilter.Checked == true && i.date == dataBox.Value.ToShortDateString() ||
                                                               dataFilter.Checked == false))
                    {
                        booksList.Items.Add(i.genre);
                    }
                }

                currentSumText.Text = "Всего: " + booksList.Items.Count.ToString();
            }
        }
Exemplo n.º 6
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (authorInfo.Text.Length != 0 && authorInfo.Text.Replace(" ", "").Length != 0 &&
                nameInfo.Text.Length != 0 && nameInfo.Text.Replace(" ", "").Length != 0 &&
                genreInfo.Text.Length != 0 && genreInfo.Text.Replace(" ", "").Length != 0 &&
                costInfo.Text.Length != 0 && costInfo.Text.Replace(" ", "").Length != 0 &&
                bookDescription.Text.Length != 0 && bookDescription.Text.Replace(" ", "").Length != 0)
            {
                for (int i = 0; i < costInfo.Text.Length; i++)
                {
                    if (!Char.IsDigit(costInfo.Text[i]))
                    {
                        MessageBox.Show("Цена задана некорректно!");
                        return;
                    }
                }

                Book currentBook = new Book();
                currentBook.author      = authorInfo.Text;
                currentBook.name        = nameInfo.Text;
                currentBook.genre       = genreInfo.Text;
                currentBook.cost        = Convert.ToInt32(costInfo.Text);
                currentBook.description = bookDescription.Text;

                if (AdminBaseForm.bookName.Length != 0)
                {
                    BooksBase.getBooksBase().editBook(AdminBaseForm.bookName, currentBook);
                }
                else
                {
                    BooksBase.getBooksBase().addBook(currentBook);
                }

                if (pictureBook.Image != null)
                {
                    pictureBook.Image.Dispose();
                    pictureBook.InitialImage = null;

                    string sourceDir = openPictureFile.FileName;
                    string destDir   = "G:\\LovelyLibDataFiles\\booksImages\\" + nameInfo.Text + ".jpg";

                    if (!File.Exists(destDir))
                    {
                        File.Copy(sourceDir, destDir, true);
                    }
                }

                this.Close();
            }
            else
            {
                MessageBox.Show("Необходимо заполнить каждое поле");
            }
        }
Exemplo n.º 7
0
        public CurrentBookInfoForm()
        {
            InitializeComponent();
            if (findImage())
            {
                pictureBook.Image = Image.FromFile("G:\\LovelyLibDataFiles\\booksImages\\" + CatalogForm.bookName + ".jpg");
            }

            Book currentBook = BooksBase.getBooksBase().getBook(CatalogForm.bookName);

            bookDescription.Text = currentBook.description;
        }
Exemplo n.º 8
0
        private void SetInfo()
        {
            if (findImage())
            {
                pictureBook.Image = Image.FromFile("G:\\LovelyLibDataFiles\\booksImages\\" + CatalogForm.bookName + ".jpg");
            }

            Book currentBook = BooksBase.getBooksBase().getBookFromLib(CatalogForm.bookName, MainWindow.selectedUserLib.lib);

            nameInfo.Text        = currentBook.name;
            authorInfo.Text      = currentBook.author;
            genreInfo.Text       = currentBook.genre;
            costInfo.Text        = currentBook.cost.ToString();
            bookDescription.Text = currentBook.description;
            addCalendarBox.SetDate(DateTime.Parse(currentBook.date));
        }
Exemplo n.º 9
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (BooksList.CurrentCell == null || BooksList[0, BooksList.CurrentCell.RowIndex].Value == null)
            {
                MessageBox.Show("Вы не выбрали книгу!");
                return;
            }

            if (BooksBase.getBooksBase().addBookToLib(BooksList[0, BooksList.CurrentCell.RowIndex].Value.ToString(), ChooseLib.selectedLib.lib))
            {
                FilterForm.filterBooks.Clear();
                MessageBox.Show("Книга \"" + BooksList[0, BooksList.CurrentCell.RowIndex].Value.ToString() + "\" добавлена в вашу библиотеку");
            }
            else
            {
                MessageBox.Show("Эта книга уже есть в вашей библиотеке");
            }
        }
Exemplo n.º 10
0
 private void yesButton_Click(object sender, EventArgs e)
 {
     BooksBase.getBooksBase().deleteBookFromLib(MainWindow.delBook, ChooseLib.selectedLib.lib);
     FilterForm.filterBooks.Clear();
     this.Hide();
 }