예제 #1
0
        private void productAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProductForm productForm = new ProductForm();

            if (productForm.ShowDialog() == DialogResult.OK)
            {
                _dbContext.Products.Add(productForm.Product);
                _dbContext.SaveChanges();
            }
        }
예제 #2
0
        private void ProductAddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var Form = new ProductForm();

            if (Form.ShowDialog() == DialogResult.OK)
            {
                db.Products.Add(Form.Product);
                db.SaveChanges();
            }
        }
예제 #3
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();
                    }
                }
            }
        }
예제 #4
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();
                    }
                }
            }
        }
예제 #5
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("Вы не выбрали строку!");
     }
 }
예제 #6
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();
                    }
                }
            }
        }
예제 #7
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();
                    }
                }
            }
        }
예제 #8
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();
                    }
                }
            }
        }
예제 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (typeof(T) == typeof(Product))
            {
                ProductForm productForm = new ProductForm();
                //ProductForm productForm = new ProductForm();

                //if (productForm.ShowDialog() == DialogResult.OK)
                //{
                //    db.Products.Add(productForm.Product);
                //    db.SaveChanges();
                //}
            }
            else if (typeof(T) == typeof(Seller))
            {
            }
            else if (typeof(T) == typeof(Customer))
            {
            }
        }