Code:
Imports MySql.Data.MySqlClient
Public Class loginForm
Public conn As MySqlConnection
Private Sub loginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginButton.Click
conn = New MySqlConnection(ServerString)
Select Case ComboBox1.Text
Case "Normal Member"
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Please fill up all the fields.", MsgBoxStyle.Information, "Error")
Else
Me.Cursor = Cursors.AppStarting
Try
conn.Open()
Dim sqlquery As String = "SELECT * FROM reg_members"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() = True Then
If Not data(1).ToString = txtUsername.Text Then
MsgBox("Login Failed. Account doesn't exist. Please register to log in.", MsgBoxStyle.Critical, "Error")
Else
If data(2).ToString = txtPassword.Text Then
MsgBox("You have successfully logged in.", MsgBoxStyle.Information, "Login Successful")
Me.Close()
normalMemberForm.Show()
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End If
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End While
Catch ex As Exception
End Try
End If
Case "Official Member"
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Please fill up all the fields.", MsgBoxStyle.Information, "Error")
Else
Me.Cursor = Cursors.AppStarting
Try
conn.Open()
Dim sqlquery As String = "SELECT * FROM off_members"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() = True Then
If Not data(1).ToString = txtUsername.Text Then
MsgBox("Login Failed. Account doesn't exist. Please register to log in.", MsgBoxStyle.Critical, "Error")
Else
If data(2).ToString = txtPassword.Text Then
MsgBox("You have successfully logged in.", MsgBoxStyle.Information, "Login Successful")
Me.Close()
officialMemberForm.Show()
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End If
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End While
Catch ex As Exception
End Try
End If
End Select
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
loginButton.Enabled = True
loginButton.Select()
End Sub
End Class