private void btnDelete_Click(object sender, EventArgs e) { //Delete a product int productID = Convert.ToInt32(tbID.Text); FLOWERPRO product = new FLOWERPRO(); try { //Show a confirmation message before delete if (MessageBox.Show("Are you sure?", "DELETE", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (product.deleteProducts(productID)) { MessageBox.Show("FlowerProducts Deleted", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Information); //clear fields tbID.Text = ""; cbCat.Text = ""; tbName.Text = ""; tbDes.Text = ""; tbPrice.Text = ""; pbFlower.Image = null; } else { MessageBox.Show("FlowerProduct is not Deleted", "DELETE", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Delete", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnUpdate_Click(object sender, EventArgs e) { //update the selected product FLOWERPRO product = new FLOWERPRO(); int id = Convert.ToInt32(tbID.Text); string category = cbCat.Text; string productName = tbName.Text; string proPrice = tbPrice.Text; string description = tbDes.Text; try { if (verifFields("add")) { //Get Image MemoryStream image = new MemoryStream(); pbFlower.Image.Save(image, pbFlower.Image.RawFormat); if (product.editFlowerProducts(id, category, productName, proPrice, description, image)) { MessageBox.Show("The flower product details are updated", "UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Something went wrong", "UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Required Fields", "add", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "UPDATE", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Button for add new product private void btnAdd_Click(object sender, EventArgs e) { FLOWERPRO product = new FLOWERPRO(); string category = cbCat.Text; string productName = tbName.Text; int proPrice = Convert.ToInt32(tbPrice.Text); string description = tbDes.Text; try { if (verifFields("add")) { //Get Image MemoryStream image = new MemoryStream(); pbFlower.Image.Save(image, pbFlower.Image.RawFormat); if (product.insertProduct(category, productName, proPrice, description, image)) { MessageBox.Show("New Product is added", "ADD", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Something went wrong", "ADD", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Required Fields", "add", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ADD", MessageBoxButtons.OK, MessageBoxIcon.Error); } }