Select oldest record do some action then go to the next oldest record and do some action in vb.net
Posted on 2014-04-30
I'm working on a vb.net script in Visual Studio 2010 that needs to go through a collection of records and do some action and then move on to the next until the Quantity = 0.
Each record is a "picking order" each order has a order date, product and order amount.
The Quantity field is the amount we have in stock for the product. In my example, product ABC the Quantity = 60
So, I need to be able to loop through my picking orders and begin slotting the quantity I have into each picking order beginning with the oldest one.
Using my example,
(1) I start with Quantity = 60, and apply 50 to Picking Order 123 thus closing that one. And now I have Quantity = 10
(2) Then I move on to the second oldest picking order, in this case 456, and apply the remaining Quantity of 10 to it, thus making picking order 456 have an order amount of 10.
(3) If there is only 1 picking order then apply the 50 it needs and place the remaining quantity of 10 in a field called "overage", or if there only 2 picking orders and we've closed them both out and still have some "overage" then apply that "overage" to the last blanket order (in this case the second one).
The picking orders are pulled from a query to the database:
Select * From PickingOrders Where ItemNumber = "the item number I'm analyzing"
Any idea how I can do this? I was thinking a do while loop or do until loop, but need some syntax guidance.
Thank you in advance!