diff --git a/C968Project/Inventory.cs b/C968Project/Inventory.cs index a8a18c9..a3c959e 100644 --- a/C968Project/Inventory.cs +++ b/C968Project/Inventory.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel; namespace C968Project; @@ -7,32 +8,87 @@ public class Inventory public BindingList Products { get; set; } public BindingList Parts { get; set; } - public void AddProduct(Product product){} + 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) { - return false; + 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 partIndex) + public Product? LookupProduct(int productIndex) { - return null; + 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 UpdateProduct(int index, Product newProduct){} - public void AddPart(Part part){} + 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 false; + return Parts.Remove(part); } public Part LookupPart(int partIndex) { - return null; + 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){} + 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; + } } \ No newline at end of file diff --git a/C968Project/Program.cs b/C968Project/Program.cs index b4a9560..9207d58 100644 --- a/C968Project/Program.cs +++ b/C968Project/Program.cs @@ -4,6 +4,9 @@ namespace C968Project; static class Program { + + public static Inventory Inventory = new(); + /// /// The main entry point for the application. /// diff --git a/C968Project/Views/MainScreen.cs b/C968Project/Views/MainScreen.cs index 620e748..8ca5f03 100644 --- a/C968Project/Views/MainScreen.cs +++ b/C968Project/Views/MainScreen.cs @@ -5,5 +5,8 @@ public partial class MainScreen : Form public MainScreen() { InitializeComponent(); + + productsDataGridView.DataSource = Program.Inventory.Products; + partsDataGridView.DataSource = Program.Inventory.Parts; } } \ No newline at end of file