提问人:siwa86 提问时间:10/19/2023 最后编辑:Amit Joshisiwa86 更新时间:10/19/2023 访问量:68
如何处理以前删除的顺序交易编号,以便它们可以保持顺序
How to handle sequential transaction numbers that were previously deleted so they can remain sequential
问:
如何使用 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 |
答: 暂无答案
评论
Is this a typo in your narrative: *DEPT-ITU
Do records have a date created field?