以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 流水账问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=149265) |
-- 作者:swagger -- 发布时间:2020/4/27 16:49:00 -- 流水账问题 Select Case e.DataCol.Name
Case "产品","入库","出库" Dim dr As DataRow Dim mr As DataRow = e.DataRow Dim drs As List(of DataRow) Dim jk As Integer Dim ck As Integer dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品] = \'" & mr("产品") & "\'", "[_SortKey] Desc") If dr Is Nothing Then \'如果是第一行,计算结存 jk = DataTables("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & mr("产品") & "\'") ck = DataTables("例子二").SQLCompute("Sum(出库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & mr("产品") & "\'") mr("库存") = e.DataRow("入库") - e.DataRow("出库") + jk - ck 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 \'如果找到,计算库存 jk = DataTables("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & e.OldValue & "\'") ck = DataTables("例子二").SQLCompute("Sum(出库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & e.OldValue & "\'") dr("库存") = dr("入库") - dr("出库") + jk - ck 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 |
-- 作者:有点蓝 -- 发布时间:2020/4/27 17:20:00 -- 所有地方都加多一个条件,另外可能要分开处理一下,大概这样 Select Case e.DataCol.Name Case "入库","出库","产品","产品ID" Dim dr As DataRow Dim mr As DataRow = e.DataRow Dim drs As List(of DataRow) Dim jk As Integer Dim ck As Integer dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品] = \'" & mr("产品") & "\' and [产品ID] = \'" & mr("产品ID") & "\' ", "[_SortKey] Desc") If dr Is Nothing Then \'如果是第一行,计算结存 jk = DataTables("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And [产品] = \'" & mr("产品") & "\' and [产品ID] = \'" & mr("产品ID") & "\' ") ck = DataTables("例子二").SQLCompute("Sum(出库)","[_SortKey] < " & mr("_SortKey") & " And [产品] = \'" & mr("产品") & "\' and [产品ID] = \'" & mr("产品ID") & "\'") mr("库存") = e.DataRow("入库") - e.DataRow("出库") + jk - ck dr = mr End If drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品] = \'" & dr("产品") & "\' and [产品ID] = \'" & mr("产品ID") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库") Next End Select Select Case e.DataCol.Name Case "产品" Dim dr As DataRow Dim mr As DataRow = e.DataRow Dim drs As List(of DataRow) Dim jk As Integer Dim ck As Integer If e.OldValue IsNot Nothing Then dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品] = \'" & e.OldValue & "\' and [产品ID] = \'" & mr("产品ID") & "\' ", "[_SortKey] Desc") \'找出旧产品的上一行 If dr Is Nothing Then \'如果不存在上一行,那么本行就是旧产品的第一行,由于已经被修改为新产品,需要找出旧产品现在的第一行 dr = e.DataTable.Find("[产品] = \'" & e.OldValue & "\'and [产品ID] = \'" & mr("产品ID") & "\' ", "[_SortKey]") \'找出旧产品现在的第一行 If dr IsNot Nothing Then \'如果找到,计算库存 jk = DataTables("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & e.OldValue & "\' and [产品ID] = \'" & mr("产品ID") & "\' ") ck = DataTables("例子二").SQLCompute("Sum(出库)","[_SortKey] < " & mr("_SortKey") & " And 产品 = \'" & e.OldValue & "\' and [产品ID] = \'" & mr("产品ID") & "\' ") dr("库存") = dr("入库") - dr("出库") + jk - ck End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品] = \'" & dr("产品") & "\' and [产品ID] = \'" & mr("产品ID") & "\' ", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("库存") = drs(i-1)("库存") + drs(i)("入库") - drs(i)("出库") Next End If End If Case "产品ID" Dim dr As DataRow Dim mr As DataRow = e.DataRow Dim drs As List(of DataRow) Dim jk As Integer Dim ck As Integer If e.OldValue IsNot Nothing Then dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [产品ID] = \'" & e.OldValue & "\' and [产品] = \'" & mr("产品") & "\' ", "[_SortKey] Desc") \'找出旧产品的上一行 If dr Is Nothing Then \'如果不存在上一行,那么本行就是旧产品的第一行,由于已经被修改为新产品,需要找出旧产品现在的第一行 dr = e.DataTable.Find("[产品ID] = \'" & e.OldValue & "\'and [产品] = \'" & mr("产品") & "\' ", "[_SortKey]") \'找出旧产品现在的第一行 If dr IsNot Nothing Then \'如果找到,计算库存 jk = DataTables("例子二").SQLCompute("Sum(入库)","[_SortKey] < " & mr("_SortKey") & " And 产品ID = \'" & e.OldValue & "\' and [产品] = \'" & mr("产品") & "\' ") ck = DataTables("例子二").SQLCompute("Sum(出库)","[_SortKey] < " & mr("_SortKey") & " And 产品ID = \'" & e.OldValue & "\' and [产品] = \'" & mr("产品") & "\' ") dr("库存") = dr("入库") - dr("出库") + jk - ck End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [产品ID] = \'" & dr("产品ID") & "\' and [产品] = \'" & mr("产品") & "\' ", "[_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 |