private void btnAddProduct_Click(object sender, EventArgs e) { NorthwindService.Product pro = new NorthwindService.Product(); pro.CategoryID = int.Parse(cbCategory.SelectedValue.ToString()); pro.ProductName = txtProductName.Text; pro.QuantityPerUnit = txtProductQuantity.Text; pro.UnitPrice = decimal.Parse(txtPrice.Text); pro.UnitsInStock = int.Parse(txtInStock.Text); pro.UnitsOnOrder = int.Parse(txtOnOrder.Text); pro.ReorderLevel = int.Parse(txtReorder.Text); pro.Discontinued = ckbDiscontinue.Checked; int a = test.AddProduct(pro); if (a == 1) { MessageBox.Show("Add successful !", "Add Category", MessageBoxButtons.OK); } else { MessageBox.Show("Add failed !", "Add Category", MessageBoxButtons.OK); } }
private void dtgProduct_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { int CurrentIndex = dtgProduct.CurrentCell.RowIndex; NorthwindService.Product _product = new NorthwindService.Product(); _product.CategoryID = Convert.ToInt32(dtgProduct.Rows[CurrentIndex].Cells[0].Value.ToString()); _product.ProductID = Convert.ToInt32(dtgProduct.Rows[CurrentIndex].Cells[1].Value.ToString()); _product.ProductName = Convert.ToString(dtgProduct.Rows[CurrentIndex].Cells[2].Value.ToString()); _product.QuantityPerUnit = Convert.ToString(dtgProduct.Rows[CurrentIndex].Cells[3].Value.ToString()); _product.ReorderLevel = Convert.ToInt16(dtgProduct.Rows[CurrentIndex].Cells[4].Value.ToString()); _product.UnitPrice = Convert.ToDecimal(dtgProduct.Rows[CurrentIndex].Cells[5].Value.ToString()); _product.UnitsInStock = Convert.ToInt16(dtgProduct.Rows[CurrentIndex].Cells[6].Value.ToString()); _product.UnitsOnOrder = Convert.ToInt16(dtgProduct.Rows[CurrentIndex].Cells[7].Value.ToString()); test.UpdateProduct(_product); }