Imports System.Data.SqlClient
Public Class ChangePass
    Public Sub Userlog()
        Dim dd As String
        dd = Now.Date
        Try
            Call opencon()
            Dim myd As New SqlDataAdapter
            With myd
                .InsertCommand = New SqlCommand
                .InsertCommand.CommandText = "INSERT INTO loy(datte,uname,action)VALUES(@datte,@uname,@action) "
                .InsertCommand.Connection = con
                With .InsertCommand.Parameters
                    .AddWithValue("@datte", dd)
                    .AddWithValue("@uname", logger)
                    .AddWithValue("@action", action)
                End With
                .InsertCommand.ExecuteNonQuery()
            End With
            Call closecon()
        Catch ex As Exception
            MsgBox(ex.Message)
            Call closecon()
        End Try
    End Sub
    Private Sub btn_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
       
    End Sub

    Private Sub ChangePass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.txtname.Text = nam
        If Me.txtname.Text.Length = 0 Then
            Me.txtname.ReadOnly = False
        End If
    End Sub


    Private Sub txtconf_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs)
       
    End Sub

    Private Sub btn_Refresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      
    End Sub

    Private Sub btn_close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub btn_Add_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Add.Click
        Try
            Call opencon()
            Dim myda As New SqlDataAdapter
            With myda
                .SelectCommand = New SqlCommand
                .SelectCommand.CommandText = "SELECT * FROM login WHERE username LIKE '%%" & Me.txtname.Text & "%%'"
                .SelectCommand.Connection = con
            End With
            Dim dr As New DataSet
            myda.Fill(dr, "myTable")
            If dr.Tables("myTable").Rows.Count > 0 Then

            Else
                Me.txtname.ReadOnly = False
                Me.txtname.Focus()
                Me.txtname.SelectAll()
                Call closecon()
                MsgBox("Username does not exist", MsgBoxStyle.Exclamation, "WARNING")
                Exit Sub
            End If


        Catch ex As Exception
            MsgBox(ex.Message)
            Call closecon()
        End Try
        Try
            Call opencon()
            Dim myd2 As New SqlDataAdapter
            With myd2
                .UpdateCommand = New SqlCommand
                .UpdateCommand.CommandText = "UPDATE login SET [password] = @password WHERE username LIKE '%%" & Me.txtname.Text & "%%'"
                .UpdateCommand.Connection = con
                With .UpdateCommand.Parameters
                    .AddWithValue("@password", Me.txtpass.Text)
                End With
                .UpdateCommand.ExecuteNonQuery()
            End With
           
            MsgBox("Password successfully updated....", MsgBoxStyle.Information, "ALERT INFO")
            Call closecon()
        Catch ex As Exception
            MsgBox(ex.Message)
            Call closecon()
        End Try
    End Sub

    Private Sub btn_Refresh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Refresh.Click
        Me.txtconf.Clear()
        Me.txtpass.Clear()
    End Sub

    Private Sub txtpass_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpass.TextChanged

    End Sub

    Private Sub txtconf_LostFocus1(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtconf.LostFocus
        If Me.txtpass.Text = Me.txtconf.Text Then

        Else
            MsgBox("Password do not match....", MsgBoxStyle.Exclamation, "WARNING")
            txtconf.Focus()
            txtconf.SelectAll()
        End If
    End Sub

    Private Sub txtconf_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtconf.TextChanged

    End Sub

    Private Sub Label8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click
        Me.Close()
    End Sub
End Class