Exemplo n.º 1
0
        private void dgvProducts_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = int.Parse(dgvProducts.CurrentRow.Cells[0].Value.ToString());

            if (e.ColumnIndex == 5)
            {
                if (MessageBox.Show($"¿Seguro que desea eliminar '{dgvProducts.CurrentRow.Cells[1].Value}'?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    Product model = db.Products.Where(p => p.ProductID == id).FirstOrDefault();
                    var     entry = db.Entry(model);
                    if (entry.State == EntityState.Unchanged)
                    {
                        db.Products.Remove(model);
                        db.SaveChanges();
                        Filldgv();
                    }
                }
            }

            if (e.ColumnIndex == 4)
            {
                Product model = db.Products.Where(p => p.ProductID == id).FirstOrDefault();
                Visible = false;
                frmAddProduct frmAddProduct = new frmAddProduct(model);
                frmAddProduct.ShowDialog();
                Filldgv();
                Visible = true;
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Visible = false;
            frmAddProduct frmAddProduct = new frmAddProduct(null);

            frmAddProduct.ShowDialog();
            Filldgv();
            Visible = true;
        }