Skip to content

Instantly share code, notes, and snippets.

@noahhaasis
Created February 9, 2021 12:25
Show Gist options
  • Save noahhaasis/d45d83ee2b547c8848dd109acc22eb65 to your computer and use it in GitHub Desktop.
Save noahhaasis/d45d83ee2b547c8848dd109acc22eb65 to your computer and use it in GitHub Desktop.
Prog 2 Klausur Aufgabe 4
using System;
using System.Collections.Generic;
namespace Aufgabe4
{
partial class WarehouseMmgt
{
private List<Item> specialList;
public delegate void WM_InventoryCheck(Item i, ref bool addToList);
public event WM_InventoryCheck InventoryCheck;
public void InventoryInspection()
{
specialList = new List<Item>();
if (InventoryCheck == null)
{
throw new NullReferenceException("No registered inspection method(s)");
}
foreach (Item item in itemList)
{
bool addToList = false;
InventoryCheck(item, ref addToList);
if (addToList)
{
specialList.Add(item);
}
}
}
public string SpecialInventory() => GetItemNames("Sonderartikel", specialList);
}
partial class WH_Setup
{
public static string Testaufruf4235() => Testaufruf4234(IncomingGoods);
public static string Testaufruf4234(Item[] items)
{
WarehouseMmgt whm = new WarehouseMmgt();
whm.PlaceInStorage(items);
whm.InventoryCheck += ItemExpiresSoon;
whm.InventoryCheck += ItemOnSpecialList;
whm.InventoryInspection();
return whm.SpecialInventory();
}
private static void ItemOnSpecialList(Item i, ref bool addToList)
{
if (!addToList)
{
addToList = Array.Exists(OnSaleList, no => i.ItemNo == no);
}
}
private static void ItemExpiresSoon(Item i, ref bool addToList)
{
if (!addToList)
{
addToList = (DateTime.Today - i.ExpirationDate).TotalDays <= 14;
}
}
static readonly int[] OnSaleList = { 2000200, 2000400 };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment