Dim Cmd As OleDbCommand
Dim Dr As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GenOrderID()
End Sub
Sub GenOrderID()
Dim sql As String = "Select Max(Right(id_staff,5)) as oid from tb_staff"
Cmd = New OleDbCommand(sql, conn)
ConnectDB()
'MsgBox(Cmd.ExecuteScalar)
'Dim newOid As Integer = CInt(Cmd.ExecuteScalar)
Dr = Cmd.ExecuteReader
Dr.Read()
If Not Dr.HasRows Then
'ถ้าค่าที่ได้รับเป็นค่า Null
' MsgBox("ok")
'MsgBox(Now.ToString("yy"))
t_id.Text = "S" & Now.ToString("yy") & "0000000001"
Else
Dim newID As Integer = CInt(Dr.Item("oid"))
newID += 1
t_id.Text = "S" & Now.ToString("yy") & newID.ToString("0000000000")
End If
'newOid = newOid + 1
'txtOrderId.Text = newOid.ToString
'Conn.Close()
End Sub
Protected Sub GenOrderID()
Dim dv As DataView
Dim sql As String = "Select Max(Right(staff_id,4)) as staff_id from tb_staff"
dv = ObjDb.GetDataSet(sql).Tables(0).DefaultView
'dv.Table(tb_staff)
If Not dv.Count > 0 Then
'ถ้าค่าที่ได้รับเป็นค่า Null
' MsgBox("ok")
'MsgBox(Now.ToString("yy"))
txtstaff_id.Text = "S" & "001"
Else
Dim newID As Integer = CInt(dv.Equals("staff_id"))
newID = newID + 1
' MsgBox(newID)
txtstaff_id.Text = "S" & newID.ToString("000")
End If
End Sub
DECLARE @CAPTURE INT;
SELECT @CAPTURE=RequestNumber FROM [config] ;
IF (@CAPTURE IS NULL)
BEGIN
INSERT INTO [CONFIG]
(
RequestNumber
)
VALUES
(
0
)
END ;
UPDATE [CONFIG] SET RequestNumber= RequestNumber+1 ;
SELECT RequestNumber FROM [config] ;
Public Sub AutoID()
Call OpenDB()
gStrSql = ""
'gStrSql = "select max(ID) as AutoID from Tbl_Event"
gStrSql = "select top 1 ID from Tbl_Event order by ID desc"
Dim daID = New OleDbDataAdapter(gStrSql, Conn)
Dim dsID = New DataSet
daID.Fill(dsID, "Tbl_Event")
yy = CStr(Now.Year + 543)
mm = Now.Month.ToString("00")
With dsID.Tables("Tbl_Event")
If .Rows.Count <> 0 Then
Dim eid, Lid, Mid, Rid As String
eid = .Rows(0).Item("ID").ToString
Lid = eid.Substring(0, 4)
Mid = eid.Substring(4, 2)
Rid = eid.Substring(6, 5)
If Lid = yy Then
If Mid = mm Then
StrIDAcc = Lid & Mid & (CInt(Rid) + 1).ToString("00000")
Else
StrIDAcc = Lid & mm & "00001"
End If
Else
StrIDAcc = yy & mm & "00001"
End If
Else
StrIDAcc = yy & mm & "00001"
End If
End With
End Sub
$sql="select * from TblServices where ID like 'SERV"."%' order by ID desc";
$re=mssql_query($sql) or die(error());
$row=mssql_fetch_array($re);
$id=$row["ID"];
$date1=date("Y-m-d");
$dd=substr($date1,8,2);
$mm=substr($date1,5,2);
$yy=substr($date1,0,4);
if($id==""){
$serv_id="SERV".$yy.$mm."0001";
}else{
$chk_id=substr($id,0,10);
$chk_date="SERV".$yy.$mm;
if($chk_id==$chk_date){
$id=substr($id,10,4);
$id=$id+1;
if(strlen($id)==1)$id="000".$id;
if(strlen($id)==2)$id="00".$id;
if(strlen($id)==3)$id="0".$id;
$serv_id="SERV".$yy.$mm.$id;
}else{
$serv_id="SERV".$yy.$mm."0001";
}
}