private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); this.PutProductData(product); try { // Calls the AddProduct method of the ProductDB class. // if false, displays a message to user, if true, adds. if (!ProductDB.AddProduct(product)) { MessageBox.Show("Another product with the same" + " code already exists.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Product newProduct = new Product(); newProduct.Code = product.Code; this.PutProductData(newProduct); try { // Calls the UpdateProduct method of the ProductDB class. // if false, displays a message to user, if true, updates. if (!ProductDB.UpdateProduct(product, newProduct)) { MessageBox.Show("Another user has updated or " + "deleted that product.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); this.PutProductData(product); try { // Add code here to call the AddProduct method of the ProductDB class. if (ProductDB.AddProduct(product)) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Cannot add product.", "Database Error"); this.DialogResult = DialogResult.Retry; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Product newProduct = new Product(); this.PutProductData(newProduct); try { // Add code here to call the UpdateProduct method of the ProductDB class. if (!ProductDB.UpdateProduct(newProduct)) { MessageBox.Show("Another user has updated or " + "deleted that product.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); this.PutProductData(product); try { // Add code here to call the AddProduct method of the ProductDB class. bool result = ProductDB.AddProduct(product); if (result) { DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.Retry; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Product newProduct = new Product(); this.PutProductData(newProduct); try { // Add code here to call the UpdateProduct method of the ProductDB class. bool result = ProductDB.UpdateProduct(product, newProduct); if (result) { product = newProduct; DialogResult = DialogResult.OK; } else { MessageBox.Show("Error, another user has updated or deleted the product"); DialogResult = DialogResult.Retry; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void btnAccept_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); this.PutProductData(product); try { if (!ProductDB.AddProduct(product)) { MessageBox.Show("A product with that code already exists.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } else { Product newProduct = new Product(); this.PutProductData(newProduct); try { if (!ProductDB.UpdateProduct(product, newProduct)) { MessageBox.Show("Another user has updated or " + "deleted that product.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } }
private void AcceptButton_Click(object sender, EventArgs e) { if (IsValidData()) { if (addProduct) { product = new Product(); PutProductData(product); if (ProductDB.AddProduct(product)) { this.DialogResult = DialogResult.OK; } else { this.DialogResult = DialogResult.Abort; } } else { Product newProduct = new Product(); newProduct.ProductCode = product.ProductCode; this.PutProductData(newProduct); try { if (!ProductDB.UpdateProduct(product, newProduct)) { MessageBox.Show("Another user has updated or deleted that customer.", "Database Error"); this.DialogResult = DialogResult.Retry; } else { product = newProduct; this.DialogResult = DialogResult.OK; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }