Пример #1
0
        private void Delete_OnClick(object sender, RoutedEventArgs e)
        {
            DbPublication item = DataGrid.SelectedItem as DbPublication;

            using (var db = new LibraryDBContainer())
            {
                item = db.DbPublicationSet1.Find(item.Id);

                item.Authors.Clear();
                item.Course.Clear();

                foreach (var location in item.PhysicalLocations)
                {
                    location.Reader      = null;
                    location.Publication = null;
                }

                item.PhysicalLocations.Clear();

                item.Stats.Clear();
                item.Discipline.Clear();
                db.DbPublicationSet1.Remove(item);
                db.SaveChanges();
            }

            UpdateLayout();
        }
Пример #2
0
        private void This_OnLoaded(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBContainer())
            {
                Display = db.DbPublicationSet1.Find(Display.Id);

                UriBox.Text            = Display.InternetLocation;
                ListPlaces.ItemsSource = Display.PhysicalLocations.Where(d => !d.IsTaken);
                var t = Display.PhysicalLocations.Where(d => d.IsTaken).Select(d => d.Reader);
                ListReaders.ItemsSource = t;
            }
        }
Пример #3
0
        private void Accept_OnClick(object sender, RoutedEventArgs e)
        {
            //PlacesComboBox.Items.Remove(PlacesComboBox.SelectedItem);
            using (var db = new LibraryDBContainer())
            {
                EditItem = db.DbPublicationSet1.Find(EditItem.Id);

                int.TryParse(RoomsBox.Text, out int num);

                DbBookLocation p;
                if (EditItem.PhysicalLocations.ElementAt(PlacesComboBox.SelectedIndex) == null)
                {
                    p = new DbBookLocation(num, Place.Text)
                    {
                        IsTaken     = ReaderRButton.IsChecked == true,
                        Reader      = ListReaders.SelectedIndex != -1 ? db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader)?.Id) : null,
                        Publication = EditItem
                    }
                }
                ;
                else
                {
                    p         = EditItem.PhysicalLocations.ElementAt(PlacesComboBox.SelectedIndex);
                    p.Room    = num;
                    p.Place   = Place.Text;
                    p.IsTaken = ReaderRButton.IsChecked == true;
                    p.Reader  = ListReaders.SelectedIndex != -1 ? db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader)?.Id) : null;
                }

                if (ReaderRButton.IsChecked == true)
                {
                    db.DbStatsSet.Add(new DbStats
                    {
                        DateTaken   = DateTime.Now,
                        Publication = EditItem,
                    });
                }

                db.DbBookLocationSet.Local.Add(p);
                db.SaveChanges();
            }


            if (PlacesComboBox.SelectedIndex == PlacesComboBox.Items.Count)
            {
                Close();
            }
            PlacesComboBox.SelectedIndex++;
        }
Пример #4
0
        public WindowAddEditPublication(Window Owner, DbPublication pub) : this(Owner)
        {
            Publication  = pub;
            NameBox.Text = Publication.Name;
            PublishDatePicker.SelectedDate = Publication.DatePublished;
            Publisher.Text = Publication.Publisher;

            BookRButton.IsChecked        = Publication.BookPublication == eBookPublication.Book.e();
            PublicationRButton.IsChecked = Publication.BookPublication == eBookPublication.Publication.e();

            ScientificPublication.IsChecked = Publication.PublicationType == ePublicationType.Scientific.e();
            MethodicalPublication.IsChecked = Publication.PublicationType == ePublicationType.Educational.e();

            EpubCheckBox.IsChecked = !string.IsNullOrWhiteSpace(Publication.InternetLocation);
            EpubAdress.Text        = Publication.InternetLocation;

            using (var db = new LibraryDBContainer())
            {
                Publication = db.DbPublicationSet1.Find(Publication.Id);
                var p = Publication?.Course.Select(e => e.Course).ToList();
                if (p != null)
                {
                    Course1.IsChecked = p.Contains(1);
                    Course2.IsChecked = p.Contains(2);
                    Course3.IsChecked = p.Contains(3);
                    Course4.IsChecked = p.Contains(4);
                }

                PubNumberChechBox.IsChecked = Publication?.PhysicalLocations.Count != 0;
                PubNumber.Text = Publication?.PhysicalLocations.Count.ToString();

                AuthorList.ItemsSource = db.DbAuthorSet1.ToList().OrderBy(e => e.WriterType);
                foreach (var author in db.DbAuthorSet1.Where(d => d.Publications.Any(e => e.Id == Publication.Id)))
                {
                    AuthorList.SelectedItems.Add(author);
                }

                DisciplinesList.ItemsSource = db.DbDisciplineSet.Where(d => d != null).ToList();
                foreach (DbDiscipline discipline in db.DbDisciplineSet.Where(
                             d => d.Publication.Any(e => e.Id == Publication.Id)))
                {
                    DisciplinesList.SelectedItems.Add(discipline);
                }
            }
        }
Пример #5
0
        private void AcceptAll_OnClick(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBContainer())
            {
                EditItem = db.DbPublicationSet1.Find(EditItem.Id);
                for (int i = 0; i < PlacesComboBox.Items.Count; i++)
                {
                    db.DbBookLocationSet.Add(new DbBookLocation(int.Parse(RoomsBox.Text), Place.Text)
                    {
                        IsTaken     = ReaderRButton.IsChecked == true,
                        Reader      = db.DbReaderSet.Find((ListReaders.SelectedItem as DbReader).Id),
                        Publication = EditItem
                    });
                    db.SaveChanges();
                }
            }

            Close();
        }
Пример #6
0
        public WindowEditLocation(Window Owner, DbPublication pub, int number = 0) : this(Owner)
        {
            EditItem = pub;

            using (var db = new LibraryDBContainer())
            {
                EditItem = db.DbPublicationSet1.Find(EditItem.Id) ?? pub;
                if (EditItem.PhysicalLocations == null || EditItem.PhysicalLocations.Count == 0)
                {
                    for (int i = 0; i < number; i++)
                    {
                        PlacesComboBox.Items.Add(i + 1);
                    }
                }
                else
                {
                    PlacesComboBox.ItemsSource = EditItem.PhysicalLocations.Select(e => e.ToString().Clone()).ToArray();
                }
            }
        }
Пример #7
0
 public WindowLocation(Window Owner, DbPublication item) : this(Owner)
 {
     Display = item;
 }
Пример #8
0
        private void LocationButton_OnClick(object sender, RoutedEventArgs e)
        {
            int num = 0;

            int.TryParse(PubNumber.Text, out num);

            Hide();
            if (Publication == null)
            {
                using (var db = new LibraryDBContainer())
                {
                    Publication = new DbPublication(NameBox.Text, new List <DbAuthor>(),
                                                    BookRButton.IsChecked == true
                                                        ? ePublicationType.None
                                                        : ScientificPublication.IsChecked == true
                                                            ? ePublicationType.Scientific
                                                            : ePublicationType.Educational,
                                                    BookRButton.IsChecked == true
                                                        ? eBookPublication.Book
                                                        : eBookPublication.Publication,
                                                    PublishDatePicker.SelectedDate.Value, Publisher.Text);

                    if (Course1.IsChecked == true)
                    {
                        db.DbCourseSet.Find(1).Publication.Add(Publication);
                    }
                    if (Course2.IsChecked == true)
                    {
                        db.DbCourseSet.Find(2).Publication.Add(Publication);
                    }
                    if (Course3.IsChecked == true)
                    {
                        db.DbCourseSet.Find(3).Publication.Add(Publication);
                    }
                    if (Course4.IsChecked == true)
                    {
                        db.DbCourseSet.Find(4).Publication.Add(Publication);
                    }

                    var selectedIds = AuthorList
                                      .SelectedItems.Cast <DbAuthor>()
                                      .Select(g => g.Id);
                    Publication.Authors = db.DbAuthorSet1.Where(d => selectedIds.Contains(d.Id)).ToList();

                    db.DbPublicationSet1.Add(Publication);

                    var selectedDisciplines = db.DbDisciplineSet
                                              .ToArray()
                                              .Where(d =>
                    {
                        return(DisciplinesList
                               .SelectedItems
                               .Cast <DbDiscipline>()
                               .Select(f => f.Id)
                               .Contains(d.Id));
                    });
                    foreach (var disc in selectedDisciplines)
                    {
                        disc.Publication.Add(Publication);
                    }

                    if (EpubCheckBox.IsChecked == true)
                    {
                        Publication.InternetLocation = EpubAdress.Text;
                    }

                    if (EpubCheckBox.IsChecked != true && PubNumberChechBox.IsChecked != true)
                    {
                        Publication.BookPublication = eBookPublication.None.e();
                    }

                    Publication.PhysicalLocations = new List <DbBookLocation>(num);

                    db.SaveChanges();
                }

                if (PubNumberChechBox.IsChecked == true)
                {
                    var p = new WindowEditLocation(this, Publication, num);
                    p.ShowDialog();
                }

                Close();
            }
            else
            {
                using (var db = new LibraryDBContainer())
                {
                    Publication = db.DbPublicationSet1.Find(Publication.Id);

                    Publication.Name          = NameBox.Text;
                    Publication.DatePublished = PublishDatePicker.SelectedDate.Value;
                    Publication.Publisher     = Publisher.Text;

                    Publication.BookPublication = BookRButton.IsChecked == true
                        ? eBookPublication.Book.e()
                        : eBookPublication.Publication.e();

                    Publication.PublicationType = BookRButton.IsChecked == true
                        ? ePublicationType.None.e()
                        : ScientificPublication.IsChecked == true
                            ? ePublicationType.Scientific.e()
                            : ePublicationType.Educational.e();

                    Publication.Course.Clear();
                    if (Course1.IsChecked == true)
                    {
                        db.DbCourseSet.Find(1).Publication.Add(Publication);
                    }
                    if (Course2.IsChecked == true)
                    {
                        db.DbCourseSet.Find(2).Publication.Add(Publication);
                    }
                    if (Course3.IsChecked == true)
                    {
                        db.DbCourseSet.Find(3).Publication.Add(Publication);
                    }
                    if (Course4.IsChecked == true)
                    {
                        db.DbCourseSet.Find(4).Publication.Add(Publication);
                    }

                    Publication.Discipline.Clear();
                    foreach (var disc in DisciplinesList
                             .SelectedItems.Cast <DbDiscipline>().Select(d => db.DbDisciplineSet.Find(d.Id)))
                    {
                        Publication.Discipline.Add(disc);
                    }

                    if (EpubCheckBox.IsChecked == true)
                    {
                        Publication.InternetLocation = EpubAdress.Text;
                    }

                    Publication.Authors.Clear();
                    Publication.Authors = AuthorList.SelectedItems.Cast <DbAuthor>()
                                          .Select(d => db.DbAuthorSet1.Find(d.Id)).ToList();
                    Thread.Sleep(10);
                    db.SaveChanges();
                }

                if (PubNumberChechBox.IsChecked == true)
                {
                    var p = new WindowEditLocation(this, Publication, num);
                    p.ShowDialog();
                }

                Close();
            }
        }