Wednesday, April 13, 2011

log in form(vb.net 2008)

Imports System.Data
Imports System.Data.OleDb
Imports System.Math
Public Class Loginfrm
    Dim objRead As OleDb.OleDbDataReader

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        tempun.Text = ""
        tempPass.Text = ""
        tempType.Text = ""

        If UsernameTextBox.Text = "" And PasswordTextBox.Text = "" Then
            ErrorProvider1.SetError(UsernameTextBox, "connot leave Username blank")
            ErrorProvider1.SetError(PasswordTextBox, "connot leave Password blank")
            MsgBox("Enter Username and Password !", MsgBoxStyle.Critical, "Information System")
            UsernameTextBox.Focus()

            Exit Sub
        ElseIf UsernameTextBox.Text = "" Then
            ErrorProvider1.SetError(UsernameTextBox, "connot leave Username blank")
            MsgBox("Enter Username !", MsgBoxStyle.Critical, "Information System")
            ErrorProvider1.SetError(PasswordTextBox, "")
            UsernameTextBox.Focus()
        ElseIf PasswordTextBox.Text = "" Then
            ErrorProvider1.SetError(PasswordTextBox, "connot leave Password blank")
            MsgBox("Enter Password !", MsgBoxStyle.Critical, "Information System")
            ErrorProvider1.SetError(UsernameTextBox, "")
            PasswordTextBox.Focus()
        End If
        connection_open()
        Dim str As String = "select * from tbllogin where users='" & UsernameTextBox.Text & "'"
        Dim cmd As New OleDb.OleDbCommand(str, olecon)

        objRead = cmd.ExecuteReader()
        While objRead.Read()
            tempun.Text = objRead("users")
            tempPass.Text = objRead("pass")
            tempType.Text = objRead("type")

        End While

        objRead.Close()
        connection_close()
        If tempun.Text = UsernameTextBox.Text And tempPass.Text = PasswordTextBox.Text Then
            trackuser()
            MsgBox("Your log in time is " + TimeOfDay, MsgBoxStyle.Information, "Sales System")
            mainMDIParent.Show()
            Me.Visible = False
            UsernameTextBox.Text = ""
            PasswordTextBox.Text = ""
        Else
            i += 1
            If i >= 3 Then
                MsgBox("Sorry, Application Canceled !", MsgBoxStyle.Critical, "Sales System")

                Application.Exit()

            Else
                MsgBox("Wrong Password !. Try Again !", MsgBoxStyle.Critical, "Sales System")

                PasswordTextBox.Clear()
                PasswordTextBox.Focus()
            End If
        End If
        mainMDIParent.txtuser.Text = tempun.Text
        mainMDIParent.txttype.Text = tempType.Text
    End Sub
    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Application.Exit()
    End Sub
    Private Sub PasswordTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles PasswordTextBox.KeyPress
        If e.KeyChar = Chr(13) Then
            OK.PerformClick()
        End If
    End Sub
    Private Sub trackuser()
        Dim a As Date = Now
        connection_open()
        Dim sqql As String = "INSERT INTO tbluser_transaction(users,date_timelogin) Values ('" & tempun.Text & "','" & a & "')"
        Dim cmd As New OleDb.OleDbCommand(sqql, olecon)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        connection_close()

    End Sub

    Private Sub Loginfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

No comments:

Post a Comment