Пример #1
0
 public FormChangeBookExemplar(int id)
 {
     InitializeComponent();
     bookexemplar               = model.BookExemplarSet.Find(id);
     labelTitle.Text            = book.Name;
     labelAuthor.Text           = book.Author.Surname + " " + book.Author.Name + " " + book.Author.SecondName;
     labelGenre.Text            = book.Genre.Name;
     labelBookDescription.Text  = book.Description;
     labelGenreDescription.Text = book.Genre.Description;
     ShowComboBoxes();
     ShowTextBoxes();
 }
Пример #2
0
        private void buttonAddInfo_Click(object sender, EventArgs e)
        {
            if ((comboBoxSeries.SelectedItem != null) && (comboBoxStore.SelectedItem != null))
            {
                BookExemplar bookexemplar = new BookExemplar();
                {
                    try
                    {
                        if (Int32.Parse(textBoxYear.Text) <= DateTime.Now.Year)
                        {
                            bookexemplar.Year = Int32.Parse(textBoxYear.Text);
                        }
                        else
                        {
                            MessageBox.Show("Неверно указан год");
                            return;
                        }
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Неверно указан год");
                        return;
                    }

                    try
                    {
                        bookexemplar.Number = Int32.Parse(textBoxNumber.Text);
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("Неверно указано количество");
                        return;
                    }
                }

                Series series =
                    model.SeriesSet.Find(
                        model.SeriesSet.Where(x => x.Name.Contains(comboBoxSeries.Text)).ToList()[0].Id);
                series.BookExemplar.Add(bookexemplar);
                Store store =
                    model.StoreSet.Find(model.StoreSet.Where(x => (x.Name + " " + x.City.Name).Contains(comboBoxStore.Text)).ToList()[0].Id);
                store.BookExemplar.Add(bookexemplar);

                book.BookExemplar.Add(bookexemplar);

                model.BookExemplarSet.Add(bookexemplar);
                model.SaveChanges();

                ParentBookExemplar.ShowTable();
                ParentBookExemplar.Show();
                Close();
            }
            else
            {
                if (comboBoxSeries.SelectedItem == null)
                {
                    MessageBox.Show("Вы не указали серию");
                }
                if (comboBoxStore.SelectedItem == null)
                {
                    MessageBox.Show("Вы не указали магазин");
                }
            }
        }