Implement Inventory Methods; Add static Inventory object to static Program class

This commit is contained in:
2025-05-14 22:08:02 -05:00
parent 62eb1deeda
commit 179e8e13f9
3 changed files with 71 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.ComponentModel;
namespace C968Project;
@@ -7,32 +8,87 @@ public class Inventory
public BindingList<Product> Products { get; set; }
public BindingList<Part> 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;
}
}