コード例 #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Ingredients i = (Ingredients)ingredientsBindingSource.Current;

            ingr a = new ingr();

            a.db = db;
            a.i  = i;

            DialogResult dr = a.ShowDialog();

            if (dr == DialogResult.OK)
            {
                ingredientsBindingSource.DataSource = db.Ingredients.ToList();
            }
        }
コード例 #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            Ingredients i = (Ingredients)ingredientsBindingSource.Current;

            string       str = $"Вы действительно хотите удалить - {i.Nomer}";
            DialogResult dr  = MessageBox.Show(str, "Удаление ингредиент", MessageBoxButtons.YesNo,
                                               MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (dr == DialogResult.Yes)
            {
                db.Ingredients.Remove(i);
                try
                {
                    db.SaveChanges();
                    MessageBox.Show($"Ингредиент - {i.Name} успешно удален!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Произошла ошибка - " + ex.Message);
                }
            }
        }