我可能在我的嵌套循环上做错了,它没有循环遍历所有菜单项以减少库存。 [英] Wha I may done wrong on my nested loop, its not looping through all the menu items to decrement stock.
问题描述
我正在尝试使用网格视图中显示的数据减少商店数据库中的库存。
- (grdSaleSet)此gridview显示我销售的销售类别
- (grdStockDecrement) - 此gridview显示从saleset gridview获取参数的配方(项目ID和项目比例)。
问题开始当我需要在这个嵌套循环中循环时,它只遍历由saleset项提供的项目配方的一次迭代,但它不从Saleset gridview读取第二项,因此它可以搜索第二项配方并减少它。
循环仅使用其配方减少第一个待售商品的库存。第二项似乎没有遍历。
请在下面的代码中告知我可能错过了什么?
我有什么试过:
' 搜索控制器减少库存驱动程序网格
对于 ss As 整数 = 0 grdSaleSet.Rows .Count - 1
objCM.MenuDescription = grdSaleSet.Rows(ss).Cells( 1 )。值' 提取项目描述
objCM.Price = Convert.ToDecimal (grdSaleSet.Rows(ss).Cells( 2 )。Value)' 提取项目价格
grdStockDecrement.DataSourc e = objc.GetIngredientsDecrementDriver(objCM.MenuDescription,objCM.Price)' 使用项目desc和价格进行搜索并在减量gridview上显示
grdStockDecrement.Columns( 0 )。Visible = False 隐藏未重新确定的列。
' 减少库存的比例
对于 dd 作为 整数 = 0 grdStockDecrement.Rows.Count - 1 ' 使用递减gridview循环
objc._ingrId = grdStockDecrement.Rows(dd).Cells( 1 )。值' 提取成分ID
objc.Proportion = Convert.ToDecimal(grdStockDecrement.Rows(dd).Cells( 2 )。Value)' 提取成分配方比例
objc.decrement_Inventory(objc._ingrId,objc.Proportion)
下一步
下一步
< blockquote>我认为你的问题是由在外循环中不断重置 grdStockDecrement.DataSource
引起的。
用于过滤 DataSet
,请参阅:数据集中的过滤和排序 [ ^ ]
如果你使用 DataTable
您可以使用 dataTable.DefaultView.RowFilter
。
这里是我如何修复它。
'现金支付仅
如果radCash.Checked = True则
如果txtTenderAmount.Text =那么
MessageBox.Show(请输入现金金额)
其他
'保存到订单表
objCust.CustomerId = Convert.ToInt32(1)
objCust.EmployeeId = 3
objCust.OrderTotal = Convert.ToDecimal(txtSaleTotal.Text)
objCust.OrderTender = Convert.ToDecimal(txtTenderAmount.Text)
objCust.PaymentMethod =Cash
objCust.PaymentStatus =付费
objCust.OrderStatus =Open
objCust.OrderDate = CDate(System.DateTime.Now)
objCust.CreateNewCustomerOrder(objCust)
'将订单信息保存到桥实体OrderItem表
For x As Int eger = 0到grdSaleSet.Rows.Count - 1
itemQty = CInt(grdSaleSet.Rows(x).Cells(0).Value)'提取项目数量在销售集
如果itemQty = 0然后
lbl1.Text = itemQty
objCustOrd.ItemQty = 1
否则
objCustOrd.ItemQty = itemQty'提取项目数量在销售中设置
结束如果
'objCustOrd.ItemQty = grdSaleSet.Rows(x).Cells(0).Value'在销售集中提取项目数量
objCustOrd.ItemNo = CInt(grdSaleSet.Rows(x).Cells(1).Value )'提取项目否
objCustOrd.ItemPrice = grdSaleSet.Rows(x).Cells(3).Value'提取项目价格
objCustOrd.CreateNewCustomerOrderItem()'将保存功能调用到订单项
下一个
'控制器运行ver gridview to decrement stock
for ss As Integer = 0 to grdSaleSet.Rows.Count - 2'这个gridview -2因为默认标题,网格中的最后一行是空的。
itemQty = CInt(grdSaleSet.Rows(ss).Cells(0).Value)'销售集中每个订单项的数量
objCM.MenuDescription = grdSaleSet.Rows(ss).Cells(2) ).Value'提取项目描述
objCM.Price = Convert.ToDecimal(grdSaleSet.Rows(ss).Cells(3).Value)'提取项目价格
'检查订单项数量,如果它的零设置为一个
如果itemQty = 0则
itemQty = 1'设置行项目数量为默认值1
结束如果
grdStockDecrement .DataSource = objc.GetIngredientsDecrementDriver(objCM.MenuDescription,objCM.Price)'使用项目desc和价格进行搜索并显示减量gridview
grdStockDecrement.Columns(0).Visible = False'隐藏未重新确定的列。
'减少股票的比例
对于dd As Integer = 0到grdStockDecrement.Rows.Count - 1'循环使用递减gridview
objc._ingrId = grdStockDecrement.Rows(dd).Cells(1 ).Value'提取成分id
objc.Proportion = Convert.ToDecimal(grdStockDecrement.Rows(dd).Cells(2).Value)* itemQty'提取成分配方比例
objc.decrement_Inventory(objc。 _ingrId,objc.Proportion)
下一个
下一个
MessageBox.Show(订单成功保存)'显示订单完成订单
结束如果
结束如果
I'm trying to decrement a stock in the store database using the displayed data in my gridviews.
- (grdSaleSet) This gridview displays my sales sort of a receipt for a sale
- (grdStockDecrement) - This gridview displays the recipe (item Id and item proportion) which get the parameters from the saleset gridview.
The problem begins when i need to loop in this nested loop, it only traverse one iteration of the item recipe supplied by saleset item, but its not reading the second item from Saleset gridview so it could search for the second items recipe and decrement it.
The loop only decrement the stock for the 1st item on sale using its recipe. The second item seem to not traversed.
Please advise what i may have missed in the code below?
What I have tried:
'search controller to decrement stock driver grid
For ss As Integer = 0 To grdSaleSet.Rows.Count - 1
objCM.MenuDescription = grdSaleSet.Rows(ss).Cells(1).Value 'extract item description
objCM.Price = Convert.ToDecimal(grdSaleSet.Rows(ss).Cells(2).Value) 'extract item price
grdStockDecrement.DataSource = objc.GetIngredientsDecrementDriver(objCM.MenuDescription, objCM.Price) 'search using item desc and price and display on decrement gridview
grdStockDecrement.Columns(0).Visible = False 'Hiding the column which is not reqiured.
'Proportion to decrease stock
For dd As Integer = 0 To grdStockDecrement.Rows.Count - 1 'loop using decreament gridview
objc._ingrId = grdStockDecrement.Rows(dd).Cells(1).Value 'extract ingredient id
objc.Proportion = Convert.ToDecimal(grdStockDecrement.Rows(dd).Cells(2).Value) 'extract ingredient recipe proportion
objc.decrement_Inventory(objc._ingrId, objc.Proportion)
Next
Next
I think your problem is caused by resettinggrdStockDecrement.DataSource
constantly in the outer loop.
For filteringDataSet
, see: Filtering and Sorting in Datasets[^]
If you use aDataTable
you might usedataTable.DefaultView.RowFilter
.
Here is how i fixed it. 'The CASH payment only If radCash.Checked = True Then If txtTenderAmount.Text = "" Then MessageBox.Show("Please enter cash amount") Else 'saving into order table objCust.CustomerId = Convert.ToInt32(1) objCust.EmployeeId = 3 objCust.OrderTotal = Convert.ToDecimal(txtSaleTotal.Text) objCust.OrderTender = Convert.ToDecimal(txtTenderAmount.Text) objCust.PaymentMethod = "Cash" objCust.PaymentStatus = "Paid" objCust.OrderStatus = "Open" objCust.OrderDate = CDate(System.DateTime.Now) objCust.CreateNewCustomerOrder(objCust) 'Save order info into bridge entity OrderItem table For x As Integer = 0 To grdSaleSet.Rows.Count - 1 itemQty = CInt(grdSaleSet.Rows(x).Cells(0).Value) 'extract item qty in sale set If itemQty = 0 Then lbl1.Text = itemQty objCustOrd.ItemQty = 1 Else objCustOrd.ItemQty = itemQty 'extract item qty in sale set End If 'objCustOrd.ItemQty = grdSaleSet.Rows(x).Cells(0).Value 'extract item qty in sale set objCustOrd.ItemNo = CInt(grdSaleSet.Rows(x).Cells(1).Value) 'extract item No objCustOrd.ItemPrice = grdSaleSet.Rows(x).Cells(3).Value 'extract item price objCustOrd.CreateNewCustomerOrderItem() 'calling save function into order item Next 'Controller driver gridview to decrement stock For ss As Integer = 0 To grdSaleSet.Rows.Count - 2 'This gridview -2 because of the default header which and last row in the grid which is empty. itemQty = CInt(grdSaleSet.Rows(ss).Cells(0).Value) 'Quantity per line item in a sale-set objCM.MenuDescription = grdSaleSet.Rows(ss).Cells(2).Value 'extract item description objCM.Price = Convert.ToDecimal(grdSaleSet.Rows(ss).Cells(3).Value) 'extract item price 'Checking the line item qty, if its zero set it one If itemQty = 0 Then itemQty = 1 'set line item qty to a default value of one End If grdStockDecrement.DataSource = objc.GetIngredientsDecrementDriver(objCM.MenuDescription, objCM.Price) 'search using item desc and price and display on decrement gridview grdStockDecrement.Columns(0).Visible = False 'Hiding the column which is not reqiured. 'Proportion to decrease stock For dd As Integer = 0 To grdStockDecrement.Rows.Count - 1 'loop using decreament gridview objc._ingrId = grdStockDecrement.Rows(dd).Cells(1).Value 'extract ingredient id objc.Proportion = Convert.ToDecimal(grdStockDecrement.Rows(dd).Cells(2).Value) * itemQty 'extract ingredient recipe proportion objc.decrement_Inventory(objc._ingrId, objc.Proportion) Next Next MessageBox.Show("Order succesfully saved") 'Show succes completion of order End If End If
这篇关于我可能在我的嵌套循环上做错了,它没有循环遍历所有菜单项以减少库存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!