Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3.  
  4. Public Class frmLogin
  5.     'declaring the objects
  6.    Dim connLogin As New SQLConn()
  7.     Dim varCounter As Integer
  8.  
  9.     Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
  10.         If Not (txtUsername.Text = "" Or txtPassword.Text = "") Then 'check if txtbox is empty
  11.            If varCounter = 4 Then 'check if number of tries is 4
  12.                MsgBox("You have reached the allowed number of tries. The program is now shutting down.", MsgBoxStyle.Exclamation)
  13.                 Me.Close()
  14.             Else
  15.                 connLogin.Open() 'Open database
  16.                'read from database
  17.                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)
  18.                 Dim r As SqlDataReader = connLIcmd.ExecuteReader()
  19.  
  20.                 If r.HasRows = 0 Then
  21.                     MsgBox("Either username or password is incorrect. Please try again.", MsgBoxStyle.Exclamation) 'display error msg
  22.                    r.Close() 'close reader
  23.                    varCounter += 1 'add 1 to counter
  24.  
  25.                     txtUsername.Text = "" 'reset login form
  26.                    txtPassword.Text = ""
  27.                     txtUsername.Focus()
  28.                 Else
  29.                     r.Close() 'close reader
  30.                    connLogin.Close() 'close database
  31.  
  32.                     txtUsername.Text = "" 'reset login form
  33.                    txtPassword.Text = ""
  34.                     txtUsername.Focus()
  35.  
  36.                     'hide login form and show main form
  37.                    Dim frmCopy As New frmMain
  38.                     frmCopy.Owner = Me
  39.                     frmCopy.Show()
  40.                     Me.Hide()
  41.                 End If
  42.             End If
  43.         Else
  44.             MsgBox("Please fill in the required fields.", MsgBoxStyle.Exclamation) 'display error msg
  45.            varCounter += 1
  46.         End If
  47.     End Sub
  48.  
  49.     Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  50.         'close database and program
  51.        connLogin.Close()
  52.         Me.Close()
  53.     End Sub
  54.  
  55.     Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  56.         varCounter = 0 'set counter to 0
  57.    End Sub
  58. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement