如何处理以前删除的顺序交易编号,以便它们可以保持顺序

How to handle sequential transaction numbers that were previously deleted so they can remain sequential

提问人:siwa86 提问时间:10/19/2023 最后编辑:Amit Joshisiwa86 更新时间:10/19/2023 访问量:68

问:

如何使用 VB.NET 在Dapper中调用MS ACCESS数据库中以前删除的顺序交易编号?

以下是我之前删除的交易编号:

因夫诺
部门-ITI-1023-00002

如果我从组合框中选择转移项“DEPT-ITI-”的值,则会出现以下交易编号:

因夫诺
部门-ITI-1023-00004

因此,如果我从组合框中选择转账项目“DEPT-ITI-”的值,那么交易编号所需的结果如下:

因夫诺
部门-ITI-1023-00002
Public Class Form1
    Private HeaderInvno As Integer
    Dim sis As New Stocksinservice()
    Private CurrentMonthYear As String
    Private ItemTransferIn As String ' Define ItemTransferIn as a string
    Private Sub CreateInvno()
        'Dim myDate As DateTime = DateTime.Now
        Dim myDate As DateTime = DateTimePicker1.Value
        Dim strTime As String = myDate.ToString("MMyy-")
        Dim newMonthYear As String = myDate.ToString("yyMM")

        ' Set ItemTransferIn based on ComboBox1.Text
        If ComboBox1.Text = "ITEM TRANSFER IN" Then
            ItemTransferIn = "DEPT-ITI-"
        ElseIf ComboBox1.Text = "PURCHASE INVOICE" Then
            ItemTransferIn = "DEPT-PI-"
        ElseIf ComboBox1.Text = "RECEIVE ITEM" Then
            ItemTransferIn = "DEPT-RI-"
        End If
        ' Retrieve the HeaderInvno and MonthYear from the database
        Dim stockin = sis.SelectTop(ItemTransferIn)
        If stockin IsNot Nothing Then
            HeaderInvno = stockin.HeaderInvno
            CurrentMonthYear = stockin.MonthYear
        Else
            HeaderInvno = 0
            CurrentMonthYear = ""
        End If
        '' Check if the month and year have changed
        If stockin Is Nothing OrElse myDate.Year > stockin.InvnoDate.Year OrElse myDate.Month > stockin.InvnoDate.Month Then
            '        If Not newMonthYear.Equals(CurrentMonthYear) Then
            HeaderInvno = 1
            CurrentMonthYear = newMonthYear
        Else
            HeaderInvno = stockin.HeaderInvno + 1
        End If
        ' Concatenate ItemTransferIn with other parts of the invoice number
        BtxtInvoNo.Text = ItemTransferIn & strTime & HeaderInvno.ToString("00000")
    End Sub
    Private Sub ComboBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedValueChanged
        CreateInvno()
    End Sub

Public Class Stocksinservice
    Private connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DEMO.accdb;Persist Security Info=False;"
    Public Function SelectTop(itemTransferIn As String) As Stocksin
        Dim sql = $"SELECT TOP 1 HeaderInvno,InvnoDate FROM Stocksin WHERE ItemTransferIn = '{itemTransferIn}' ORDER BY HeaderInvno DESC "
        Using _conn = New OleDbConnection(connectionString)
            Return _conn.Query(Of Stocksin)(sql).FirstOrDefault()
        End Using
    End Function
End Class
Public Class Stocksin
    Public Property Invno() As String
    Public Property HeaderInvno() As Integer
    Public Property Transaction() As String
    Public Property InvnoDate As DateTime
    Public Property ItemTransferIn() As String
    Public Property MonthYear() As String
End Class

表记录Stockin

因夫诺 标题Invno 交易 InvnoDate 项目转移 月年
部门-ITI-1023-00001 1 物品转入 19/10/2023 部门-ITI- 2310
部门-ITI-1023-00003 3 物品转入 19/10/2023 部门-ITI- 2310
SQL vb.net MS-Access

评论

0赞 June7 10/19/2023
这是你叙述中的错别字吗:*DEPT-ITU
0赞 June7 10/19/2023
我还有一个数据库,不需要顺序上的间隙。我进行了编程,以便在创建新记录时立即将其提交到具有新序列号的表中。然后,如果用户决定中止输入,我会删除除序列 ID 之外的所有数据,因此会出现“空白”记录。接下来,新的记录数据条目将找到此“空白”记录并使用它。在序列中查找间隙需要遍历数据集并比较序列值,直到遇到间隙。我不知道如何在 vb.net 中对其进行编码。这是否有助于 fredmastro.com/blog/10
0赞 June7 10/19/2023
记录是否具有创建日期字段?DEPT 值的时间顺序重要吗?可以找到这些旧的空白并创建“VOIDED”或“DELETED”记录。
0赞 siwa86 10/19/2023
@June7,你是对的,这是一个错别字Is this a typo in your narrative: *DEPT-ITU
0赞 siwa86 10/19/2023
@June7 ,是的,我有一个名称为数据类型 datetime 的字段Do records have a date created field?

答: 暂无答案