dr("单号") = "SCXD-" & Format(rq, "yyyyMMdd") & Format(id,"000")
老师,上面代码中,就这个 id 没看明白,以下是我OpenQQ实现网络环境下的编号的代码,请老师根据代码帮我改改在网页上如何写,谢谢!
服务端全局代码:
Public scxdbh As new Dictionary(of String,Integer)
服务端AfterOpenProject代码:
Dim dt2 As DataTable
Dim cmd2 As New SQLCommand
cmd2.C onnection Name = "SqlQqServer"
cmd2.C ommandT ext = "S elect Year(录入时间) As 年, Month(录入时间) As 月, Day(录入时间) As 日, Max(单号) as 单号 From {生产任务通知} Group By Year(录入时间), Month(录入时间),Day(录入时间)"
dt2 = cmd2.ExecuteReader
scxdbh.Clear()
For Each dr As DataRow In dt2.DataRows
Dim qz As String = dr("年") & Format(dr("月"),"00") & Format(dr("日"),"00") '编号前缀,4位年,2位月,2位日
Dim bh As String = dr("单号")
Dim id As Integer
If bh.Length = 17 Then
bh = bh.SubString(14)
If Integer.TryParse(bh,id) Then
scxdbh.Add(qz, id)
End If
End If
Next
服务端OpenQQ服务端事件ReceivedMessage代码:
Dim msg2 As String = e.Message '生产任务通知单号
If msg2.StartsWith(":x") AndAlso msg1.EndsWith("x:") Then
msg2 = msg2.SubString(2, msg2.Length - 4)
If scxdbh.ContainsKey(msg2) Then '如果存在这个年月日的编号
scxdbh(msg2) = scxdbh(msg2) + 1 '将该日最大编号加1
Else
scxdbh.Add(msg2,1) '如果是这个年月日的首次编号,则编号等于1
End If
e.ReturnValue = scxdbh(msg2) '将编号返回给客户端
End If
客户端部分代码:
Dim cmd As New SQLCommand
Dim dt As Date
cmd.C onnection Name = "ShcsErpSQL"
cmd.C ommand Text = "Select GetDate()"
dt = cmd.ExecuteScalar()
Dim dqsj As Date = Format(dt, "yyyy-MM-dd HH:mm:ss")
Dim bh As String = Format(dqsj,"yyyyMMdd")
Dim rt As String = QQClient.SendWait(":x" & bh & "x:")
Dim id As Integer
If rt > "" Then
If Integer.TryParse(rt,id) Then
dr = _dt生产任务通知.AddNew
dr("单号") = "SCXD-" & bh & "-" & Format(id,"000")