Beispiel #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            switch (typeof(T).Name)
            {
            case "Product":
                ProductForm pForm = new ProductForm();
                pForm.ShowDialog();
                if (pForm.DialogResult == DialogResult.OK)
                {
                    db.Products.Add(pForm.product);
                }
                break;

            case "Seller":
                SellerForm sForm = new SellerForm();
                sForm.ShowDialog();
                if (sForm.DialogResult == DialogResult.OK)
                {
                    db.Sellers.Add(sForm.seller);
                }
                break;

            case "Customer":
                CustomerForm cForm = new CustomerForm();
                cForm.ShowDialog();
                if (cForm.DialogResult == DialogResult.OK)
                {
                    db.Customers.Add(cForm.customer);
                }
                break;
            }

            db.SaveChanges();
        }
Beispiel #2
0
        private void SellerAddMenu_Click(object sender, EventArgs e)
        {
            var SellerForm = new SellerForm();

            if (SellerForm.ShowDialog() == DialogResult.OK)
            {
                database.Sellers.Add(SellerForm.seller);
                database.SaveChanges();
            }
        }
Beispiel #3
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count > 0)
            {
                int id = (int)dataGridView.SelectedRows[0].Cells[0].Value;
                switch (typeof(T).Name)
                {
                case "Product":
                    Product     product = db.Products.FirstOrDefault(p => p.ProductId == id);
                    ProductForm pForm   = new ProductForm(product);
                    pForm.ShowDialog();
                    if (pForm.DialogResult == DialogResult.OK)
                    {
                        product = pForm.product;
                    }
                    break;

                case "Seller":
                    Seller     seller = db.Sellers.FirstOrDefault(p => p.SellerId == id);
                    SellerForm sForm  = new SellerForm(seller);
                    sForm.ShowDialog();
                    if (sForm.DialogResult == DialogResult.OK)
                    {
                        seller = sForm.seller;
                    }
                    break;

                case "Customer":
                    Customer     customer = db.Customers.FirstOrDefault(p => p.CustomerId == id);
                    CustomerForm cForm    = new CustomerForm(customer);
                    cForm.ShowDialog();
                    if (cForm.DialogResult == DialogResult.OK)
                    {
                        customer = cForm.customer;
                    }
                    break;
                }

                db.SaveChanges();
            }
        }