-- [求助]库存先进先出,一直错误,求教高手
DataTables("产品库").load()
DataTables("产品出入明细").load()
Dim ssck As String = e.Form.Controls("所属仓库").Value
Dim rq As Date = e.Form.Controls("日期").Value
Dim cpmc As String = e.Form.Controls("产品名称").Value
Dim cplx As String = e.Form.Controls("产品类型").Value
Dim lqry As String = e.Form.Controls("领取人员").Value
Dim ddbh As String = e.Form.Controls("订单编号").Value
Dim lqsl As Integer = e.Form.Controls("领取数量").Value
Dim kc As Double = DataTables("产品库").SQLCompute("Sum(库存数量)", "产品类型 = \'" & cplx & "\' And 产品名称 = \'" & cpmc & "\' And 所属仓库 = \'" & ssck & "\'")
If lqsl > 0 Then
If kc >= lqsl Then
Dim count As Integer = 0
Dim drs As List(Of DataRow) = DataTables("产品库").Select("产品类型 = \'" & cplx & "\' And 产品名称 = \'" & cpmc & "\' And 库存数量 > 0 And 所属仓库 = \'" & ssck & "\'", "产品批次, 存储位置_架,存储位置_层")
For i As Integer = 0 To drs.count - 1
Dim dr As DataRow = drs(i)
Dim sy As Integer = lqsl - dr("库存数量")
If sy > 0 Then
Dim cr As DataRow = DataTables("产品出入明细").AddNew()
cr("方向") = "出库"
cr("所属仓库") = ssck
cr("日期") = rq
cr("产品批次") = dr("产品批次")
cr("产品名称") = cpmc
cr("产品类型") = cplx
cr("交接人") = lqry
cr("数量") = dr("库存数量")
cr("存储位置_架") = dr("存储位置_架")
cr("存储位置_层") = dr("存储位置_层")
cr("订单编号") = ddbh
dr("库存数量") = 0
lqsl = lqsl - dr("库存数量")
Else
Dim cr As DataRow = DataTables("产品出入明细").AddNew()
cr("方向") = "出库"
cr("所属仓库") = ssck
cr("日期") = rq
cr("产品批次") = dr("产品批次")
cr("产品名称") = cpmc
cr("产品类型") = cplx
cr("交接人") = lqry
cr("数量") = lqsl
cr("存储位置_架") = dr("存储位置_架")
cr("存储位置_层") = dr("存储位置_层")
cr("订单编号") = ddbh
dr("库存数量") = dr("库存数量") - lqsl
Exit For
End If
Next
Else
msgbox("库存不够")
End If
Else
msgbox("领取数量必须大于零")
End If
DataTables("产品库").load()
DataTables("产品出入明细").load()