Пример #1
0
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxTitle.Text != "" && textBoxAuthor.Text != "" &&
                textBoxPrice.Text != "" && comboBoxGenre.SelectedItem != null)
            {
                BookSet book = new BookSet();

                book.Title  = textBoxTitle.Text;
                book.Author = textBoxAuthor.Text;

                if (comboBoxGenre.SelectedIndex == 0)
                {
                    book.Genre = 0;
                }
                else if (comboBoxGenre.SelectedIndex == 1)
                {
                    book.Genre = 1;
                }
                else if (comboBoxGenre.SelectedIndex == 2)
                {
                    book.Genre = 2;
                }

                book.Price = Convert.ToInt32(textBoxPrice.Text);

                Program.litRes.BookSet.Add(book);
                Program.litRes.SaveChanges();
                ShowBookSet();
            }
            else
            {
                MessageBox.Show("Заполните обязательные поля!", "Ошибка",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
 private void ButtonDel_Click(object sender, EventArgs e)
 {
     try
     {
         if (comboBoxGenre.SelectedIndex == 0)
         {
             if (listViewBooks.SelectedItems.Count == 1)
             {
                 BookSet book = listViewBooks.SelectedItems[0].Tag as BookSet;
                 Program.litRes.BookSet.Remove(book);
                 Program.litRes.SaveChanges();
                 ShowBookSet();
             }
             textBoxTitle.Text  = "";
             textBoxAuthor.Text = "";
             textBoxPrice.Text  = "";
         }
         else if (comboBoxGenre.SelectedIndex == 1)
         {
             if (listViewBooks.SelectedItems.Count == 1)
             {
                 BookSet book = listViewBooks.SelectedItems[0].Tag as BookSet;
                 Program.litRes.BookSet.Remove(book);
                 Program.litRes.SaveChanges();
                 ShowBookSet();
             }
             textBoxTitle.Text  = "";
             textBoxAuthor.Text = "";
             textBoxPrice.Text  = "";
         }
         else if (comboBoxGenre.SelectedIndex == 2)
         {
             if (listViewBooks.SelectedItems.Count == 1)
             {
                 BookSet book = listViewBooks.SelectedItems[0].Tag as BookSet;
                 Program.litRes.BookSet.Remove(book);
                 Program.litRes.SaveChanges();
                 ShowBookSet();
             }
             textBoxTitle.Text  = "";
             textBoxAuthor.Text = "";
             textBoxPrice.Text  = "";
         }
     }
     catch
     {
         MessageBox.Show("Невозможно удалить, эта запись используется!", "Ошибка!",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #3
0
 private void ListViewBooks_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listViewBooks.SelectedItems.Count == 1)
     {
         BookSet book = listViewBooks.SelectedItems[0].Tag as BookSet;
         textBoxTitle.Text  = book.Title;
         textBoxAuthor.Text = book.Author;
         comboBoxGenre.Text = book.Genre.ToString();
         textBoxPrice.Text  = book.Price.ToString();
     }
     else
     {
         textBoxTitle.Text          = "";
         textBoxAuthor.Text         = "";
         comboBoxGenre.SelectedItem = null;
         textBoxPrice.Text          = "";
     }
 }
Пример #4
0
        private void ButtonEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (listViewBooks.SelectedItems.Count == 1)
                {
                    BookSet book = listViewBooks.SelectedItems[0].Tag as BookSet;

                    if (textBoxTitle.Text != "" && textBoxAuthor.Text != "" &&
                        textBoxPrice.Text != "" && comboBoxGenre.SelectedItem != null)
                    {
                        throw new Exception("Заполните обязательные поля!");
                    }

                    book.Title  = textBoxTitle.Text;
                    book.Author = textBoxAuthor.Text;

                    if (comboBoxGenre.SelectedIndex == 0)
                    {
                        book.Genre = 0;
                    }
                    else if (comboBoxGenre.SelectedIndex == 1)
                    {
                        book.Genre = 1;
                    }
                    else if (comboBoxGenre.SelectedIndex == 2)
                    {
                        book.Genre = 2;
                    }

                    book.Price = Convert.ToInt32(textBoxPrice.Text);

                    Program.litRes.SaveChanges();
                    ShowBookSet();
                }
            }
            catch (Exception ex) { MessageBox.Show("" + ex.Message, "Внимание",
                                                   MessageBoxButtons.OK, MessageBoxIcon.Information); }
        }