Imports MySql.Data.MySqlClient
Imports MySql.Data
Imports System.Data
Public Class fmlogin
Dim sql As String = "Server=localhost;User Id=root; Password=1234; Database=shop_management_system;"
Dim conn As New MySqlConnection
Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click
Close()
End Sub
Private Sub btnregistry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnregistry.Click
fmregistry.Show()
Me.Hide()
End Sub
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
conn.ConnectionString = sql
conn.Open()
Try
If Me.txtusername.Text = "" Or Me.txtpass.Text = "" Then
MsgBox("กรุณากรอกชื่อผู้ใช้งานและรหัสผ่าน", MsgBoxStyle.Exclamation, "Error")
txtusername.Clear()
txtpass.Clear()
Me.txtusername.Focus()
End If
If txtusername.Text <> "" And txtpass.Text <> "" Then
Dim cm As New MySqlCommand("select * from login where Username=" & "'" & txtusername.Text & "' and pass=" & "'" & txtpass.Text & "'", conn)
Dim Rd As MySqlDataReader
Dim User As String
Dim Pass As String
Dim firstname As String
Dim lastname As String
Rd = cm.ExecuteReader
Rd.Read()
User = Rd.Item("Username")
Pass = Rd.Item("pass")
firstname = Rd.Item("Firstname")
lastname = Rd.Item("Lastname")
If txtusername.Text = User And txtpass.Text = Pass Then
Dim insert As New MySqlCommand
Dim dd As String = " INSERT INTO [Checkuser] (Status,Username,Firstname,Lastname ) " & _
"SELECT Status,Username,Firstname,Lastname FROM Login WHERE Username='" & User & "' and Firstname='" & firstname & "' and Lastname='" & lastname & "'"
insert.CommandType = CommandType.Text
insert.CommandText = dd
insert.Connection = conn
insert.ExecuteNonQuery()
fmshop.Text = firstname
fmshop.Show()
Me.Hide()
End If
End If
Catch ex As Exception
If txtusername.Text = "admin" And txtpass.Text = "admin" Then
fmshop.tsmadmin.Visible = True
fmshop.Show()
txtusername.Text = ""
txtpass.Text = ""
Me.Hide()
Else
MsgBox("คุณไม่มีสิทธิ์เข้าใช้ระบบนะครับ T-T")
End If
Exit Sub
conn.Close()
End Try
End Sub
End Class