If e.DataCol.Name = "开单日期" Then
If e.DataRow.IsNull("开单日期") Then
e.DataRow("年") = Nothing
e.DataRow("月") = Nothing
e.DataRow("日") = Nothing
e.DataRow("发货单号") = Nothing
Else
e.DataRow("年") = Format(e.DataRow("开单日期"),"yyyy")
e.DataRow("月") = Format(e.DataRow("开单日期"),"yyyyMM")
e.DataRow("日") = Format(e.DataRow("开单日期"),"yyyyMMdd")
End If
End If
'按开单日期的月份自动生成发货单号(FH1502001)
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 m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
Dim bh As String = "FH" & Format(d,"yyMM") '生成编号的前4位,2位年,2位月
If e.DataRow("发货单号").StartsWith(bh) = False '如果编号的前4位不符
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(7,3)) + 1 '获得最大编号的后三位顺序号,并加1
idx = CInt(max.Substring(6,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
'e.DataRow("订单单号") = bh & "-" & Format(idx,"000")
e.DataRow("发货单号") = bh & Format(idx,"000")
End If
End If
End If
'如果客户代码或业务员更改
Select Case e.DataCol.Name
Case "客户代码","业务员"
Dim crs As List(of DataRow) = e.DataRow.GetChildRows("销售发货明细") '获得明细表中的所有行
For Each cr As DataRow In crs
cr(e.DataCol.Name) = e.DataRow(e.DataCol.Name)
Next
End Select
'客户取值
If e.DataCol.Name = "客户代码" Then '产品ID发生改变
Dim dr As DataRow
dr = DataTables("客户").Find("客户代码 = " & "'" & e.DataRow("客户代码") & "'" ) '在产品表找出该产品
If dr IsNot Nothing '如果找到, 则设置各列内容
e.DataRow("客户简称")= dr("客户简称")
e.DataRow("客户全称")= dr("客户全称")
e.DataRow("联系人")= dr("联系人")
e.DataRow("送货地址")= dr("客户地址")
End If
End If
'自动记录开单人和时间
If e.DataCol.Name = "开单日期" Then
If e.DataRow("开单日期") = Nothing Then '如果开单日期是空的
e.DataRow("开单人") = Nothing
Else
'e.DataRow("开单人") = Nothing
e.DataRow("开单人") = _UserName & " " & format(Date.Now,"g")
End If
End If
If e.DataCol.Name = "审核" Then
e.DataRow("审核人") = User.Name & " " & format(Date.Now,"g")
End If