你好,下面的代码是根据网格视图中的产品数量从库存中扣除产品数量的代码。
问题是,我想用类别=1减去产品数量,并进行验证,以检查网格中的所有产品数量是否大于库存中的数量,如果一个产品数量大于存储中的数量,则代码不应执行。
Category Id =gridagree.Rows[index].Cells[7].Text
Product Id = gridagree.Rows[index].Cells[3].Text)
Product Quantity in the grid =gridagree.Rows[index].Cells[5].Text
StoreClass s = new StoreClass();
if(//suggested code)
{
lblmsg.Text="Product quantity is bigger than current balance please change product quantity and try again"// here also can i determine to the user which product has the issue product with id=?
}
else
{
for (int index = 0; index < this.gridagree.Rows.Count; index++)
                    {
                        if (gridagree.Rows[index].Cells[7].Text == "1")
                        {
                            string qun = s.getprodqun(Convert.ToInt32(gridagree.Rows[index].Cells[3].Text));
                            s.subtract(Convert.ToInt32(gridagree.Rows[index].Cells[3].Text), Convert.ToInt32(qun) - Convert.ToInt32(gridagree.Rows[index].Cells[5].Text));
                        }
                    }
}发布于 2015-09-18 18:42:59
我不想评论代码,我只会给你提供我认为你想要的。如何在样本中编码,你需要另一个循环.
int categoryIdIndex = 7;
int productIdIndex = 3;
int quantityRequestedIndex = 5;
List<string> errors = new List<string>()
for (int index = 0; index < this.gridagree.Rows.Count; index++)
{
  Row row = gridagree.Rows[index];
  int categoryId = Convert.ToInt32(row.Cells[categoryIdIndex].Text);
  int productId = Convert.ToInt32(row.Cells[productIdIndex].Text);
  int quantityRequested = Convert.ToInt32(row.Cells[quantityRequestedIndex].Text);
  int availableQuantity = s.getprodqun(productId);
  if(quantityRequested > availableQuantity)
  {
    errors.Add(string.Format("Inventory contains insufficient items for product id {0} ", productId));
  }
}
if(errors.Count == 0)
{
  ... process the orders ...
}
else
{
  ... show the errors
}https://stackoverflow.com/questions/32658504
复制相似问题