Exemplo n.º 1
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         int sageId = Convert.ToInt32(dataGridViewSage.SelectedRows[0].Cells["Id"].Value);
         using (SagesAndBooksEntities context = new SagesAndBooksEntities())
         {
             Sage sage = context.Sages.Where(s => s.Id == sageId).FirstOrDefault();
             context.Sages.Remove(sage);
             context.SaveChanges();
         }
         InitializeDataGridViewSage();
     }
     catch { MessageBox.Show("Selected row == null"); }
 }
Exemplo n.º 2
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            using (SagesAndBooksEntities context = new SagesAndBooksEntities())
            {
                Sage sage = context.Sages.Where(s => s.Id == sageId).FirstOrDefault();

                if (!string.IsNullOrWhiteSpace(textBoxName.Text) &&
                    !string.IsNullOrWhiteSpace(textBoxAge.Text))
                {
                    sage.Name = textBoxName.Text;
                    sage.Age  = Convert.ToInt32(textBoxAge.Text);

                    context.SaveChanges();
                }
                this.Dispose();
                this.Close();
            }
        }
Exemplo n.º 3
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            using (SagesAndBooksEntities context = new SagesAndBooksEntities())
            {
                Book book = context.Books.Where(b => b.Id == bookId).FirstOrDefault();

                if (!string.IsNullOrWhiteSpace(textBoxName.Text) &&
                    !string.IsNullOrWhiteSpace(textBoxPrice.Text) && book != null)
                {
                    book.Name  = textBoxName.Text;
                    book.Price = Convert.ToInt32(textBoxPrice.Text);

                    context.SaveChanges();
                }
                this.Dispose();
                this.Close();
            }
        }
Exemplo n.º 4
0
 private void buttonInsert_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(textBoxName.Text) &&
         !string.IsNullOrWhiteSpace(textBoxAge.Text))
     {
         using (SagesAndBooksEntities context = new SagesAndBooksEntities())
         {
             Sage sage = new Sage()
             {
                 Name = textBoxName.Text,
                 Age  = Convert.ToInt32(textBoxAge.Text)
             };
             context.Sages.Add(sage);
             context.SaveChanges();
         }
         this.Dispose();
         this.Close();
     }
 }
Exemplo n.º 5
0
 private void buttonInsert_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(textBoxName.Text) &&
         !string.IsNullOrWhiteSpace(textBoxPrice.Text) &&
         !string.IsNullOrWhiteSpace(comboBoxSages.Text))
     {
         using (SagesAndBooksEntities context = new SagesAndBooksEntities())
         {
             Book book = new Book()
             {
                 Name   = textBoxName.Text,
                 Price  = Convert.ToInt32(textBoxPrice.Text),
                 SageId = (comboBoxSages.SelectedItem as Sage).Id
             };
             context.Books.Add(book);
             context.SaveChanges();
         }
         this.Dispose();
         this.Close();
     }
 }