Exemplo n.º 1
0
        public static bool Delete(Product entity)
        {
            SqlCommand command = new SqlCommand("DeleteProduct", Helper.Connection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@id", entity.ProductID);

            return Helper.MyExecuteNonQuery(command);
        }
Exemplo n.º 2
0
        public static bool Add(Product entity)
        {
            SqlCommand command = new SqlCommand("AddProduct", Helper.Connection);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@n", entity.ProductName);
            command.Parameters.AddWithValue("@p", entity.UnitPrice);
            command.Parameters.AddWithValue("@s", entity.UnitsInStock);

            return Helper.MyExecuteNonQuery(command);
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0) return;

            Product deleted = new Product();
            deleted.ProductID = (int)dataGridView1.CurrentRow.Cells["ProductID"].Value;
            if (!Products.Delete(deleted))
                MessageBox.Show("Ürün Silenemedi");

            dataGridView1.DataSource = Products.getList();
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Product updated = new Product();
            updated.ProductID = (int)txtProductName.Tag;
            updated.ProductName = txtProductName.Text;
            updated.UnitPrice = nudPrice.Value;
            updated.UnitsInStock = (short)nudPrice.Value;
            if (!Products.Update(updated))
                MessageBox.Show("Ürün Güncellenemedi");

            dataGridView1.DataSource = Products.getList();
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Product entity = new Product();
            entity.ProductName = txtProductName.Text;
            entity.UnitPrice = nudPrice.Value;
            entity.UnitsInStock = (short)nudStock.Value;
            if (!Products.Add(entity))
                MessageBox.Show("Ürün Eklenemedi");

            //ekledikten sonra listelemeyi yeniden yapıyoruz.
            dataGridView1.DataSource = Products.getList();
        }