Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1())
                {
                    Product product = new Product()
                    {
                        prodName = txtProdName.Text,
                        prodCode = txtProdCode.Text,
                        prodPrice = decimal.Parse(txtProdPrice.Text)

                    };

                    context.Products.Add(product);
                    context.SaveChanges();
                    this.Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("You must enter a value for each item");
            }
        }
Exemplo n.º 2
0
 private void btnSearchProducts_Click(object sender, EventArgs e)
 {
     if (txtSearchProducts.Text != "")
     {
         using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1())
         {
             Product product = new Product();
             string userSelected = txtSearchProducts.Text;
             var data = from b in context.Products where b.prodName.Contains(userSelected) select b;
             dtgProducts.DataSource = data.ToList();
         }
     }
 }
Exemplo n.º 3
0
        private void btnEditProducts_Click(object sender, EventArgs e)
        {
            using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1())
            {
                Product product = new Product();

                foreach (DataGridViewRow row in this.dtgProducts.SelectedRows)
                {
                    Product prod = row.DataBoundItem as Product;
                    if (prod != null)
                    {

                        frmEditProduct editProd = new frmEditProduct(prod.Id);

                        editProd.ShowDialog();
                    }
                }

                loadProductDatagrid();
            }
        }
Exemplo n.º 4
0
        private void btnDeleteProduct_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Are you sure you want to delete this product?",
                "Delete product", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dialog == DialogResult.Yes)
            {
                using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1())
                {
                    Product product = new Product();

                    foreach (DataGridViewRow row in this.dtgProducts.SelectedRows)
                    {
                        Product prod = row.DataBoundItem as Product;
                        if (prod != null)
                        {
                            Product prod_to_delete = context.Products.Single(c => c.Id == prod.Id);
                            context.Products.Remove(prod_to_delete);
                        }
                    }

                    context.SaveChanges();
                    loadProductDatagrid();
                }
            }
        }