Select Case e.DataCol.Name
Case "产品编号", "期初_数量", "入库_数量", "出库_数量"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(Of DataRow)
dr = e.DataTable.Find("[行号] < " & mr("行号") & " And [产品编号] = '" & mr("产品编号") & "'", "[行号] Desc")
If dr Is Nothing Then
mr("库存_数量") = mr("期初_数量") + mr("入库_数量") - mr("出库_数量")
dr = mr
End If
drs = e.DataTable.Select("[行号] >= " & dr("行号") & " And [产品编号] = '" & dr("产品编号") & "'", "[行号]")
For 行号 As Integer = 1 To drs.Count - 1
drs(行号)("库存_数量") = drs(行号 - 1)("库存_数量") + drs(行号)("入库_数量") - drs(行号)("出库_数量")
Next
If e.DataCol.Name = "产品编号" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[行号] < " & mr("行号") & " And [产品编号] = '" & e.OldValue & "'", "[行号] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[产品编号] = '" & e.OldValue & "'", "[行号]")
If dr IsNot Nothing Then
dr("库存_数量") = dr("入库_数量") - dr("出库_数量")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[行号] >= " & dr("行号") & " And [产品编号] = '" & dr("产品编号") & "'", "[行号]")
For 行号 As Integer = 1 To drs.Count - 1
drs(行号)("库存_数量") = drs(行号 - 1)("库存_数量") + drs(行号)("入库_数量") - drs(行号)("出库_数量")
Next
End If
End If
End Select
有时会升序,有时会降序,有时中间插入,如何让它按固定一种?比如在最后一行
此主题相关图片如下:新增顺序.png
dr = e.DataTable.Find("[行号] < " & mr("行号") & " And [产品编号] = '" & mr("产品编号") & "'", "[行号] Desc")
问题1:按行号排序还是错乱,如何处理不乱?如何更好?
'DataRowAdded
Dim max As Integer = e.DataTable.Compute("Max(行号)")
e.DataRow("行号") = max + 1
代码执行,还有重号,如处理?
[此贴子已经被作者于2024/8/15 16:00:50编辑过]
Dim Cols3() As String = {"下期", "产品编号", "数量""}'
Dim Cols4() As String = {"下期", "产品编号", "数量""}'
For Each dr3 As DataRow In DataTables("窗口_Table1").Select("选中=True") '
If DataTables("窗口_Table2").Find("产品编号 = '" & dr3("产品编号") & "'") Is Nothing Then '
Dim dr4 As Row = Tables("窗口_Table2").AddNew() '
For r As Integer = 0 To Cols3.Length - 1
dr4(Cols4(r)) = dr3(Cols3(r))
Next
Else
End If
Next
执行一次后,怎么会行号和其他数据都重复三条或多条,如何实现不重复?
此主题相关图片如下:流水重复.png
行号生成
Dim max As Integer = e.DataTable.Compute("Max(行号)")
e.DataRow("行号") = max + 1
查一下,是下面问题,保存一次就所有数据复制一次,在其他表保存,没有发现异常,用流水帐,就会这样保存一次就所有数据复制一次,如何处理?
Dim db = HySql.DataBaseFactory.CreateDatabase("t4") '
Dim dt2 As DataTable = e.Form.Controls("Table2").Table.DataTable
Dim dtb2 As System.Data.DataTable = dt2.basetable.Copy '
dtb2.Columns.Remove("_Locked") '
dtb2.Columns.Remove("System_Sort_Temporary")
dtb2.Columns.Remove("System_Filter_Temporary")
dtb2.Columns.Remove("System_Filter_Unique")
Dim res2 = db.UpdateDataTable(dtb2, "流水")
'dt2.AcceptChanges()
MessageBox.Show("保存成功!"