Dim
dt As
DataTable
'SQL省略发不出贴
flbhs.Clear()
For
Each dr As
DataRow
In dt.DataRows
Dim qz As
String = dr("年") & Format(dr("月"),"00") '编号前缀,4位年,2位月
Dim bh As
String = dr("编号")
Dim id As
Integer
If
bh.Length =
10
Then
bh
= bh.SubString(7)
If
Integer.TryParse(bh,id) Then
flbhs.Add(qz, id)
End
If
End
If
Next
上述代码在启动项目后,用SQL语句提取现有数据的每月最大编号,将其整数部分存储在字典flbhs中。
3、在服务端的OpenQQ服务端事件ReceivedMessage中编写代码:
Dim
msg As
String = e.Message
If msg.StartsWith(":p")
AndAlso msg.EndsWith("p:") Then
msg = msg.SubString(2, msg.Length - 4)
If flbhs.ContainsKey(msg)
Then
'如果存在这个月的编号
flbhs(msg) = flbhs(msg) + 1
'将该月最大编号加1
Else
flbhs.Add(msg,1) '如果是这个月的首次编号,则编号等于1
End
If
e.ReturnValue =
flbhs(msg) '将编号返回给客户端
End
If
客户端的设计
选择客户端项目的订单表,在其DataColChanged事件中加上代码:
If
e.DataCol.Name =
"日期"
Then
If
e.DataRow.IsNull("日期") Then
e.DataRow("编号") = Nothing
Else
If QQClient.Ready = False
Then
PopMessage("QQClient未启动,无法生成编号!","提示",PopIconEnum.Infomation,5)
Else
Dim bh As
String = Format(e.DataRow("日期"),"yyyyMM")
Dim rt As
String =
QQClient.SendWait(":p"
& bh
& "p:")
Dim id As
Integer
If rt > "" Then
If
Integer.TryParse(rt,id) Then
e.DataRow("编号") = bh & "-" & Format(id,"000")
Else
PopMessage("服务器返回错误信息:" & rt,"提示",PopIconEnum.Infomation,5)
End
If
Else
PopMessage("服务器无响应,无法生成编号!","提示",PopIconEnum.Infomation,5)
End
If
End
If
End
If
End
If