Exemplo n.º 1
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     if (sender is Button button)
     {
         if (typeof(T) == typeof(Product))
         {
             var form = new ProductForm();
             if (form.ShowDialog() == DialogResult.OK)
             {
                 db.Products.Add(form.Product);
                 db.SaveChanges();
             }
         }
         else if (typeof(T) == typeof(Seller))
         {
             var form = new SellerForm();
             if (form.ShowDialog() == DialogResult.OK)
             {
                 db.Sellers.Add(form.Seller);
                 db.SaveChanges();
             }
         }
         else if (typeof(T) == typeof(Customer))
         {
             var form = new CustomerForm();
             if (form.ShowDialog() == DialogResult.OK)
             {
                 db.Customers.Add(form.Customer);
                 db.SaveChanges();
             }
         }
         dataGridView.Refresh();
     }
 }
Exemplo n.º 2
0
        private void SellerAddToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            SellerForm Form = new SellerForm();

            if (Form.ShowDialog() == DialogResult.OK)
            {
                db.Sellers.Add(Form.Seller);
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private void SellerAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var form = new SellerForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                context.Sellers.Add(form.Seller);
                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        private void sellerAddToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            SellerForm sellerForm = new SellerForm();

            if (sellerForm.ShowDialog() == DialogResult.OK)
            {
                _dbContext.Sellers.Add(sellerForm.Seller);
                _dbContext.SaveChanges();
            }
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                Product product = _set.Find(id) as Product;

                if (product != null)
                {
                    ProductForm productForm = new ProductForm(product);

                    if (productForm.ShowDialog() == DialogResult.OK)
                    {
                        product = productForm.Product;
                        _dbContext.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Seller))
            {
                Seller seller = _set.Find(id) as Seller;

                if (seller != null)
                {
                    SellerForm sellerForm = new SellerForm(seller);

                    if (sellerForm.ShowDialog() == DialogResult.OK)
                    {
                        seller = sellerForm.Seller;
                        _dbContext.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Customer))
            {
                Customer customer = _set.Find(id) as Customer;

                if (customer != null)
                {
                    CustomerForm customerForm = new CustomerForm(customer);

                    if (customerForm.ShowDialog() == DialogResult.OK)
                    {
                        customer = customerForm.Customer;
                        _dbContext.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            var id = dataGridView1.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                //по идентификатору ищем продукт
                var product = set.Find(id) as Product;
                if (product != null)
                {
                    var form = new ProductForm(product);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        product = form.Product;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            if (typeof(T) == typeof(Seller))
            {
                //по идентификатору ищем продукт
                var seller = set.Find(id) as Seller;
                if (seller != null)
                {
                    var form = new SellerForm(seller);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        seller = form.Seller;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            if (typeof(T) == typeof(Customer))
            {
                //по идентификатору ищем продукт
                var customer = set.Find(id) as Customer;
                if (customer != null)
                {
                    var form = new CustomerForm(customer);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        customer = form.Customer;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
        }
Exemplo n.º 7
0
 private void ChangeButton_Click(object sender, EventArgs e)
 {
     try
     {
         var id = dataGridView.SelectedRows[0].Cells[0].Value;
         if (typeof(T) == typeof(Product))
         {
             var product = set.Find(id) as Product;
             if (product != null)
             {
                 var form = new ProductForm(product);
                 if (form.ShowDialog() == DialogResult.OK)
                 {
                     product = form.Product;
                     db.SaveChanges();
                 }
             }
         }
         else if (typeof(T) == typeof(Seller))
         {
             var seller = set.Find(id) as Seller;
             if (seller != null)
             {
                 var form = new SellerForm(seller);
                 if (form.ShowDialog() == DialogResult.OK)
                 {
                     seller = form.Seller;
                     db.SaveChanges();
                 }
             }
         }
         else if (typeof(T) == typeof(Customer))
         {
             var customer = set.Find(id) as Customer;
             if (customer != null)
             {
                 var form = new CustomerForm(customer);
                 if (form.ShowDialog() == DialogResult.OK)
                 {
                     customer = form.Customer;
                     db.SaveChanges();
                 }
             }
         }
         dataGridView.Refresh();
     }
     catch (ArgumentOutOfRangeException)
     {
         MessageBox.Show("Вы не выбрали строку!");
     }
 }
Exemplo n.º 8
0
        private void btnEdit_Click(object sender, System.EventArgs e)
        {
            var id = dataGridView1.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                var product = set.Find(id) as Product;

                if (product != null)
                {
                    var form = new ProductForm(product);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        product = form.Product;
                        context.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Seller))
            {
                var seller = set.Find(id) as Seller;

                if (seller != null)
                {
                    var form = new SellerForm(seller);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        seller = form.Seller;
                        context.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Customer))
            {
                var customer = set.Find(id) as Customer;

                if (customer != null)
                {
                    var form = new CustomerForm(customer);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        customer = form.Customer;
                        context.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView.SelectedRows.Count > 0)
            {
                int index = dataGridView.SelectedRows[0].Index;
                var id    = dataGridView.SelectedRows[0].Cells[0].Value;
                //int id = 0;
                //bool converted = Int32.TryParse(dataGridView[0, index].Value.ToString(), out id);

                if (typeof(T) == typeof(Product))
                {
                    var product = set.Find(id) as Product;
                    var form    = new ProductForm(product);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        product = form.Product;
                        db.SaveChanges();
                        dataGridView.Refresh();
                    }
                }
                else if (typeof(T) == typeof(Customer))
                {
                    var customer = db.Customers.Find(id);
                    var form     = new CustomerForm(customer);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        customer = form.Customer;
                        db.SaveChanges();
                        dataGridView.Refresh();
                    }
                }
                else if (typeof(T) == typeof(Seller))
                {
                    var seller = db.Sellers.Find(id);
                    var form   = new SellerForm(seller);

                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        seller = form.Seller;
                        db.SaveChanges();
                        dataGridView.Refresh();
                    }
                }
            }
        }
Exemplo n.º 10
0
        private void Button2_Click(object sender, EventArgs e)
        {
            var id = dataGridView1.SelectedRows[0].Cells[0].Value;

            if (typeof(T) == typeof(Product))
            {
                var p = set.Find(id) as Product;
                if (p != null)
                {
                    var form = new ProductForm(p);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        p = form.Product;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Seller))
            {
                var s = set.Find(id) as Seller;
                if (s != null)
                {
                    var form = new SellerForm(s);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        s = form.Seller;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
            else if (typeof(T) == typeof(Customer))
            {
                var c = set.Find(id) as Customer;
                if (c != null)
                {
                    var form = new CustomerForm(c);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        c = form.Customer;
                        db.SaveChanges();
                        dataGridView1.Update();
                    }
                }
            }
        }