'已知订单日期,自动得出订单编号,年月日编号: Select Case User.Group Case "财务" If e.DataCol.Name = "订单日期" Then If e.DataRow.IsNull("订单日期") Then e.DataRow("订单编号") = Nothing Else Dim bh1 As String = "DT" & Format(e.DataRow("订单日期"),"yyMMdd") '取得订单编号的8位前缀 If e.DataRow("订单编号").StartsWith(bh1) = False '如果订单编号的前8位不符 Dim max1 As String Dim idx1 As Integer Dim d1 As Date = e.DataRow("订单日期").Date max1 = e.DataTable.Compute("Max(订单编号)","订单编号 like '" & bh1 & "%' and 订单日期 >= #" & d1 & "# And 订单日期 < #" & d1.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号 If max1 > "" Then '如果存在最大订单编号 idx1 = CInt(max1.Substring(max1.length-3,3)) + 1 '获得最大过磅编号的后三位顺序号,并加1 Else idx1 = 1 '否则顺序号等于1 End If e.DataRow("订单编号") = bh1 & Format(idx1,"000") End If End If End If Case Else If e.DataCol.Name = "订单日期" Then If e.DataRow.IsNull("订单日期") Then e.DataRow("订单编号") = Nothing Else Dim bh2 As String = "DY" & Format(e.DataRow("订单日期"),"yyMMdd") '取得订单编号的8位前缀 If e.DataRow("订单编号").StartsWith(bh2) = False '如果订单编号的前8位不符 Dim max2 As String Dim idx2 As Integer Dim d2 As Date = e.DataRow("订单日期").Date max2 = e.DataTable.Compute("Max(订单编号)","订单编号 like '" & bh2 & "%' and 订单日期 >= #" & d2 & "# And 订单日期 < #" & d2.adddays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该月的最大编号 If max2 > "" Then '如果存在最大订单编号 idx2 = CInt(max2.Substring(max2.length-3,3)) + 1 '获得最大过磅编号的后三位顺序号,并加1 Else idx2 = 1 '否则顺序号等于1 End If e.DataRow("订单编号") = bh2 & Format(idx2,"000") End If End If End If End Select
|