Dim eb As DataRow
eb = DataTables("计划明细1").Find("工piao编号 = '" & e.DataRow("工piao编号") & "'")
If eb IsNot Nothing '如果找到, 则设置各列内容
e.DataRow("试样编号")= eb("试样编号")
e.DataRow("材检编号")= eb("材检编号")
e.DataRow("工号")= eb("工号")
e.DataRow("部件图号")= eb("部件图号")
e.DataRow("零件图号")= eb("零件图号")
e.DataRow("零件名称")= eb("零件名称")
e.DataRow("材质")= eb("材质")
e.DataRow("数量")= eb("数量")
e.DataRow("规格")= eb("下料尺寸")
End If
If e.DataCol.Name = "开具日期" Then
If e.DataRow.IsNull("开具日期") Then
e.DataRow("转送单号") = Nothing
Else
Dim d As Date = e.DataRow("开具日期")
Dim y As Integer = d.Year
Dim fd As Date = New Date(y,1,1) '获得该月的第一天
Dim ld As Date = fd.AddYears(1)
Dim bh As String = Format(d,"yyyy") '生成编号的前6位,4位年,2位月.
If e.DataRow("转送单号").StartsWith(bh) = False '如果编号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(转送单号)","开具日期 >= #" & fd & "# And 开具日期 < #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(bh.length+1)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("转送单号") = bh & "-" & Format(idx,"000")
End If
End If
[此贴子已经被作者于2017/4/26 18:14:26编辑过]