【发布时间】:2014-01-01 02:41:56
【问题描述】:
我在做包装系统时遇到了一些逻辑问题。让我先解释一下情况,每个类别都有 listCapacity。还有一个SPUItemList来存储标准包装单位的物品。
首先,我需要检查 SPUItemList 中商品的库存是否充足。如果它们还不够,我会从 prodSubstitute 获得。 prodSubstitute 是按 stockLevel 和每个类别降序排序的项目列表。添加到 prodIDList 后,我减去 listCapacity。
如果 stockLevel 足够,我会立即添加到 prodIDList 并减去 listCapacity。
代码如下:
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--;
}
所以我的问题是,如果它们足够 stockLevel 并且我添加到 prodIDList 中,我该如何修复我的代码,以便他们知道该类别的 listCapacity 已被扣除?因为到目前为止我对这部分代码有一些逻辑问题。
对不起,我的解释很糟糕,我希望你们都明白我在说什么。
提前致谢。
【问题讨论】:
-
listCapacity 是 Category 的属性吗?
-
不,它只是一个字符串变量让我检查for循环
-
@afzalulh 有什么建议吗?
-
请看下面我的回答。