Ejemplo n.º 1
0
        private void Add_Reader(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DataBase.Context db = new DataBase.Context())
                {
                    var reader = db.Readers.Where(p => p.Name == Name_Reader.Text);

                    if (reader.Count() == 0)
                    {
                        DataBase.Reader r = new DataBase.Reader {
                            Name = Name_Reader.Text
                        };
                        db.Readers.Add(r);
                        db.SaveChanges();
                        ReadersLoad();
                    }
                    else
                    {
                        MessageBox.Show("Данный читатель уже существует");
                    }
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Данные введены не верно");
            }
        }
Ejemplo n.º 2
0
        private void Add_Book(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DataBase.Context db = new DataBase.Context())
                {
                    var book = db.Books.Where(p =>
                                              p.Name == Name_Book.Text &&
                                              p.Author.Name == ListAuthors.SelectedItem.ToString());

                    var genre = db.Genres.Where(p => p.Name == Genre.SelectedItem.ToString());

                    var a = db.Authors.Where(p => p.Name == ListAuthors.SelectedItem.ToString());

                    if (book.Count() == 0)
                    {
                        DataBase.Book b = new DataBase.Book {
                            Name = Name_Book.Text, Year = Convert.ToInt32(Year.Text), Description = Description.Text, Genre = genre.FirstOrDefault(), Quantity = Convert.ToInt32(Quantity.Text), Author = a.FirstOrDefault()
                        };

                        db.Books.Add(b);
                        db.SaveChanges();
                        BooksLoad();
                    }
                    else
                    {
                        MessageBox.Show("Данная книга уже существует");
                    }
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Данные введены не верно");
            }
        }
Ejemplo n.º 3
0
        private void Add_Author(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DataBase.Context db = new DataBase.Context())
                {
                    var author = db.Authors.Where(p => p.Name == Name_Author.Text);

                    if (author.Count() == 0)
                    {
                        DataBase.Author a = new DataBase.Author {
                            Name = Name_Author.Text
                        };
                        db.Authors.Add(a);
                        db.SaveChanges();
                        AuthorsLoad();
                    }
                    else
                    {
                        MessageBox.Show("Данный автор уже существует");
                    }
                }
            }
            catch (Exception e1)
            {
                MessageBox.Show("Данные введены не верно");
            }
        }
Ejemplo n.º 4
0
        private void LibraryLoad()
        {
            using (DataBase.Context db = new DataBase.Context())
            {
                //db = new DataBase.Context();
                //db.Libraries.Load(); // загружаем данные
                //LibraryGrid.ItemsSource = db.Libraries.Local.ToBindingList();
                var libraries = db.Libraries.Select(p => new
                {
                    Id           = p.Id,
                    NameReader   = p.Reader.Name,
                    NameBook     = p.Book.Name,
                    DateOfTook   = p.DateOfTook,
                    DateOfReturn = p.DateOfReturn,
                    Author       = p.Book.Author.Name
                });

                LibraryGrid.ItemsSource = libraries.ToList();

                var reader = db.Readers.Select(p => p.Name);
                Reader.ItemsSource = reader.ToList();


                var book = db.Books.Select(p => p.Name);
                Book.ItemsSource = book.ToList();

                db.Dispose();
            }
        }
Ejemplo n.º 5
0
 private void ReadersLoad()
 {
     using (DataBase.Context db = new DataBase.Context())
     {
         var readers = db.Readers.Select(p => new
         {
             Id   = p.Id,
             Name = p.Name
         });
         ReadersGrid.ItemsSource = readers.ToList();
     }
 }
Ejemplo n.º 6
0
 private void AuthorsLoad()
 {
     using (DataBase.Context db = new DataBase.Context())
     {
         var authors = db.Authors.Select(p => new
         {
             Id   = p.Id,
             Name = p.Name
         });
         AuthorsGrid.ItemsSource = authors.ToList();
     }
 }
Ejemplo n.º 7
0
        private void BooksLoad()
        {
            using (DataBase.Context db = new DataBase.Context())
            {
                var books = db.Books.Select(p => new
                {
                    Id          = p.Id,
                    Name        = p.Name,
                    Year        = p.Year,
                    Description = p.Description,
                    Genre       = p.Genre.Name,
                    Quantity    = p.Quantity,
                    Author      = p.Author.Name
                });
                BooksGrid.ItemsSource = books.ToList();

                var author = db.Authors.Select(p => p.Name);
                ListAuthors.ItemsSource = author.ToList();

                var genre = db.Genres.Select(p => p.Name);
                Genre.ItemsSource = genre.ToList();
            }
        }
Ejemplo n.º 8
0
        private void Add_Took(object sender, RoutedEventArgs e)
        {
            try
            {
                using (DataBase.Context db = new DataBase.Context())
                {
                    var reader = db.Readers.Where(p => p.Name == Reader.Text);

                    var book = db.Books.Where(p => p.Name == Book.Text);

                    var libr = db.Libraries.Where(p => p.Book.Name == Book.Text && p.Reader.Name == Reader.Text);


                    DateTime d1 = DateTime.Today;
                    if (libr.Count() == 0)
                    {
                        DataBase.Library l = new DataBase.Library {
                            DateOfTook = d1, DateOfReturn = d1.AddMonths(2), Book = book.FirstOrDefault(), Reader = reader.FirstOrDefault()
                        };
                        db.Libraries.Add(l);
                        db.SaveChanges();
                        LibraryLoad();
                        MessageBox.Show("Книга выдана на 2 месяца");
                    }
                    else
                    {
                        MessageBox.Show("Данная запись уже существует");
                    }
                }
                db.Dispose();
            }
            catch (Exception e1)
            {
                MessageBox.Show("Данные введены не верно");
            }
        }
Ejemplo n.º 9
0
 public MainWindow()
 {
     InitializeComponent();
     db = new DataBase.Context();
     LibraryLoad();
 }