C# for循环中的逻辑困难&;if-else语句
我在做包装系统时遇到了一些逻辑问题。让我先解释一下情况,每个类别都有列表容量。还有一个项目列表用于存储标准包装单位项目 首先,我需要检查SPUItemList中项目的库存是否足够。如果它们还不够,我可以从prodSubstitute获得。prodSubstitute是按库存水平和每个类别降序排列的项目列表。一旦我添加到prodiList,我减去列表容量 如果他们有足够的库存水平,我会直接将其添加到prodIDList中,减去listCapacity 代码如下:C# for循环中的逻辑困难&;if-else语句,c#,asp.net,database,logic,C#,Asp.net,Database,Logic,我在做包装系统时遇到了一些逻辑问题。让我先解释一下情况,每个类别都有列表容量。还有一个项目列表用于存储标准包装单位项目 首先,我需要检查SPUItemList中项目的库存是否足够。如果它们还不够,我可以从prodSubstitute获得。prodSubstitute是按库存水平和每个类别降序排列的项目列表。一旦我添加到prodiList,我减去列表容量 如果他们有足够的库存水平,我会直接将其添加到prodIDList中,减去listCapacity 代码如下: List<D
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--;
}
List SPUItemList=newlist();
List prodIDList=新列表();
List distSPUItem=新列表();
//获取每个发行版所需的软件包总数
packagesNeeded=prodPackBLL.getPackagesNeedByDistributionId(distributionID);
//用标准包装单位包装
SPUItemList=packBLL.getAllSPUItemByDistributionID(distributionID);
for(int i=0;i总产品单位)
{
//获取库存不足的项目的类别名称
category=SPUItemList[i].categoryName;
//获取具有前5个最高存储级别的替代产品列表
List prodSubstitute=新列表();
//找到库存水平最高的替代品清单并更换产品
prodSubstitute=prodPackBLL.GetProductId,库存最高(类别);
for(int count=0;count
所以我的问题是,如果他们有足够的库存水平,并且我将其添加到prodIDList中,我如何修复我的代码,以便他们知道该类别的listCapacity已被扣除?因为到目前为止,我对这部分代码存在一些逻辑问题
对不起,我解释得不好,我希望你们都明白我在说什么
提前感谢。我想这样做(将listCapacity替换为categoryCheck并检查):
List lstcontegory=新列表();
List SPUItemList=新列表();
List prodIDList=新列表();
List distSPUItem=新列表();
//获取每个发行版所需的软件包总数
packagesNeeded=prodPackBLL.getPackagesNeedByDistributionId(distributionID);
//用标准包装单位包装
SPUItemList=packBLL.getAllSPUItemByDistributionID(distributionID);
for(int i=0;i总产品单位)
{
//获取库存不足的项目的类别名称
category=SPUItemList[i].categoryName;
//获取具有前5个最高存储级别的替代产品列表
List prodSubstitute=新列表();
//找到库存水平最高的替代品清单并更换产品
prodSubstitute=prodPackBLL.GetProductId,库存最高(类别);
for(int count=0;countx.Equals(category))。选择(x=>x.count()>2))
{
添加(prodSubstitute[count].id);
//列表容量--;
添加(类别);
}
}
}
其他的
{
//如果库存足够,请立即将其添加到ProdList中
category=SPUItemList[i].categoryName;
如果(!prodiList.Contains(SPUItemList[i].id)和&!(lstcontegory.Where(x=>x.Equals(category))。选择(x=>x.Count()>2))
{
添加(SPUItemList[i].id);
//列表容量--;
添加(类别);
}
}
}
listCapacity是Category的属性吗?不,它只是一个字符串变量,我需要检查-loop@afzalulh有什么建议吗?请看下面我的答案。但我需要将每个类别的列表容量限制为2。因此每个类别可能有2个products@Gwen-每个类别可以有两次相同的产品吗?不,不能有重复的,并且有一个检查if语句中是否存在重复项。不幸的是,没有。每个类别仍然有一个产品。我正在尝试为每个类别设置两个产品。现在,每个类别限制为两个产品。@afzaluluh假设我得到了产品1、2、3、4和5。我的产品
List<string> lstCategory = new List<string>();
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) && !(lstCategory.Where(x=>x.Equals(category)).Select(x=>x).Count() > 2))
{
prodIDList.Add(prodSubstitute[count].id);
//listCapacity--;
lstCategory.Add(category);
}
}
}
else
{
//If the stock is enough, add it into the prodIDList straight away
category = SPUItemList[i].categoryName;
if(!prodIDList.Contains(SPUItemList[i].id) && !(lstCategory.Where(x=>x.Equals(category)).Select(x=>x).Count() > 2))
{
prodIDList.Add(SPUItemList[i].id);
//listCapacity--;
lstCategory.Add(category);
}
}
}