Ejemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ShowAllProducts f = new ShowAllProducts();

            f.Show();
            this.Hide();
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            String n = name.Text;
            double p = Double.Parse(price.Text);
            String c = category.Text;
            String b = brand.Text;

            Boolean check = false;
            int     id    = -1;

            Model1 db     = new Model1();
            var    brands = (from r in db.brands select new { name = r.name, id = r.id }).ToList();

            foreach (var bb in brands)
            {
                if (bb.name.Equals(b))
                {
                    check = true;
                    id    = bb.id;
                    break;
                }
            }

            if (check)
            {
                db.products.Add(new product {
                    id = db.products.Count(), name = n, price = (decimal)p, category = c, brand_id = id
                });

                db.SaveChanges();

                ShowAllProducts f = new ShowAllProducts();
                f.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("This brand does not exist !");
            }
        }