Private Const constPurchaseIDPrefix As String = "PUR"
Private Const constPurchaseCounterFormatPattern As String = "000000"
'Overload for common usage
Private Function GetPurchaseMatid() As String
Return GetPurchaseMatid(DateTime.Now)
End Function
Private Function GetPurchaseMatid(ByVal RefDateTime As DateTime) As String
Dim datePartStr As String = RefDateTime.ToString("ddMMyy")
'Dicut only counter and if no record founded it's alway convert to 0
Dim retStr As String = String.Format("SELECT ISNULL(MAX(SUBSTRING([Pur_ID],{0},LEN([Pur_ID])-{1} )),0) FROM [Tl_Purchase]" _
, constPurchaseIDPrefix.Length, datePartStr.Length)
Dim d_command As SqlCommand = New SqlCommand(retStr, Conn)
Dim PurchaseCounter As Integer = 0
DGSTOCK.Visible = False
Btnbuy.Visible = False
Try
Conn.Open()
retStr = d_command.ExecuteScalar().ToString()
PurchaseCounter = Convert.ToInt32(retStr) + 1
'Response.Write(constPurchaseIDPrefix)
'Response.Write(constPurchaseCounterFormatPattern)
'Response.Write(datePartStr)
Response.Write(retStr)
Response.Write(PurchaseCounter)
Response.End()
retStr = String.Format("{0}{1}{2}", constPurchaseIDPrefix _
, PurchaseCounter.ToString(constPurchaseCounterFormatPattern) _
, datePartStr)
Response.Write(retStr)
Response.End()
'Catch 'ex As Exception
' retStr = "#ERROR"
'End Try
'เป็น()
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
Return retStr
End Function
พอทราบว่ามันผิดตรง substring แต่พอรันแล้วมันฟ้องว่า Invalid length parameter passed to the substring function.
ต้องแก้ยังหร๋อค่ะ รบกวนหน่อยนะคะ