📄 mainmodule.vb
字号:
Public Function createCode(ByVal agentId As Integer, ByVal userId As Integer, ByVal productId As Integer, ByVal codeNum As Long) As Boolean
Dim db As New Dbase
Dim dt As New DataView
Dim strSet As New DataSet
Dim strTable As DataTable = strSet.Tables.Add("strTable")
Dim strCol As DataColumn = strTable.Columns.Add("code", Type.GetType("System.String"))
strCol.Unique = True
dt = db.RunSelectSQL("SELECT table_flag,code_flag,table_time FROM fw_user WHERE id = " & userId & " AND del_flag=0")
Dim tableFlag As String = dt.Item(0)("table_flag")
Dim codeFlag As Integer = dt.Item(0)("code_flag")
Dim tableName As String = "fw_" & tableFlag & "_" & codeFlag.ToString
Dim tableTime As Integer = dt.Item(0)("table_time") + 1
Dim codeLen As Integer
Dim i As Long, j As Integer
Dim rndStr As String
Dim codeLeftStr As String = tableFlag & Strings.Right(("0" & tableTime.ToString), 2)
Dim codeString As String = ""
Dim ctime As String = Now().ToString
statusForm.Label1.Text = "正在处理..."
statusForm.PBar1.Maximum = codeNum
mainForm.Hide()
statusForm.Show()
For i = 0 To codeNum - 1
Try
strTable.Rows.Add()
rand:
rndStr = ""
Randomize()
Select Case codeFlag
Case 16
rndStr = CLng(CLng(99999999999 * Rnd()) + 0).ToString
Case 18
rndStr = CLng(CLng(9999999999999 * Rnd()) + 0).ToString
Case 20
rndStr = CLng(CLng(999999999999999 * Rnd()) + 0).ToString
End Select
codeLen = codeFlag - 5 - rndStr.Length
For j = 1 To codeLen
rndStr = "0" & rndStr
Next
codeString = codeLeftStr & rndStr
strTable.Rows(i).Item(0) = codeString
Catch ex As Exception
GoTo rand
End Try
If i Mod 1000 = 0 Then statusForm.PBar1.Value = i
Application.DoEvents()
Next
statusForm.PBar1.Value = codeNum
statusForm.Label1.Text = "正在存储..."
'save
db.RunDelOrInsSQL("INSERT INTO fw_order(agent_id,user_id,product_id,code_num,insert_time) VALUES(" & agentId & "," & userId & ", " & productId & "," & codeNum & ",'" & ctime & "')")
Dim orderId As Integer = db.getLastId("fw_order")
db.RunTran("code")
db.RunExec("UPDATE fw_user SET table_time=" & tableTime & " WHERE id=" & userId & "")
Try
For i = 0 To codeNum - 1
db.RunExec("INSERT INTO " & tableName & "(code,agent_id,user_id,product_id,order_id) VALUES('" & strTable.Rows(i).Item(0) & "'," & agentId & "," & userId & "," & productId & "," & orderId & ")")
If i Mod 1000 = 0 Then statusForm.PBar1.Value = i
Application.DoEvents()
Next
db.RunCommit()
Catch ex As Exception
Throw ex
db.RunRollback()
db.RunDelOrInsSQL("DELETE FROM fw_order WHERE id=" & orderId & "")
End Try
statusForm.Hide()
mainForm.Show()
Return True
End Function
End Module
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -