Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Imports System.Data
Imports System.Runtime.InteropServices
Imports System.Reflection
Public Class frmLogin
'เข้าสู่ระบบ
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim objConn As New MySqlConnection
Dim objCmd As New MySqlCommand
Dim strConnString, strSQL, strNUMANDDATE, strTIMETOLOCK As String
Dim i As Integer
i = TimeOfDay.Hour
If i Mod 2 = 0 Then
strTIMETOLOCK = i
Else
strTIMETOLOCK = i - 1
End If
strConnString = "Server=localhost;User Id=root; Password=1234; Database=reservation; Pooling=false"
objConn.ConnectionString = strConnString
objConn.Open()
Dim checkid As Integer
strSQL = "SELECT COUNT(*) FROM member WHERE Username = '" & Me.txtUsername.Text &
"' AND password = '" & Me.txtPassword.Text & "' AND member_id = '" & Me.txtmemberid.Text & "'"
objCmd = New MySqlCommand(strSQL, objConn)
checkid = objCmd.ExecuteScalar()
Dim checkcomanddate As Integer
strNUMANDDATE = "SELECT COUNT(*) FROM book WHERE book_no = '" & Me.lblnum.Text &
"' AND book_date = '" & Format(Now, "yyyy-mm-dd") &"' AND member_id = '" & Me.txtmemberid.Text & "'"
objCmd = New MySqlCommand(strNUMANDDATE, objConn)
checkcomanddate = objCmd.ExecuteScalar()
objConn.Close()
objConn = Nothing
If checkid > 0 Then
If checkcomanddate > 0 Then
tmlockwindow1.Start()
tmmessage1.Start()
tmtimeshow.Start()
Me.Hide()
Else
MessageBox.Show("คุณไม่ได้จองเครื่องคอมพิวเตอร์ในเวลาดังกล่าว")
End If
Else
MessageBox.Show("รหัสผ่านหรือรหัสประจำตัวไม่ถูกต้อง ")
End If
End Sub
'ปุ่มปิด
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
If MessageBox.Show("คุณต้องการออกจากโปรแกรมใช่หรือไม่ ?", "", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub tmlockwindow1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmlockwindow1.Tick
If Now.Hour & Now.Minute & Now.Second = 6 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 8 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 10 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 12 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 14 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 16 & 0 & 1 Then
Me.Show()
End If
If Now.Hour & Now.Minute & Now.Second = 18 & 0 & 1 Then
Me.Show()
End If
End Sub
Private Sub tmmessage1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmmessage1.Tick
If Now.Hour & Now.Minute & Now.Second = 7 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
If Now.Hour & Now.Minute & Now.Second = 9 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
If Now.Hour & Now.Minute & Now.Second = 11 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
If Now.Hour & Now.Minute & Now.Second = 13 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
If Now.Hour & Now.Minute & Now.Second = 15 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
If Now.Hour & Now.Minute & Now.Second = 17 & 55 & 1 Then
frmmessage.Show()
tmmessage1.Stop()
End If
End Sub
Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
If (e.Alt AndAlso e.KeyCode = Keys.F4) Then
e.Handled = True
End If
If (e.Alt AndAlso e.KeyCode = Keys.Tab) Then
e.Handled = True
End If
End Sub
Private Sub frmlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Focus()
End Sub
Private Sub tmtimeshow_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmtimeshow.Tick
lbltimeshow.Text = DateAndTime.TimeString
End Sub
End Class
1. สร้าง Form จองเวลาขึ้นมา
2. เวลาเก็บข้อมูลการจองเข้าฐานข้อมูล ให้เก็บค่าของ เวลาเริ่มต้น และ เวลาสิ้นสุด ในรูปแบบ(DataType)ของ DateTime
3. เวลาเอามาเปรียบเทียบ if Now >= เวลาเริ่มต้น AND NOW < เวลาสิ้นสุด Then
**ไม่ต้องไปแยกเป็น ชั่วโมง นาที วินาทีแล้ว