Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data
- Imports System.Data.SqlClient
- Public Class frmLogin
- 'declaring the objects
- Dim connLogin As New SQLConn()
- Dim varCounter As Integer
- Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
- If Not (txtUsername.Text = "" Or txtPassword.Text = "") Then 'check if txtbox is empty
- If varCounter = 4 Then 'check if number of tries is 4
- MsgBox("You have reached the allowed number of tries. The program is now shutting down.", MsgBoxStyle.Exclamation)
- Me.Close()
- Else
- connLogin.Open() 'Open database
- 'read from database
- Dim connLIcmd As New SqlCommand("SELECT Logn_Username, Logn_Password FROM User_Login WHERE Logn_Username = '" & txtUsername.Text & "' AND Logn_Password='" & txtPassword.Text & "'", connLogin.Conn)
- Dim r As SqlDataReader = connLIcmd.ExecuteReader()
- If r.HasRows = 0 Then
- MsgBox("Either username or password is incorrect. Please try again.", MsgBoxStyle.Exclamation) 'display error msg
- r.Close() 'close reader
- varCounter += 1 'add 1 to counter
- txtUsername.Text = "" 'reset login form
- txtPassword.Text = ""
- txtUsername.Focus()
- Else
- r.Close() 'close reader
- connLogin.Close() 'close database
- txtUsername.Text = "" 'reset login form
- txtPassword.Text = ""
- txtUsername.Focus()
- 'hide login form and show main form
- Dim frmCopy As New frmMain
- frmCopy.Owner = Me
- frmCopy.Show()
- Me.Hide()
- End If
- End If
- Else
- MsgBox("Please fill in the required fields.", MsgBoxStyle.Exclamation) 'display error msg
- varCounter += 1
- End If
- End Sub
- Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- 'close database and program
- connLogin.Close()
- Me.Close()
- End Sub
- Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- varCounter = 0 'set counter to 0
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement