Public Sub RunID(ByRef CodeID As String, ByVal DocCate As String)
Dim Sql As String = ""
Sql = " SELECT * FROM DocMstr "
Sql &= " WHERE DocCate = '" & DocCate.Trim & "' "
Dim DA As New SqlDataAdapter(Sql, CnnDB)
Dim DS As New DataSet
DA.Fill(DS, "RunNewID")
If DS.Tables("RunNewID").Rows.Count > 0 Then
Dim YearUdt As Date '= CDate(DS.Tables("RunNewID").Rows(0).Item("DocUpdate"))
YearUdt = Now
Dim DocTitle As String = CStr(DS.Tables("RunNewID").Rows(0).Item("DocTitle"))
Dim DocNo As Integer = CInt(DS.Tables("RunNewID").Rows(0).Item("DocNo"))
If Now.Year > YearUdt.Year Then
DocNo = 1
Else
DocNo += 1
End If
CodeID = DocTitle & Now.Year.ToString.Substring(2, 2) & Now.Month.ToString("00") & DocNo.ToString("0000")
UpdateDocMstr(DocNo, DocCate.Trim)
Else
MessageBox.Show("ไม่พบเลขรหัสล่าสุด")
End If
End Sub