コード例 #1
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();
            }
        }
コード例 #2
0
        private void booksView_Click(object sender, RoutedEventArgs e)
        {
            if (Readers.Visibility == Visibility.Visible)
            {
                Readers.Visibility = Visibility.Collapsed;
            }
            else if (Library.Visibility == Visibility.Visible)
            {
                Library.Visibility = Visibility.Collapsed;
            }
            else
            {
                Authors.Visibility = Visibility.Collapsed;
            }


            Books.Visibility = Visibility.Visible;

            BooksLoad();
            db.Dispose();
        }
コード例 #3
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("Данные введены не верно");
            }
        }