I am having some logic problem when doing packaging system. Let me explain the situation first, there is listCapacity for each category. There is also a SPUItemList to store the standard packing unit items.
First, I need to check whether the stock for items in SPUItemList is enough or not. If they are not enough, I get from the prodSubstitute. prodSubstitute is a list of items sorted descending by stockLevel and by each category. Once I added into prodIDList, I minus the listCapacity.
If they are enough stockLevel, I straight away add into prodIDList and minus the listCapacity.
Here is the codes:
List<DistributionStandardPackingUnitItems> SPUItemList = new List<DistributionStandardPackingUnitItems>();
List<string> prodIDList = new List<string>();
List<DistributionStandardPackingUnitItems> distSPUItem = new List<DistributionStandardPackingUnitItems>();
//Get total amount of packages needed by each distribution
packagesNeeded = prodPackBLL.getPackagesNeededByDistributionID(distributionID);
//Get the items in standard packing unit
SPUItemList = packBLL.getAllSPUItemByDistributionID(distributionID);
for (int i = 0; i < SPUItemList.Count; i++)
{
//Get the product quantity of each item in standard packing unit
productQuantity = Convert.ToInt32(SPUItemList[i].productQuantity);
//Get the total stock unit of each product in standard packing unit
totalProductUnit = prodPackBLL.getTotalProductUnit(SPUItemList[i].id);
if ((productQuantity * packagesNeeded) > totalProductUnit)
{
//Get the category name of the item which has not enough stock
category = SPUItemList[i].categoryName;
//Get the list of substitute product with top 5 highest storage level
List<ProductPacking> prodSubstitute = new List<ProductPacking>();
//Find list of substitute with highest stock level and replace the product
prodSubstitute = prodPackBLL.getProductIDWithHighestStock(category);
for (int count = 0; count < prodSubstitute.Count; count++)
{
//To prevent duplication of same product and check for the listCapacity
if (prodSubstitute[count].id != SPUItemList[i].id && !prodIDList.Contains(prodSubstitute[count].id) && count < listCapacity)
{
prodIDList.Add(prodSubstitute[count].id);
listCapacity--;
}
}
}
else
{
//If the stock is enough, add it into the prodIDList straight away
prodIDList.Add(SPUItemList[i].id);
listCapacity--;
}
So my question is, if they are enough stockLevel and I added into prodIDList, how can I fix my code so that they know the listCapacity for this category has been deducted? Because so far I have some logic problem with this portion of codes.
Sorry for my poor explanation and I hope you all understand what am I talking about.
Thanks in advance.