以下是引用cxcx在2011-8-31 19:09:00的发言:
比如说产品是分规格 和型号的
我要做 什么规格 什么型号 出库 入库 库存 该怎么改这代码
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品] = '" & mr("产品") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("库存") = mr("入库") - mr("出库")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品] = '" & dr("产品") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库")
Next
If e.DataCol.Name = "产品" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品] = '" & e.OldValue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[产品] = '" & e.OldValue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("库存") = dr("入库") - dr("出库")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品] = '" & dr("产品") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库")
Next
End If
End If
End Select
DataRowDeleting
e.DataRow("入库") = 0
e.DataRow("出库") = 0
AfterMoveRow
Dim Key As Decimal
Dim Index As Integer
Dim Filter As String
Dim r As Row
Index = Math.Min(e.OldIndex, e.NewIndex)
Key = e.Table.Rows(Index)("_SortKey")
r = e.Table.Rows(e.NewIndex)
Filter = "[_SortKey] >= " & Key & " And [产品] = '" & r("产品") & "'"
e.Table.DataTable.DataCols("入库").RaiseDataColChanged(Filter)
常规的进销存,不建议采取产品、规格、型号等方式进行库存处理。
合理的方案为,对商品进行唯一编码。实际操作中库存盘点、补货、入库等都方便很多。
而编码长度按实际需求而定,常规商品在1万以下6位编码唯一,方便简洁。