代码设置在发外染纱表的datacolchanged事件中,发外染纱表是发外加工表的明细表,窗口中发外加工表在上,发外染纱表在下,发外染纱表增加一行,根据发外加工表得当前行的发外编号产生一个发外明细编号,当发外染纱表新增行时其他单元格有复制的内容时会产生发外明细编号,当没有内容时,不会产生发外明细编号,请问老师什么原因?谢谢!
Dim r As Row = Tables("生产计划排产_table11").Current
If r IsNot Nothing AndAlso r.Isnull("发外编号") = False Then
Dim lb As String = r("发外编号") & "-"
If e.DataRow("发外明细编号").StartsWith(lb) = False Then '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.sqlCompute("Max(发外明细编号)","发外明细编号 like '" & r("发外编号") & "%' And [_Identify] <> " & e.DataRow("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(lb.length,2)) + 1 '获得最大编号的后两位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("发外明细编号") = lb & Format(idx,"00")
e.DataRow.Save
End If
ElseIf r IsNot Nothing AndAlso r.Isnull("发外编号") = True Then
msgbox("请检查发外加工单,发外编号不能空!")
Return
ElseIf r Is Nothing Then
msgbox("发外加工单没有当前行,请检查!")
Return
End If
下面是发外染纱表增加按钮的代码:
_userroles.Contains("生产计划") = True Then
Dim r1 As Row = Tables("发外加工计划表").Current
If r1 IsNot Nothing Then
Dim r2 As Row = Tables("发外毛坯表").addnew
Dim Cols1() As String = {"订单编号","订单客户","外加工厂商"}
Dim Cols2() As String = {"订单编号","客户","外加工厂商"}
For i As Integer = 0 To Cols1.Length -1
If r1.Isnull(Cols1(i)) = False Then
r2(Cols2(i)) = r1(Cols1(i))
End If
r2.save
Next
Else
msgbox("没有发外单请检查!")
End If
Else
msgbox("您没有权限增加发外明细!")
Return
End If