//SaveProduct private void picSaveAddProdDet_Click(object sender, EventArgs e) { MyProduct myProduct = new MyProduct(); bool ok = true; errP.Clear(); try { myProduct.ProductNo = lblProductNumberDisplay.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblProductNumberDisplay, MyEx.toString()); } try { myProduct.ProductTypeCode = cbTypeCode.SelectedValue.ToString(); } catch (MyException MyEx) { ok = false; errP.SetError(cbTypeCode, MyEx.toString()); } try { myProduct.ProductDesc = txtProdDesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtProdDesc, MyEx.toString()); } try { myProduct.CostPrice = txtCostPrice.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCostPrice, MyEx.toString()); } try { myProduct.QtyInStock = txtQTY.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtQTY, MyEx.toString()); } try { myProduct.PackSize = txtPackSize.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPackSize, MyEx.toString()); } try { myProduct.ReOrderLvl = txtReOrder.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtReOrder, MyEx.toString()); } try { myProduct.SupplierID = cbSuppID.SelectedValue.ToString(); } catch (MyException MyEx) { ok = false; errP.SetError(cbSuppID, MyEx.toString()); } //Try Adding try { if (ok) { drProduct = dsBelfray.Tables["Product"].NewRow(); drProduct["productNumber"] = myProduct.ProductNo; drProduct["productTypeCode"] = myProduct.ProductTypeCode; drProduct["productDesc"] = myProduct.ProductDesc; drProduct["costPrice"] = myProduct.CostPrice; drProduct["qtyInStock"] = myProduct.QtyInStock; drProduct["packSize"] = myProduct.PackSize; drProduct["reorderLvl"] = myProduct.ReOrderLvl; drProduct["supplierID"] = myProduct.SupplierID; dsBelfray.Tables["Product"].Rows.Add(drProduct); daProduct.Update(dsBelfray, "Product"); MessageBox.Show("Product Added"); if (MessageBox.Show("Do you wish to add another product?", "AddProduct", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { formLoad = true; clearAddPanel(); getProdNum(dsBelfray.Tables["Product"].Rows.Count); string s = drProduct["productNumber"].ToString(); string s1 = "PRD" + (Convert.ToInt32(s.Replace("PRD", "")) + 1).ToString().PadLeft(5, '0'); lblProductNumberDisplay.Text = s1; } else { this.Close(); } } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }
private void PicSaveProductEdit_Click(object sender, EventArgs e) { MyProduct myProduct = new MyProduct(); bool ok = true; errP.Clear(); try { myProduct.ProductNo = lblProductNumberDisplay.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(lblProductNumberDisplay, MyEx.toString()); } try { myProduct.ProductTypeCode = cbTypeCode.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cbTypeCode, MyEx.toString()); } try { myProduct.ProductDesc = txtProdDesc.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtProdDesc, MyEx.toString()); } try { myProduct.CostPrice = txtCostPrice.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtCostPrice, MyEx.toString()); } try { myProduct.QtyInStock = txtQTY.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtQTY, MyEx.toString()); } try { myProduct.PackSize = txtPackSize.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtPackSize, MyEx.toString()); } try { myProduct.ReOrderLvl = txtReOrder.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(txtReOrder, MyEx.toString()); } try { myProduct.SupplierID = cbSuppID.Text.Trim(); } catch (MyException MyEx) { ok = false; errP.SetError(cbSuppID, MyEx.toString()); } //try edit try { if (ok) { drProduct.BeginEdit(); drProduct["productNumber"] = myProduct.ProductNo; drProduct["productTypeCode"] = myProduct.ProductTypeCode; drProduct["productDesc"] = myProduct.ProductDesc; drProduct["costPrice"] = myProduct.CostPrice; drProduct["qtyInStock"] = myProduct.QtyInStock; drProduct["packSize"] = myProduct.PackSize; drProduct["reorderLvl"] = myProduct.ReOrderLvl; drProduct["supplierID"] = myProduct.SupplierID; drProduct.EndEdit(); daProduct.Update(dsBelfray, "Product"); MessageBox.Show("Product Details Edited"); } } catch (Exception ex) { MessageBox.Show("" + ex.TargetSite + "", ex.Message + "Error!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); } }