private void EditProduct(Product product) { var form = new ProductDetailForm(product); var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } //Update the product form.Product.Id = product.Id; _database.Update(form.Product, out var message); if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message); } RefreshUI(); }
private void OnProductEdit(object sender, EventArgs e) { if (_product == null) { return; } var form = new ProductDetailForm(); form.Text = "Add Product"; //form.Product = _product; //Show form modally var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } }
private void OnProductEdit(object sender, EventArgs e) { if (_product == null) { return; } var form = new ProductDetailForm(_product); //form.Product = _product; //Show form modally var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } //"Editing" the product _product = form.Product; }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } try { //Save product _database.Add(child.Product); UpdateList(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK); } }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors //Save product try { _database.Add(child.Product); } catch (Exception ex) { DisplayError(ex); } UpdateList(); }
private void OnProductAdd(object sender, EventArgs e) { //Make sure there is room left // var index = FindAvailableElement(); // if (index < 0) // { // MessageBox.Show("No more products available."); // return; // }; var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Save product // _database.Add = child.Product; }
private void OnProductAdd(object sender, EventArgs e) { try { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product _database.Add(child.Product); UpdateList(); } catch (DataException) { ErrorMessage("Database failure!", "Add Failed!"); } catch (Exception ex) { ErrorMessage(ex.Message, "Add failed!"); } }
private void OnProductAdd(object sender, EventArgs e) { var form = new ProductDetailForm("Add Product"); //form.Text = "Add Product"; //modal form if (form.ShowDialog() != DialogResult.OK) { return; } //add product, add try catch try { _database.Add(form.Product); } catch (Exception ex) { MessageBox.Show(ex.Message); } RefreshUI(); }
private void OnProductEdit(object sender, EventArgs e) { if (_product == null) { MessageBox.Show(this, "There is no product to edit.", "Edit Product", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var form = new ProductDetailForm(_product); //Show form modally var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } //"Editing" the product _product = form.Product; }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Update(child.Product); } catch (Exception ex) { DisplayError(ex, "Update Failed"); }; UpdateList(); }
private void OnProductAdd(object sender, EventArgs e) { var button = sender as ToolStripMenuItem; var form = new ProductDetailForm(); //form.Text = "Add Product"; //Show form modally var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } //add to database _database.Add(form.Product, out var message); if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message); } }
private void OnProductEdit(object sender, EventArgs e) { //Are there any products? //var index = FindFirstProduct(); //if (index < 0) // { // MessageBox.Show("No products avaialble."); // return; //}; var product = _database.Get(); var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Save product // _database.Update = child.Product; }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Add(child.Product); UpdateList(); } catch { MessageBox.Show(this, "Cannot Add. Perhaps duplicate entry.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } try { //Save product _database.Update(child.Product); UpdateList(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK); } }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors //try //{ //Save product _database.Update(product.Id, child.Product); //} catch (Exception ex) //{ // DisplayError(ex); //}; UpdateList(); }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors try { _database.Update(child.Product); } catch (Exception ex) { MessageBox.Show("Product could not be updated", ex.ToString()); }; //Save product UpdateList(); }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //*** //Save product try { _database.Update(child.Product); } catch (Exception ex) { MessageBox.Show(ex.Message); }; UpdateList(); }
private void EditProduct(Product product) { var form = new ProductDetailForm(product); //Show form modally var result = form.ShowDialog(this); //show child form (ProductRetailForm), return back dailog result if (result != DialogResult.OK) //use dialog result from child form { return; } //Add to database form.Product.Id = product.Id; _database.Update(form.Product, out var message); if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message); } RefreshUI(); }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors //Save product try { _database.Update(child.Product); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; UpdateList(); }
private void EditProduct(Product product) { var child = new ProductDetailForm("Edit Product"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors try { _database.Update(child.Product); }catch (Exception ex) { DisplayError("Update Failed", ex.Message); } //Save product //_database.Update(child.Product); UpdateList(); }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //TODO: Handle errors try { _database.Add(child.Product); } catch (Exception ex) { MessageBox.Show(ex.ToString()); }; //Save product UpdateList(); }
private void OnProductEdit(object sender, EventArgs e) { //dont show form to edit if theres nothing to edit if (_product == null) { return; } var form = new ProductDetailForm(_product); //form.Product = _product; //Show form modally var result = form.ShowDialog(this); //show child form (ProductRetailForm), return back dailog result if (result != DialogResult.OK) //use dialog result from child form { return; } //"Editing" the product _product = form.Product; }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Update(child.Product); UpdateList(); } catch { MessageBox.Show(this, $"Cannot update '{product.Name}'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
//Helper method to handle editing products private void EditProduct(Product product) { var form = new ProductDetailForm(product); var result = form.ShowDialog(this); if (result != DialogResult.OK) { return; } //Update the product form.Product.Id = product.Id; try { _database.Update(form.Product); } catch (Exception e) { MessageBox.Show(e.Message); }; RefreshUI(); }
private void EditProduct(Product product) { var child = new ProductDetailForm("Product Details"); child.Product = product; if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Update(child.Product); UpdateList(); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ValidationException ex) { MessageBox.Show(ex.Message, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show("Save failed" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }; }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Add(child.Product); } catch (ArgumentNullException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (DuplicateNameException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateList(); }
private void OnProductAdd(object sender, EventArgs e) { var button = sender as ToolStripMenuItem; var form = new ProductDetailForm("Add Product"); //Show form modally var result = form.ShowDialog(this); //show child form (ProductRetailForm), return back dailog result if (result != DialogResult.OK) //use dialog result from child form { return; } //Add to database _database.Add(form.Product, out var message); if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message); } RefreshUI(); }
private void OnProductAdd(object sender, EventArgs e) { var form = new ProductDetailForm(); do { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } try { AddProduct(form.Product); } catch (InvalidOperationException ex) { MessageBox.Show(this, ex.Message, "Invalid Operation", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentException ex) { MessageBox.Show(this, ex.Message, "Bad Argument", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception) { MessageBox.Show(this, "Failed", "Add Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } //Save product _database.Add(child.Product); UpdateList(); } while (true); }
private void OnProductAdd(object sender, EventArgs e) { var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } if (IsProductDuplicate(child.Product)) { return; } //Handle errors try { //Save product _database.Add(child.Product); UpdateList(); } catch (InvalidOperationException ex) { MessageBox.Show(this, ex.Message, "Invalid Operation", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (ArgumentException ex) { MessageBox.Show(this, ex.Message, "Bad Argument", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) // Equivalent to catch { //Handle errors MessageBox.Show(this, ex.Message, "Add Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
//Menus //private void OnFileExit( object sender, EventArgs e ) //{ // Close(); //} private void OnProductAdd(object sender, EventArgs e) { //_database.Add(null); var child = new ProductDetailForm("Product Details"); if (child.ShowDialog(this) != DialogResult.OK) { return; } //Save product try { _database.Add(child.Product); } catch (ValidationException ex) { DisplayError(ex, "Validation Failed"); } catch (Exception ex) { DisplayError(ex, "Add Failed"); }; UpdateList(); }