Exemple #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Dishes player = db.Dishes.Find(id);
                db.Dishes.Remove(player);
                db.SaveChanges();

                MessageBox.Show("Объект удален");
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (NameDish.Text == "" || CategoryDish.Text == "" || DescripDish.Text == "" || VesDish.Text == "" || PriceDish.Text == "" || label7.Text == "")
            {
                MessageBox.Show("Одно из значений имеет пустое поле", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                //DataBaseEntities db = new DataBaseEntities();
                Dishes Dishname = new Dishes();
                //int id = db.Dishes.Max(x => x.Id);
                //Dishname.Id = id + 1;
                Dishname.Name        = NameDish.Text;
                Dishname.Category    = CategoryDish.Text;
                Dishname.Description = DescripDish.Text;
                Dishname.Ves         = Convert.ToInt32(VesDish.Text);
                Dishname.Price       = Convert.ToDecimal(PriceDish.Text);
                byte[]       imgBrands = null;
                FileStream   fsBrand   = new FileStream(pathImage, FileMode.Open, FileAccess.Read);
                BinaryReader brBrand   = new BinaryReader(fsBrand);
                imgBrands           = brBrand.ReadBytes((int)fsBrand.Length);
                Dishname.ImagesDish = imgBrands;
                db.Dishes.Add(Dishname);
                db.SaveChanges();

                NameDish.Text     = "";
                CategoryDish.Text = "";
                DescripDish.Text  = "";
                VesDish.Text      = "";
                PriceDish.Text    = "";
                label7.Text       = "";
                MessageBox.Show("Новый объект добавлен", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);

                db.Dishes.Load();
                dataGridView1.DataSource = db.Dishes.Local.ToBindingList();
                this.dishesTableAdapter.Fill(this.dataKursDataSet.Dishes);
            }
        }