Private Sub ButtonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdd.Click
status = "add"
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim mad As String
mad = "select top 1 CustomerID from Customers order by CustomerID desc"
da = New SqlDataAdapter(mad, cn)
ds = New DataSet
da.Fill(ds, "topid")
Dim ny, Y As String
ny = CStr(Now.Year)
Y = ny.Substring(ny.Length - 2)
Dim m As String = Now.Month.ToString("00")
Dim newid As String = ""
With ds.Tables("topid")
If .Rows.Count <> 0 Then
Dim oldid, lid, mid, Rid As String
oldid = .Rows(0).Item("CustomerID").ToString
lid = oldid.Substring(0, 2)
mid = oldid.Substring(2, 2)
Rid = oldid.Substring(4, 3)
If lid = Y Then
newid = Y & m & (CInt(Rid) + 1).ToString("000")
Else
newid = Y & m & "001"
End If
End If
lblCusID.Text = newid
TbCusName.ReadOnly = False
tbAdd.ReadOnly = False
MtbIDCard.ReadOnly = False
Mtbtel.ReadOnly = False
LblPic.Enabled = False
TbCusName.Clear()
tbAdd.Clear()
MtbIDCard.Clear()
Mtbtel.Clear()
DtAdmit.Value = Now.Date ' ดึงวันที่มาโชว์
TbCusName.Focus()
End With
End Sub