有人可以就我的问题给我一些想法或解决方案吗?
目前,我的系统没有重置正在运行的号码,这是我的源代码:
If cls_PICS.get_ExistingSequenceNoOld(TextScanPartNo.Text, TextBoxMOQ.Text, TextVendorID.Text) = True Then
cls_PICS.BOXIDRunningNo(cls_PICS.BoxEnd(0))
TextStart.Text = cls_PICS.NewBox
Else
TextStart.Text = "A00001"
End If
Public Function get_ExistingSequenceNoOld(ByVal PN As String, ByVal q As String, ByVal vID As String)
On Error GoTo ErrorHandler
Dim SQL_str As String =
"SELECT * " &
"FROM setup ORDER BY PrinterDateTime DESC"
'"SELECT * " &
'"FROM setup where PartNo='" & PN & "' AND MOQ='" & q & "' AND VendorID='" & vID & "' AND Status <> 'INACTIVE' ORDER BY PrinterDateTime DESC"
Dim adLWS As New OdbcDataAdapter(SQL_str, cnPICS)
Dim dsLWS As New DataSet
adLWS.Fill(dsLWS, "BOXID")
LWS_CONT = dsLWS.Tables("BOXID").Rows.Count
If LWS_CONT < 1 Then
get_ExistingSequenceNoOld = False
'get_cstTBL_Insert(val)
Exit Function
End If
此代码主要在打印完标签后将所有信息保存到设置表中:
Public Function InsertBoxIDPrint(ByVal venID As String, ByVal PartNo As String, ByVal Quantity As String, ByVal PDate As String, ByVal Qty As String, ByVal boxID As String, ByVal EmployeeID As String, ByVal qc As String, ByVal DQ As String, ByVal BoxSTART As String, ByVal BoxEND As String, ByVal PC As String)
On Error GoTo ErrorHandler
'Dim pn As String
'Dim RefnoP As String
'Dim curDate As String
Dim dateL As Date
Dim date1 As String
dateL = cls_PICS.get_SERVER_Datetime
date1 = dateL.ToString("yyyy-MM-dd HH:mm:ss")
'curDate = dateL.Value.ToString("yyyyMMdd")
'If cls_PICS.get_RefNoPrint <> False Then
' pn = cls_PICS.RefNoPrint
' RefnoP = curDate & "-" & Format((Int(pn) + 1), "000")
'Else
' RefnoP = curDate & "-001"
'End If
Dim SQLcmd As New OdbcCommand()
Dim cnPICS As New OdbcConnection(getPICSConStr)
SQLcmd.CommandText = "INSERT INTO [setup] (VendorID, PartNo, MOQ, PrinterDateTime, PrintQty, BoxID, PrintBy, QC, DeliveryQty, StartBox, EndBox, PC) " &
"VALUES ('" &
venID & "','" &
PartNo & "','" &
Quantity & "','" &
date1 & "','" &
Qty & "','" &
boxID & "','" &
EmployeeID & "','" &
qc & "','" &
DQ & "','" &
BoxSTART & "','" &
BoxEND & "','" &
PC & "')"
SQLcmd.Connection = cnPICS
SQLcmd.CommandType = CommandType.Text
cnPICS.Open()
SQLcmd.ExecuteNonQuery()
cnPICS.Close()
SQLcmd = Nothing
InsertBoxIDPrint = True
Exit Function
ErrorHandler:
InsertBoxIDPrint = False
MsgBox("InsertBoxIDPrint:" & Err.Description, MsgBoxStyle.Critical)
On Error Resume Next
Err.Clear()
End Function
答案 0 :(得分:0)
只要数据是数据库中的数据,当前脚本就不会返回新计数。它基于数据库中的行数。我会在数据库中创建一个新表,只是为了保持上次打印日期和当前计数。每次调用打印件时,它都会检查您创建的表中的最后一个打印日期。如果它们匹配,继续今天计数并将今天的计数增加1,否则将新的开始日期添加到表并开始计数为0或1,具体取决于您是立即发出打印,还是在打印期间计数器增加。 / p>
您的新表应包含两个字段:PrintDate,PrintCounter
如果这是服务器端软件,PrintDate和PrintCounter的变量可以编写为变量脚本,但是在重置服务器时,变量将会丢失,除非您选择将它们写入文件而不是数据库。
以下是您可以尝试的一些示例代码。我的VB技能很缺乏。
adLWS.Fill(dsLWS, "date1")
Dim lastRecord As Int32
Dim lastDate As String
lastRecord = dsLWS.Tables("date1").Rows.Count - 1
lastDate = dsLWS.Tables("date1").Rows.Item(lastRecord).Item("date1")
If Today.Date > CDate(lastDate).Date Then
get_ExistingSequenceNoOld = False
Else
get_ExistingSequenceNoOld = True
End If