using System; using System.ComponentModel; namespace C968Project; public class Inventory { public BindingList Products { get; set; } = new(); public BindingList Parts { get; set; } = new(); public void AddProduct(Product product) { if (!Products.Contains(product)) { Products.Add(product); return; } MessageBox.Show($"Identical product already exists", "Error", MessageBoxButtons.OK); } public bool RemoveProduct(int productIndex) { if (productIndex > Products.Count) { MessageBox.Show($"Error occured when trying to delete product with index of {productIndex}. Out of bounds.", "Error", MessageBoxButtons.OK); return false; } Products.RemoveAt(productIndex); return true; } public Product? LookupProduct(int productIndex) { if (productIndex > Products.Count) { MessageBox.Show($"Error occured when trying to find product with index of {productIndex}. Out of bounds.", "Error", MessageBoxButtons.OK); return null; } return Products[productIndex]; } public void UpdateProduct(int index, Product newProduct) { if (index > Products.Count) { MessageBox.Show($"Error occured when trying to update product with index of {index}. Out of bounds.", "Error", MessageBoxButtons.OK); return; } Products[index] = newProduct; } public void AddPart(Part part) { if (!Parts.Contains(part)) { Parts.Add(part); return; } MessageBox.Show($"Identical part already exists", "Error", MessageBoxButtons.OK); } public bool DeletePart(Part part) { return Parts.Remove(part); } public Part LookupPart(int partIndex) { if (partIndex > Parts.Count) { MessageBox.Show($"Error occured when trying to find part with index of {partIndex}. Out of bounds.", "Error", MessageBoxButtons.OK); return null; } return Parts[partIndex]; } public void UpdatePart(int index, Part newPart) { if (index > Parts.Count) { MessageBox.Show($"Error occured when trying to update part with index of {index}. Out of bounds.", "Error", MessageBoxButtons.OK); return; } Parts[index] = newPart; } public void PropogatePartModificationToAssociatedProducts(Part oldPart, Part newPart) { foreach (var product in Products) { if (product.AssociatedParts.Contains(oldPart)) { product.RemoveAssociatedPart(product.AssociatedParts.IndexOf(oldPart)); product.AddAssociatedPart(newPart); } } } }