public bool InsertProduct(Product product) { try { contextDB.Products.Add(product); contextDB.SaveChanges(); return true; } catch { return false; } }
public bool UpdateProduct(Product product) { try { Product existing = contextDB.Products.Find(product.ProductId); ((IObjectContextAdapter)contextDB).ObjectContext.Detach(existing); contextDB.Entry(product).State = EntityState.Modified; contextDB.SaveChanges(); return true; } catch { return false; } }
private void gvBills_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { pictureBox1.Enabled = false; pictureBox2.Enabled = false; btnEdit.Enabled = true; int billsID = int.Parse(gvBills.Rows[e.RowIndex].Cells["colBillsID"].Value.ToString()); Bill bills = new Bill(); BLLBills bllBills = new BLLBills(); bills = bllBills.GetBillsById(billsID); if (gvBills.Columns[e.ColumnIndex].Name == "colBillsDeleted") { if (MessageBox.Show("Are you sure to delete: " + gvBills.Rows[e.RowIndex].Cells["colBillsId"].Value.ToString(), "Message", MessageBoxButtons.OKCancel) == DialogResult.OK) { bllBills.Deleted(bills); LoadGridBills(); gvProductsToBills.Rows.Clear(); return; } } gvProductsToBills.Rows.Clear(); foreach (BillDetail billsDetail in bills.BillDetails) { Product product = new Product(); BLLProduct productBLL = new BLLProduct(); product = productBLL.GetProductById(billsDetail.ProductId); gvProductsToBills.Rows.Add(product.ProductId, product.ProductName, billsDetail.RealPrice, billsDetail.Amounts, billsDetail.Sum, Properties.Resources.DeleteRed); } lbTotal.Text = bills.Total.ToString(); } }
private void gvProducts_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { int productId = int.Parse(gvProducts.Rows[e.RowIndex].Cells["colProductId"].Value.ToString()); int rowIndex = -1; Product product = new Product(); BLLProduct productBLL = new BLLProduct(); product = productBLL.GetProductById(productId); if (TestExistsProductInBills(gvProductsToBills, productId, ref rowIndex)) { gvProductsToBills.Rows[rowIndex].Cells["colAmounts"].Value = int.Parse(gvProductsToBills.Rows[rowIndex].Cells["colAmounts"].Value.ToString()) + 1; gvProductsToBills.Rows[rowIndex].Cells["colTotal"].Value = float.Parse(gvProductsToBills.Rows[rowIndex].Cells["colTotal"].Value.ToString()) + product.OriginalPrice; } else { gvProductsToBills.Rows.Add(product.ProductId, product.ProductName, product.OriginalPrice, 1, product.OriginalPrice, Properties.Resources.DeleteRed); } lbTotal.Text = SumTotal().ToString(); } }
private void gvProducts_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { int productId = int.Parse(gvProducts.Rows[e.RowIndex].Cells["colProductId"].Value.ToString()); Product product = new Product(); BLLProduct productBLL = new BLLProduct(); product = productBLL.GetProductById(productId); lbName.Text = product.ProductName; lbPrice.Text = product.OriginalPrice.ToString(); lbUnit.Text = product.ProductUnit; lbDescription.Text = product.Description; } }
public bool UpdateProduct(Product product) { return productDAL.UpdateProduct(product); }
public bool InserProduct(Product product) { return productDAL.InsertProduct(product); }
public bool DeleteProduct(Product product) { return productDAL.DeleteProduct(product); }
private void gvproductlist_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewImageColumn && e.RowIndex >= 0) { DialogResult result = MessageBox.Show("Do you want to delete ?","Warning", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { try { Product product = new Product { ProductId = productId, ProductName = txtproductname.Text, OriginalPrice = double.Parse(txtprice.Text), ProductUnit = txtunit.Text, CategoryId = int.Parse(cbocategory.SelectedValue.ToString()), Description = txtdescription.Text }; ProductBLL.DeleteProduct(product); MessageBox.Show("Delete Successful", "Warning"); } catch (Exception ex) { MessageBox.Show("Delete Fail", "Warning"); } } LoadProductList(); Cleartextbox(); } }
private void pictureBox2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtproductname.Text)|| string.IsNullOrEmpty(txtprice.Text)) { MessageBox.Show("Information Required", "Warning"); } else { try { Product product = new Product { ProductId = productId, ProductName = txtproductname.Text, OriginalPrice = double.Parse(txtprice.Text), ProductUnit = txtunit.Text, CategoryId = int.Parse(cbocategory.SelectedValue.ToString()), Description = txtdescription.Text }; ProductBLL.UpdateProduct(product); MessageBox.Show("UPdate Successful", "Warning"); Cleartextbox(); pictureBox1.Enabled = true; } catch (Exception ex) { MessageBox.Show("Update Fail", "Warning"); } } LoadProductList(); }