Dim Insert As String
Insert = "INSERT INTO History_ProReport (Date,Code_Tag,Pro_No,Count_Scans)"
Insert &= "SELECT Date,Code_Tag,Pro_No,Count_Scan FROM Products_CodeTag"
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
Dim com As New SqlCommand
With com
.CommandType = CommandType.Text
.CommandText = Insert
.Connection = myConn
.ExecuteNonQuery()
End With
Dim update1 As String
update1 = "UPDATE [Products_CodeTag] SET [Count_Scan]= '0' "
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
With com
.CommandType = CommandType.Text
.CommandText = update1
.Connection = myConn
.ExecuteNonQuery()
End With
End Sub
Dim sql_select As String
sql_select = "SELECT ค่าที่ตรวจสอบ จะตรวจอะไรใส่ในช่องนี้นะคับ"
Dim dr_select As OleDbDataReader
Dim com_select As OleDbCommand
com_select = New OleDbCommand()
With com_select
.CommandType = CommandType.Text
.CommandText = sql_select
.Connection = Conn
.Parameters.Clear()
dr_select = .ExecuteReader()
If dr_select.HasRows Then
' ถ้ามีเเล้วให้ทำอะไร
Else
'ถ้าไม่มีเเล้วทำอะไร
End If
End With
Dim sql_select As String
Dim dtNow As DateTime = System.DateTime.Now
sql_select = "SELECT Date,Code_Tag,Pro_No FROM History_ReportCount WHERE Date='" & dtNow.ToString("MM/dd/yyyy") & "'"
Dim dr_select As SqlDataReader
Dim com_select As SqlCommand
com_select = New SqlCommand()
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
With com_select
.CommandType = CommandType.Text
.CommandText = sql_select
.Connection = myConn
.Parameters.Clear()
dr_select = .ExecuteReader()
If dr_select.HasRows Then
Dim Update As String
Update = "UPDATE History_ReportCount SET Count_Scans= H.Count_Scans + P.Count_Scan "
Update &= "FROM History_ReportCount H inner join Products_CodeTag P on H.Date = P.Date And H.Code_Tag = P.Code_Tag And H.Pro_No = P.Pro_No"
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
Dim com As New SqlCommand
With com
.CommandType = CommandType.Text
.CommandText = Update
.Connection = myConn
.ExecuteNonQuery()
End With
Else
Dim Insert As String
Insert = "INSERT INTO History_ReportCount (Date,Code_Tag,Pro_No,Count_Scans)"
Insert &= "SELECT Date,Code_Tag,Pro_No,Count_Scan FROM Products_CodeTag"
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
Dim com As New SqlCommand
With com
.CommandType = CommandType.Text
.CommandText = Insert
.Connection = myConn
.ExecuteNonQuery()
End With
End If
End With
Dim update1 As String
update1 = "UPDATE Products_CodeTag SET Count_Scan= '0' "
With myConn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = StrConn
.Open()
End With
Dim com1 As New SqlCommand
With com1
.CommandType = CommandType.Text
.CommandText = update1
.Connection = myConn
.ExecuteNonQuery()
End With