private void btnAdd_Click(object sender, EventArgs e) { //create second form frmAddModifyProduct addModifyProduct = new frmAddModifyProduct(); // setting isAdd to true to pass it to the second form addModifyProduct.isAdd = true; addModifyProduct.product = null; //no package //show it modal DialogResult result = addModifyProduct.ShowDialog();//accept returns ok //if dialogresult is ok, save package, and display items in list view if (result == DialogResult.OK) { selectedProduct = addModifyProduct.product; selectedProductsIds = addModifyProduct.selectedProductsIds; try { var newProduct = context.Products.Add(selectedProduct); context.SaveChanges(); //adding associated products DisplayLVProducts(); } catch (DbUpdateException ex) { HandleDataError(ex); } catch (Exception ex) { HandleGeneralError(ex); } } }
private void btnModify_Click(object sender, EventArgs e) { //create second form frmAddModifyProduct secondForm = new frmAddModifyProduct(); // setting isAdd to false to pass it to the second form secondForm.isAdd = false; /*retrieving the selected product * selected_package code is retrieved from the lvPackages_ItemSelectionChanged * event handler*/ secondForm.product = context.Products.Find(selected_productID); //show it modal DialogResult result = secondForm.ShowDialog();//accept returns ok //if dialogresult is ok, save product, and display items in list view if (result == DialogResult.OK) { selectedProduct = secondForm.product; try { context.SaveChanges(); DisplayLVProducts(); } catch (DbUpdateException ex) { HandleDataError(ex); } catch (Exception ex) { HandleGeneralError(ex); } } ManageControls(false); }