/// <summary> /// Adds a product with the category White Wood. /// </summary> /// <param name="product"></param> private void AddProductToDatabase(Product product) { try { product.Category.Add(ProductDb.GetCategory(WhiteWood)); if (!ProductDb.CheckForExistingProduct(product)) { ProductDb.Add(product); ClearTxtBoxesAndCheckBoxes(); messageLbl.Text = $"{product.Height} x {product.Width} x {product.Length} added successfully"; } else { messageLbl.Text = "Product already exists in database"; } } catch (SqlException) { messageLbl.Text = "Failed to add Product"; } }
/// <summary> /// Adds a product with multiple categories. /// </summary> /// <param name="p"></param> /// <param name="treatmentLevel"></param> /// <param name="treatmentType"></param> private void AddProductToDatabase(Product p, int treatmentLevel, int treatmentType) { try { p.Category.Add(ProductDb.GetCategory(treatmentLevel)); p.Category.Add(ProductDb.GetCategory(treatmentType)); if (!ProductDb.CheckForExistingProduct(p)) { ProductDb.Add(p); ClearTxtBoxesAndCheckBoxes(); messageLbl.Text = $"{p.Height} x {p.Width} x {p.Length} added successfully"; } else { messageLbl.Text = "Product already exists in database"; } } catch (SqlException) { messageLbl.Text = "Failed to add Product"; } }
/// <summary> /// Button to create an Invoice. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CreateInvoiceBtn_Click(object sender, EventArgs e) { Customer customer = (Customer)customerComboBox1.SelectedItem; if (customer != null) { Invoice invoice = new Invoice(); invoice.Customers.Add(customer); try { ProductDb.Add(invoice); messageLbl.Text = "Invoice Created"; } catch (SqlException) { messageLbl.Text = "Failed to create invoice"; } } else { MessageBox.Show("No customer selected", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }