如何在使用VB的Dapper的MSACESS数据库中删除以往的顺序交易编号。 NET?
Below is the transaction number that I deleted previously:
Invno |
---|
DEPT-ITI-1023-00002 |
如果我从 com箱中选择转让项目“DEPT-ITU-”的价值,交易编号如下:
Invno |
---|
DEPT-ITI-1023-00004 |
因此,如果我从 com箱中选择转让项目“DEPT-ITU-”的价值,那么交易号预期结果如下:
Invno |
---|
DEPT-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 | HeaderInvno | Transaction | InvnoDate | ItemTransferIn | MonthYear |
---|---|---|---|---|---|
DEPT-ITI-1023-00001 | 1 | ITEM TRANSFER IN | 19/10/2023 | DEPT-ITI- | 2310 |
DEPT-ITI-1023-00003 | 3 | ITEM TRANSFER IN | 19/10/2023 | DEPT-ITI- | 2310 |