Datacolchanged事件代码要改一下
Select Case e.DataCol.name
Case "流水号"
If e.DataRow("提交") = True Then
Dim dr As DataRow = DataTables("检验记录").Find("流水号 = '" & e.OldValue & "'")
If dr Is Nothing Then
dr = DataTables("检验记录").AddNew()
dr("流水号") = e.DataRow("流水号")
dr("送货类别") = e.DataRow("类别")
dr("厂商") = e.DataRow("厂商")
dr("零件编号") = e.DataRow("零件编号")
dr("来货数量") = e.DataRow("来货数量")
dr("收货人") = e.DataRow("接收人")
dr("接货时间")=Date.now
dr("处理状态")="待处理"
Else
dr("流水号") = e.DataRow("流水号")
End If
End If
Case "提交"
If e.DataRow.IsNull("流水号") = False Then
If e.DataRow("提交") = True
Dim dr As DataRow = DataTables("检验记录").Find("流水号 = '" & e.DataRow("流水号") & "'")
If dr Is Nothing Then
dr = DataTables("检验记录").AddNew()
dr("流水号") = e.DataRow("流水号")
End If
dr("流水号") = e.DataRow("流水号")
dr("送货类别") = e.DataRow("类别")
dr("厂商") = e.DataRow("厂商")
dr("零件编号") = e.DataRow("零件编号")
dr("来货数量") = e.DataRow("来货数量")
dr("收货人") = e.DataRow("接收人")
dr("接货时间")=Date.now
dr("处理状态")="待处理"
End If
End If
Case "流水号","送货类别","厂商","零件编号","来货数量","收货人"
Dim dr As DataRow = DataTables("检验记录").Find("流水号 = '" & e.DataRow("流水号") & "'")
If dr IsNot Nothing Then
dr(e.DataCol.Name) = e.DataRow(e.DataCol.Name)
End If
End Select
If e.DataCol.Name = "收货日期" Then
If e.DataRow.IsNull("收货日期") Then
e.DataRow("流水号") = Nothing
Else
Dim bh As String = Format(e.DataRow("收货日期"),"yyyyMMdd") '取得编号的8位前缀
If e.DataRow("流水号").StartsWith(bh) = False '如果编号的前8位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(流水号)","收货日期= #" & e.DataRow("收货日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该天的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(9,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("流水号") = bh & "-" & Format(idx,"000")
End If
End If
End If