Пример #1
0
        private void customerAddToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            var form = new CustomerFormLoad();

            if (form.ShowDialog() == DialogResult.OK)
            {
                _contextDb.Customers.Add(form.Customer);
                _contextDb.SaveChanges();
            }
        }
Пример #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            // Getting firs row is equals id
            var id = dataGridView.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                if (_set.Find(id) is Product product)
                {
                    // Edit form product at the new form
                    var form = new ProductFormLoad(product);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        product = form.Product;
                        _db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Seller))
            {
                if (_set.Find(id) is Seller seller)
                {
                    // Edit form product at the new form
                    var form = new SellerFormLoad(seller);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        seller = form.Seller;
                        _db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Customer))
            {
                if (_set.Find(id) is Customer customer)
                {
                    // Edit form product at the new form
                    var form = new CustomerFormLoad(customer);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        customer = form.Customer;
                        _db.SaveChanges();
                        dataGridView.Update();
                    }
                }
            }
        }