Added confimation dialogues for deleting parts/products; Finished implementing Product class methods; Propogating part modifications to associated products; Stopped deleting of items if there is an association;
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System.ComponentModel;
|
|
|
|
namespace C968Project;
|
|
|
|
public class Product
|
|
{
|
|
public BindingList<Part> AssociatedParts { get; set; } = new();
|
|
public int ProductId { get; set; }
|
|
public string Name { get; set; }
|
|
public float Price { get; set; }
|
|
public int InStock { get; set; }
|
|
public int Min { get; set; }
|
|
public int Max { get; set; }
|
|
|
|
public void AddAssociatedPart(Part part)
|
|
{
|
|
if (AssociatedParts.Contains(part))
|
|
{
|
|
MessageBox.Show($"Product {Name} already has an association with part {part.Name}", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
AssociatedParts.Add(part);
|
|
}
|
|
|
|
public bool RemoveAssociatedPart(int partIndex)
|
|
{
|
|
var part = LookupAssociatedPart(partIndex);
|
|
|
|
if (part is null)
|
|
{
|
|
MessageBox.Show($"An error occured while trying to locate the part at index {partIndex}.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return false;
|
|
}
|
|
|
|
AssociatedParts.Remove(part);
|
|
return true;
|
|
}
|
|
|
|
public Part? LookupAssociatedPart(int partIndex)
|
|
{
|
|
if (partIndex > AssociatedParts.Count)
|
|
{
|
|
MessageBox.Show($"Error trying to locate part at index {partIndex}. Out of bounds.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return null;
|
|
}
|
|
|
|
return AssociatedParts[partIndex];
|
|
}
|
|
} |