Exemple #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();
        }
Exemple #2
0
        private void PlacesComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (PlacesComboBox.Items.Count == 1)
            {
                AcceptAll.Visibility = Visibility.Collapsed;
            }

            using (var db = new LibraryDBContainer())
            {
                var t = db.DbPublicationSet1.Find(EditItem.Id).PhysicalLocations
                        .ElementAt(PlacesComboBox.SelectedIndex);
                t             = db.DbBookLocationSet.Find(t.Id);
                RoomsBox.Text = t.Room.ToString();
                Place.Text    = t.Place;

                try
                {
                    ListReaders.SelectedIndex = db.DbReaderSet.Select(d => d.Id).ToList().IndexOf(t.Reader.Id);
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }

                if (t.IsTaken)
                {
                    ReaderRButton.IsChecked = true;
                }
                else
                {
                    RoomRButton.IsChecked = true;
                }
            }
        }
Exemple #3
0
 public new void UpdateLayout()
 {
     ((Page)this).UpdateLayout();
     using (var db = new LibraryDBContainer())
     {
         DataGrid.ItemsSource = db.DbAuthorSet1.ToList();
     }
 }
Exemple #4
0
 public WindowAddEditPublication(Window Owner) : this()
 {
     this.Owner = Owner;
     using (var db = new LibraryDBContainer())
     {
         AuthorList.ItemsSource      = db.DbAuthorSet1.ToList().OrderBy(e => e.WriterType);
         DisciplinesList.ItemsSource = db.DbDisciplineSet.Where(d => d != null).ToList();
     }
 }
Exemple #5
0
        private void Search_OnClick(object sender, RoutedEventArgs e)
        {
            (Owner as WindowMain)?.NavigateTo(WindowMain.pPublications);
            Hide();
            using (var db = new LibraryDBContainer())
            {
                var p1 = db.DbPublicationSet1.ToList();

                p1 = p1.Where(d => BookBox.IsChecked == true && d.toEnumBP == eBookPublication.Book || PublicationBox.IsChecked == true && d.toEnumBP == eBookPublication.Publication).ToList();
                p1 = p1.Where(d => d.toEnumPT == ePublicationType.None || SciBox.IsChecked == true && d.toEnumPT == ePublicationType.Scientific || EduBox.IsChecked == true && d.toEnumPT == ePublicationType.Educational).ToList();
                p1 = p1.Where(d => PhysicalBox.IsChecked == true && d.PhysicalLocations.Count != 0 || EpubBox.IsChecked == true && !string.IsNullOrWhiteSpace(d.InternetLocation)).ToList();

                if (Course1.IsEnabled)
                {
                    p1 = p1.Where(d => Course1.IsChecked == true && d.Course.Contains(db.DbCourseSet.Find(1)) ||
                                  Course2.IsChecked == true && d.Course.Contains(db.DbCourseSet.Find(2)) ||
                                  Course3.IsChecked == true && d.Course.Contains(db.DbCourseSet.Find(3)) ||
                                  Course4.IsChecked == true && d.Course.Contains(db.DbCourseSet.Find(4))).ToList();
                }

                if (NameBox.IsEnabled)
                {
                    p1 = p1.Where(d => d.Name.ToLower().Contains(NameBox.Text.ToLower())).ToList();
                }

                if (ListAuthor.IsEnabled)
                {
                    var a1 = ListAuthor.SelectedItems.Cast <DbAuthor>().Select(d => d.Id).ToList();
                    var a2 = db.DbAuthorSet1.Where(f => a1.Contains(f.Id)).ToList();
                    p1 = p1.Where(d => d.Authors.Any(h => a2.Any(g => g == h))).ToList();
                }

                if (StartDate.IsEnabled)
                {
                    p1 = p1.Where(d => d.DatePublished >= StartDate.SelectedDate.Value && d.DatePublished <= FinishDate.SelectedDate.Value).ToList();
                }

                if (ListPublishers.IsEnabled)
                {
                    var a1 = ListPublishers.SelectedItems.Cast <string>().ToList();
                    p1 = p1.Where(d => a1.Contains(d.Publisher)).ToList();
                }

                if (ListDisciplines.IsEnabled)
                {
                    var a1 = ListDisciplines.SelectedItems.Cast <DbDiscipline>().Select(d => d.Id).ToList();
                    var a2 = db.DbDisciplineSet.Where(f => a1.Contains(f.Id)).ToList();
                    p1 = p1.Where(d => d.Discipline.Any(h => a2.Contains(h))).ToList();
                }


                WindowMain.pPublications.DataGrid.ItemsSource = p1;
            }

            MessageBox.Show("Поиск завершён", "Готово", MessageBoxButton.OK, MessageBoxImage.Information);
            Close();
        }
 private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
 {
     using (var db = new LibraryDBContainer())
     {
         db.DbDisciplineSet.Add(new DbDiscipline {
             Name = NewDiscipline.Text
         });
         db.SaveChanges();
     }
     Close();
 }
Exemple #7
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;
            }
        }
Exemple #8
0
        private void Accept_OnClick(object sender, RoutedEventArgs e)
        {
            Hide();
            if (Reader == null && Author == null)
            {
                using (var db = new LibraryDBContainer())
                {
                    if (isReader)
                    {
                        Reader = IsStudent
                            ? new DbReader(First.Text, Last.Text, Patronimic.Text, GroupBox.Text)
                            : new DbReader(First.Text, Last.Text, Patronimic.Text);
                        db.DbReaderSet.Add(Reader);
                    }
                    else
                    {
                        Author = new DbAuthor(First.Text, Last.Text, Patronimic.Text,
                                              (eWriterType)AuthorRole.SelectedIndex);
                        db.DbAuthorSet1.Add(Author);
                    }

                    db.SaveChanges();
                }
            }
            else
            {
                using (var db = new LibraryDBContainer())
                {
                    if (isReader)
                    {
                        Reader = db.DbReaderSet.Find(Reader.Id);

                        Reader.AccessLevel = (byte)UserRole.SelectedIndex;
                        Reader.Last        = Last.Text;
                        Reader.First       = First.Text;
                        Reader.Patronimic  = Patronimic.Text;
                        Reader.Group       = GroupBox.Text;
                    }
                    else
                    {
                        Author = db.DbAuthorSet1.Find(Author.Id);

                        Author.Last       = Last.Text;
                        Author.First      = First.Text;
                        Author.Patronimic = Patronimic.Text;
                        Author.WriterType = (byte)AuthorRole.SelectedIndex;
                    }

                    db.SaveChanges();
                }
            }
            Close();
        }
        public override bool Equals(object obj)
        {
            using (var db = new LibraryDBContainer())
            {
                var publication = obj as DbPublication;

                return(db.DbPublicationSet1.Any(e => e.Name == publication.Name &&
                                                e.DatePublished == publication.DatePublished &&
                                                e.Publisher == publication.Publisher &&
                                                e.PublicationType == publication.PublicationType &&
                                                e.BookPublication == publication.BookPublication));
            }
        }
Exemple #10
0
        public override bool Equals(object obj)
        {
            var o = obj as DbAuthor;

            using (var db = new LibraryDBContainer())
            {
                return(db.DbAuthorSet1.Any(d => d.Id == o.Id &&
                                           d.First == o.First &&
                                           d.Last == o.Last &&
                                           d.Patronimic == o.Patronimic &&
                                           d.WriterType == o.WriterType));
            }
        }
Exemple #11
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++;
        }
Exemple #12
0
        private void Delete_OnClick(object sender, RoutedEventArgs e)
        {
            var item = DataGrid.SelectedItem as DbAuthor;

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

                item.Publications.Clear();
                db.DbAuthorSet1.Remove(item);

                db.SaveChanges();
            }

            UpdateLayout();
        }
Exemple #13
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);
                }
            }
        }
Exemple #14
0
        private void Location_OnClick(object sender, RoutedEventArgs e)
        {
            var item = DataGrid.SelectedItem as DbPublication;

            using (var db = new LibraryDBContainer())
            {
                item = db.DbPublicationSet1.Find(item.Id);
                if (item.PhysicalLocations == null || item.PhysicalLocations.Count == 0)
                {
                    MessageBox.Show("Экземпляров не существует", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            var p = new WindowLocation(Owner, item);

            p.ShowDialog();
            UpdateLayout();
        }
Exemple #15
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();
        }
Exemple #16
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();
                }
            }
        }
        private void Delete_OnClick(object sender, RoutedEventArgs e)
        {
            var item = DataGrid.SelectedItem as DbReader;

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

                for (var i = 0; i < item.PhysicalLocation.Count; i++)
                {
                    item.PhysicalLocation.ElementAt(i).IsTaken = false;
                }
                item.PhysicalLocation.Clear();

                db.DbReaderSet.Remove(item);
                db.SaveChanges();
            }

            UpdateLayout();
        }
Exemple #18
0
        private void Accept_OnClick(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBContainer())
            {
                //выбраны книги или публиакции
                bool bCheck = BookCheck.IsChecked == true;
                bool pCheck = PubCheck.IsChecked == true;

                var result = db.DbPublicationSet1.ToArray();
                result = result.Where(d =>
                {
                    if (bCheck && pCheck)
                    {
                        return(true);
                    }
                    if (bCheck)
                    {
                        return(d.BookPublication == eBookPublication.Book.e());
                    }
                    if (pCheck)
                    {
                        return(d.BookPublication == eBookPublication.Publication.e());
                    }
                    return(false);
                }).ToArray();
                {
                    //выбор выделенных авторов
                    var a1 = AuthorList.SelectedItems.Cast <DbAuthor>().Select(g => g.Id).ToList();
                    var a2 = db.DbAuthorSet1.Where(f => a1.Contains(f.Id)).ToList();
                    result = result.Where(d => d.Authors.Any(h => a2.Any(g => g == h))).ToArray();
                }

                //открытие excel
                var app = new Application
                {
                    DisplayAlerts = true,
                    Visible       = true,
                };
                var       wbook  = app.Workbooks.Add(1);
                Worksheet wsheet = wbook.Worksheets[1];
                wsheet.Name = "Отчёт";

                switch (ReportType.SelectedIndex)
                {
                case 0:
                {
                    //выбор только преподавателей
                    var res = result.Where(d => d.Authors.Any(f => f.toEnumWT == eWriterType.HseTeacher))
                              //выбор дат публикации
                              .Where(d => PeriodButton.IsChecked == false ||
                                     d.DatePublished >= StartDate.SelectedDate.Value &&
                                     d.DatePublished <= FinishDate.SelectedDate.Value.AddDays(1))
                              //сотрировка по книгам/публикациям
                              .OrderByDescending(d => d.BookPublication)
                              //сортировка по дате публикации
                              .ThenBy(d => d.DDate)
                              .ToArray();

                    wsheet.Cells[1, 1] = "Название";
                    wsheet.Cells[1, 2] = "Авторы";
                    wsheet.Cells[1, 3] = "Опубликовано";

                    //запись в excel
                    for (int i = 0, offset = 2; i < res.Length; i++)
                    {
                        if (i == 0 || res[i].BookPublication != res[i - 1].BookPublication)
                        {
                            wsheet.Cells[i + offset++, 1] = $"{res[i].toEnumBP}s";
                        }

                        var authors = res[i].Authors
                                      .OrderBy(d => d.WriterType)
                                      .Select(d => d.ToString())
                                      .ToArray();

                        wsheet.Cells[i + offset, 1] = res[i].Name;
                        wsheet.Cells[i + offset, 2] = string.Join("\n", authors);
                        wsheet.Cells[i + offset, 3] = $"{res[i].DDate}";
                    }

                    break;
                }

                case 1:
                {
                    //отчёт по популярности
                    //выбор по датам выдачи
                    var selectDate = new Func <DbStats, bool>(f => PeriodButton.IsChecked == false ||
                                                              f.DateTaken.Date >= StartDate.SelectedDate.Value &&
                                                              f.DateTaken <= FinishDate.SelectedDate.Value.AddDays(1));

                    //выбор выданных хоть раз
                    var res = result.Where(d => d.Stats.Count > 0)
                              //сортировка по количеству выдач
                              .OrderBy(d => d.Stats.Count(selectDate))
                              .Reverse()
                              .ToArray();

                    wsheet.Cells[1, 1] = "Название";
                    wsheet.Cells[1, 2] = "Авторы";
                    wsheet.Cells[1, 3] = "Взято раз";

                    //запись в excel
                    for (int i = 0; i < res.Length; i++)
                    {
                        var authors = res[i].Authors
                                      .OrderBy(d => d.WriterType)
                                      .Select(d => d.ToString())
                                      .ToArray();

                        wsheet.Cells[i + 2, 1] = res[i].Name;
                        wsheet.Cells[i + 2, 2] = string.Join("\n", authors);
                        wsheet.Cells[i + 2, 3] = res[i].Stats.Count(selectDate);
                    }

                    break;
                }

                case 2:
                {
                    //отчёт по не возвращённым книгам
                    //выбор выданных книг
                    var res = result.SelectMany(d => d.PhysicalLocations)
                              .Where(d => d.IsTaken)
                              //сортировка по последней выдаче
                              .OrderBy(d => d.Publication.Stats.Last().DateTaken.ToNiceDate())
                              .ToArray();

                    wsheet.Cells[1, 1] = "Название";
                    wsheet.Cells[1, 2] = "Авторы";
                    wsheet.Cells[1, 3] = "Взявший";
                    wsheet.Cells[1, 4] = "Взято";

                    //запись в excel
                    for (int i = 0; i < res.Length; i++)
                    {
                        var el = res[i];

                        wsheet.Cells[i + 2, 1] = el.Publication.Name;
                        wsheet.Cells[i + 2, 2] =
                            string.Join("\n", el.Publication.Authors.Select(d => d.ToString()));
                        wsheet.Cells[i + 2, 3] = $"{el.Reader}, {el.Reader.Group}";
                        wsheet.Cells[i + 2, 4] = el.Publication.Stats.Last().DateTaken;
                    }

                    break;
                }
                }

                wsheet.Columns.ColumnWidth = 255;
                wsheet.Rows.RowHeight      = 255;
                wsheet.Columns.AutoFit();
                wsheet.Rows.AutoFit();

                app.Visible = true;
            }
        }
        private void Test_OnClick(object sender, RoutedEventArgs e)
        {
            using (var db = new LibraryDBContainer())
            {
                for (int i = 0; i < 6; i++)
                {
                    db.DbAuthorSet1.Add(DbAuthor.FillBlanks());
                }

                for (int i = 0; i < 10; i++)
                {
                    db.DbReaderSet.Add(DbReader.FillBlanks());
                }

                var courses = new[]
                {
                    new DbCourse {
                        Id = 1, Course = 1
                    },
                    new DbCourse {
                        Id = 2, Course = 2
                    },
                    new DbCourse {
                        Id = 3, Course = 3
                    },
                    new DbCourse {
                        Id = 4, Course = 4
                    },
                };
                foreach (var t in courses)
                {
                    db.DbCourseSet.Add(t);
                }

                var disciplines = new[]
                {
                    new DbDiscipline
                    {
                        Id   = 1,
                        Name = "Программирование",
                    },
                    new DbDiscipline
                    {
                        Id   = 2,
                        Name = "Конструирование ПО",
                    },
                    new DbDiscipline
                    {
                        Id   = 3,
                        Name = "НИС",
                    }
                };
                foreach (var t in disciplines)
                {
                    db.DbDisciplineSet.Add(t);
                }

                var publications = new[]
                {
                    new DbPublication("Принципы программирования",
                                      db.DbAuthorSet1.Local[2],
                                      ePublicationType.None,
                                      eBookPublication.Book,
                                      new DateTime(1985, 4, 1),
                                      "Росмэн")
                    {
                        Id     = 1,
                        Course = new []
                        {
                            courses[0],
                            courses[1]
                        },
                        Discipline = new []
                        {
                            disciplines[0]
                        }
                    },
                    new DbPublication("Справочник по C#",
                                      new[]
                    {
                        db.DbAuthorSet1.Local[1],
                        db.DbAuthorSet1.Local[2]
                    },
                                      ePublicationType.None,
                                      eBookPublication.Book,
                                      new DateTime(2011, 6, 1),
                                      "Справочники")
                    {
                        Id     = 3,
                        Course = new []
                        {
                            courses[0],
                        },
                        Discipline = new []
                        {
                            disciplines[0],
                        }
                    },
                    new DbPublication("Pascal.NET programming guide",
                                      new[]
                    {
                        db.DbAuthorSet1.Local[2],
                        db.DbAuthorSet1.Local[3]
                    },
                                      ePublicationType.Educational,
                                      eBookPublication.Publication,
                                      new DateTime(2001, 8, 1),
                                      "Питер")
                    {
                        Id     = 2,
                        Course = new []
                        {
                            courses[1],
                            courses[3]
                        },
                        Discipline = new []
                        {
                            disciplines[0],
                            disciplines[1]
                        }
                    },
                    new DbPublication("Как писать божественный код",
                                      db.DbAuthorSet1.Local[5],
                                      ePublicationType.Scientific,
                                      eBookPublication.Publication,
                                      new DateTime(2018, 3, 1),
                                      null)
                    {
                        Id = 6,
                        InternetLocation = "https://youtube.com/",
                        Course           = new []
                        {
                            courses[2],
                            courses[3]
                        },
                        Discipline = new []
                        {
                            disciplines[0],
                        }
                    },
                    new DbPublication("Почему Perl 6 - лучший язык программирования",
                                      new[]
                    {
                        db.DbAuthorSet1.Local[3],
                        db.DbAuthorSet1.Local[4],
                    },
                                      ePublicationType.Educational,
                                      eBookPublication.Publication,
                                      new DateTime(2015, 1, 1), null)
                    {
                        Id = 4,
                        InternetLocation = "https://google.com/",
                        Course           = new []
                        {
                            courses[1],
                            courses[2]
                        },
                        Discipline = new []
                        {
                            disciplines[1],
                        }
                    },
                    new DbPublication("Где учиться на программиста",
                                      db.DbAuthorSet1.Local[5],
                                      ePublicationType.Educational,
                                      eBookPublication.Publication,
                                      new DateTime(2016, 11, 1),
                                      null)
                    {
                        Id = 5,
                        InternetLocation = "https://wikipedia.org/",
                        Course           = new []
                        {
                            courses[1],
                            courses[3],
                        },
                        Discipline = new []
                        {
                            disciplines[2],
                        }
                    },
                };
                foreach (var t in publications)
                {
                    db.DbPublicationSet1.Add(t);
                }

                var locations = new[]
                {
                    new DbBookLocation
                    {
                        Id          = 1,
                        Room        = 307,
                        Place       = "здесь",
                        IsTaken     = true,
                        Reader      = db.DbReaderSet.Local[2],
                        Publication = db.DbPublicationSet1.Local[2]
                    },
                    new DbBookLocation
                    {
                        Id          = 2,
                        Room        = 321,
                        Place       = "где-то была",
                        IsTaken     = false,
                        Publication = db.DbPublicationSet1.Local[2]
                    },
                    new DbBookLocation
                    {
                        Id          = 3,
                        Room        = 501,
                        Place       = "в столе",
                        IsTaken     = true,
                        Reader      = db.DbReaderSet.Local[1],
                        Publication = db.DbPublicationSet1.Local[1]
                    },

                    new DbBookLocation
                    {
                        Id          = 4,
                        Room        = 321,
                        Place       = "на верхней полке шкафа",
                        IsTaken     = false,
                        Publication = db.DbPublicationSet1.Local[2]
                    },
                    new DbBookLocation
                    {
                        Id          = 5,
                        Room        = 318,
                        Place       = "в правом шкафу слева",
                        IsTaken     = false,
                        Publication = db.DbPublicationSet1.Local[0]
                    },
                    new DbBookLocation
                    {
                        Id          = 6,
                        Room        = 302,
                        Place       = "на столе",
                        IsTaken     = false,
                        Publication = db.DbPublicationSet1.Local[1]
                    },
                    new DbBookLocation
                    {
                        Id          = 7,
                        Room        = 323,
                        Place       = "под потолком",
                        IsTaken     = false,
                        Publication = db.DbPublicationSet1.Local[0]
                    },
                };
                foreach (var t in locations)
                {
                    db.DbBookLocationSet.Add(t);
                }

                var stats = new[]
                {
                    new DbStats {
                        Id = 1, DateTaken = new DateTime(2016, 01, 09), Publication = db.DbPublicationSet1.Local[2]
                    },
                    new DbStats {
                        Id = 2, DateTaken = new DateTime(2017, 06, 10), Publication = db.DbPublicationSet1.Local[2]
                    },
                    new DbStats {
                        Id = 3, DateTaken = new DateTime(2017, 11, 15), Publication = db.DbPublicationSet1.Local[1]
                    },
                    new DbStats {
                        Id = 4, DateTaken = new DateTime(2018, 08, 20), Publication = db.DbPublicationSet1.Local[1]
                    },
                    new DbStats {
                        Id = 5, DateTaken = new DateTime(2018, 03, 01), Publication = db.DbPublicationSet1.Local[2]
                    },
                };
                foreach (var t in stats)
                {
                    db.DbStatsSet.Add(t);
                }

                db.SaveChanges();
            }

            pPublications.UpdateLayout();
            pUsers.UpdateLayout();
            pAuthors.UpdateLayout();
        }
        private void Search_OnClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(SearchBox.Text))
            {
                MessageBox.Show("Пустой запрос");
                return;
            }

            var query = SearchBox.Text.ToLower();

            switch (OnScreenContent)
            {
            case PageAuthors pageAuthors:
            {
                using (var db = new LibraryDBContainer())
                {
                    pAuthors.DataGrid.ItemsSource =
                        db.DbAuthorSet1
                        .AsParallel()
                        .Where(g => g.First.ToLower().Contains(query) ||
                               g.Last.ToLower().Contains(query) ||
                               g.Patronimic.ToLower().Contains(query) ||
                               g.toEnumWT.ToString().ToLower().Contains(query) ||
                               g.Id.ToString().ToLower().Contains(query));
                }

                break;
            }

            case PagePublications pagePublications:
            {
                using (var db = new LibraryDBContainer())
                {
                    pPublications.DataGrid.ItemsSource =
                        db.DbPublicationSet1
                        .AsParallel()
                        .Where(d => d.Name.ToLower().Contains(query) ||
                               d.DatePublished.ToLongDateString().ToLower().Contains(query) ||
                               d.Course.Any(f => f.Course.ToString().ToLower().Contains(query)) ||
                               d.Discipline.Any(f => f.Name.ToLower().Contains(query)) ||
                               d.toEnumBP.ToString().ToLower().Contains(query) ||
                               d.toEnumPT.ToString().ToLower().Contains(query));
                }

                break;
            }

            case PageUsers pageUsers:
            {
                using (var db = new LibraryDBContainer())
                {
                    pUsers.DataGrid.ItemsSource =
                        db.DbReaderSet
                        .AsParallel()
                        .Where(d => d.First.ToLower().Contains(query) ||
                               d.Last.ToLower().Contains(query) ||
                               d.Patronimic.ToLower().Contains(query) ||
                               d.Group.ToString().ToLower().Contains(query) ||
                               d.Id.ToString().ToLower().Contains(query));
                }

                break;
            }
            }
        }
Exemple #21
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();
            }
        }