Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                LibraryEntities le = new LibraryEntities();
                List <BookInfo> a  = new List <BookInfo>(le.Books.Select(x => new BookInfo()
                {
                    AuthorFirstName = x.Author.Name, AuthorSecondName = x.Author.Surname, Genre = x.Gener, PublishingYear = x.Year, Title = x.NameBook
                }));


                this.dataGridView1.DataSource = a;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
        public static object Search(string s)
        {
            LibraryEntities le = new LibraryEntities();

            var auth  = le.Author.ToList();
            var books = le.Books.ToList();

            var booksInfo = books.Join(auth, x => x.id_Author, y => y.id, (x, y) => new BookInfo
            {
                AuthorFirstName  = y.Name,
                AuthorSecondName = y.Surname,
                Genre            = x.Gener,
                PublishingYear   = x.Year,
                Title            = x.NameBook
            });

            if (Mediator.MediatorSearchBook.SearchBook() == 0)
            {
                booksInfo = booksInfo.Where(x => x.Title.Contains(s));
                return(booksInfo.ToArray());
            }
            if (Mediator.MediatorSearchBook.SearchBook() == 1)
            {
                booksInfo = booksInfo.Where(x => x.AuthorFirstName.Contains(s));
                return(booksInfo.ToArray());
            }
            if (Mediator.MediatorSearchBook.SearchBook() == 2)
            {
                booksInfo = booksInfo.Where(x => x.AuthorSecondName.Contains(s));
                return(booksInfo.ToArray());
            }
            if (Mediator.MediatorSearchBook.SearchBook() == 3)
            {
                booksInfo = booksInfo.Where(x => x.Genre.Contains(s));
                return(booksInfo.ToArray());
            }
            if (Mediator.MediatorSearchBook.SearchBook() == 4)
            {
                booksInfo = booksInfo.Where(x => x.PublishingYear.ToString().Contains(s));
                return(booksInfo.ToArray());
            }
            return(new List <BookInfo>());
        }
Exemple #3
0
        public void Add()
        {
            var le  = new LibraryEntities();
            var ath = new Author();
            var lib = new Librar();

            var name    = MediatorLoadBook.GetName();
            var surname = MediatorLoadBook.GetSurname();

            var bk = new Books
            {
                NameBook = Mediator.MediatorAddBook.GetNameBook(),
                Gener    = Mediator.MediatorAddBook.GetGenre(),
                Year     = Mediator.MediatorAddBook.GetDate()
            };

            var NomberShelf    = Mediator.MediatorAddBook.GetShelf();
            var NomberCupboard = Mediator.MediatorAddBook.GetCupboatd();


            ath          = le.Author.FirstOrDefault(x => x.Name == name && x.Surname == surname);
            bk.id_Author = ath.id;

            var c = le.Librar.FirstOrDefault(x => x.NomberCupboard == lib.NomberCupboard && x.NomberShelf == lib.NomberShelf);

            if (c == null)
            {
                le.Librar.Add(lib);

                lib          = le.Librar.FirstOrDefault(x => x.NomberCupboard == NomberCupboard && x.NomberShelf == NomberShelf);
                bk.id_Librar = lib.id;
                le.SaveChanges();
            }
            else
            {
                bk.id_Librar = c.id;
                le.SaveChanges();
            }

            le.Books.Add(bk);
            le.SaveChanges();
        }
Exemple #4
0
        private void AddAuth_Click(object sender, EventArgs e)
        {
            try
            {
                LibraryEntities le = new LibraryEntities();

                var ath = new Author
                {
                    Name    = this.textBox1.Text.ToString(),
                    Surname = this.textBox2.Text.ToString()
                };

                le.Author.Add(ath);
                le.SaveChanges();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }