如何在新的一天到来时重置运行号码ID [英] How to reset running number ID when the new day come

查看:103
本文介绍了如何在新的一天到来时重置运行号码ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用label_id打印标签

标签ID格式包含运行编号0001(0001,0002,..) - 我想在新的一天到来时将运行编号重置为0001 。

有人可以给我一些关于我的问题的想法或解决方案吗?



目前,如果新的一天到来,我的系统会重置运行号码但是问题是运行次数一次又一次地重复00001



我尝试了什么:



i want to print label with label_id
label id format contain running number which is 0001 (0001,0002,..) -i want to reset the running number to 0001 when the new day come.
can someone give me some ideas or solution regarding my problem?

currently, my system reset the running number if new day come but the problem is the running number keep repeating 00001 again and again

What I have tried:

Public Function get_ExistingSequenceNoOld(ByVal PN As String, ByVal q As String, ByVal vID As String)
       On Error GoTo ErrorHandler
       Dim dateL As Date
       Dim date1 As String
       Dim lastRecord As String
       Dim lastDate As String
       dateL = cls_PICS.get_SERVER_Datetime
       date1 = dateL.ToString("yyyy-MM-dd")


        PrinterDateTime DESC"

       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
       ' lastRecord = dsLWS.Tables("BOXID").Rows.Count - 1
       'lastDate = dsLWS.Tables("BOXID").Rows.Item(lastRecord).Item("LastDate")

       If LWS_CONT < 1 Then
           get_ExistingSequenceNoOld = False
           'get_cstTBL_Insert(val)
           Exit Function
       End If

       ReDim PartNo(LWS_CONT)
       ReDim BoxEnd(LWS_CONT)
       ReDim DateEnd(LWS_CONT)
       ReDim PrintQty(LWS_CONT)
       ReDim MOQ(LWS_CONT)
       ReDim venID(LWS_CONT)
       ReDim DeliveryQty(LWS_CONT)
       ReDim qcInspection(LWS_CONT)

       Dim i As Integer
       For i = 0 To LWS_CONT - 1
           PartNo(i) = dsLWS.Tables("BOXID").Rows(i)("PartNo").ToString
           MOQ(i) = dsLWS.Tables("BOXID").Rows(i)("MOQ").ToString
           BoxEnd(i) = dsLWS.Tables("BOXID").Rows(i)("EndBox").ToString
           PrintQty(i) = dsLWS.Tables("BOXID").Rows(i)("PrintQty").ToString
           venID(i) = dsLWS.Tables("BOXID").Rows(i)("VendorID").ToString
           DeliveryQty(i) = dsLWS.Tables("BOXID").Rows(i)("DeliveryQty").ToString
           qcInspection(i) = dsLWS.Tables("BOXID").Rows(i)("QC").ToString
           BoxEnd(i) = dsLWS.Tables("BOXID").Rows(i)("EndBox").ToString
           DateEnd(i) = dsLWS.Tables("BOXID").Rows(i)("LastDate").ToString
       Next

       If Today.Date > CDate(DateEnd(i)).Date Then
           get_ExistingSequenceNoOld = False

       Else
           get_ExistingSequenceNoOld = True
       End If



       Exit Function

推荐答案

首先在表格中添加两列:

第一个是INT IDENTITY列,名为 Ident ,自动递增一个

第二个是名为的DATE列InsDat 默认为GETDATE()

然后当你想要每日序列的行使用时:

Start by adding two columns to your Table:
The first is an INT IDENTITY column called Ident, autoincrementing by one
The second is a DATE column called InsDat which defaults to GETDATE()
Then when you want the rows with a daily sequence use this:
SELECT m.Ident, m.InsDat, m.OtherColumnList, m.Ident - s.MinSeq + 1 AS Seq FROM MyTable m
JOIN (SELECT Insdat, MIN(Ident) AS MinSeq FROM MyTable GROUP BY InsDat) s ON s.InsDat = m.InsDat



你得到的是一个整数列,每天从1开始 - 你可以将其格式化为a如果需要,可以使用zered字符串,或让你的表示层处理它。


What you get is an integer column which starts at 1 each day - you can format that to a leading zered string if you need to, or let your presentation layer handle that.

Ident	InsDat	Val	       Seq
1	2017-07-05	A         	1
2	2017-07-05	A         	2
3	2017-07-05	A         	3
4	2017-07-05	A         	4
5	2017-07-05	A         	5
6	2017-07-06	B         	1
7	2017-07-06	B         	2
8	2017-07-06	B         	3
9	2017-07-06	B        	4
10	2017-07-06	B         	5
11	2017-07-06	B         	6
12	2017-07-07	C         	1
13	2017-07-07	C         	2
14	2017-07-07	C         	3
15	2017-07-07	C         	4
16	2017-07-08	D         	1


这篇关于如何在新的一天到来时重置运行号码ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆