Public Class manageuser

    Private Sub chkShowpass_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowpass.CheckedChanged
        Try
            If chkShowpass.CheckState = CheckState.Checked Then
                txtpass.UseSystemPasswordChar = False
            Else
                txtpass.UseSystemPasswordChar = True
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub tstripList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tstripList.Click
        Try
            Panel1.BringToFront()
            Panel2.SendToBack()
            sql = "SELECT userid as Id,uname as Name,emailadd as EmailAddress,username as Username, utype as Type FROM  tbluser  "
            EmployeeDTG(sql, dtglist)
            clearAll(GroupBox1)
        Catch ex As Exception
            Me.Text = ex.Message
        End Try
    End Sub

    Private Sub tstripAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tstripAdd.Click
        Try
            Panel1.SendToBack()
            Panel2.BringToFront()
            clearAll(GroupBox1)
        Catch ex As Exception
            Me.Text = ex.Message
        End Try
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Try
            sql = "SELECT * FROM tbluser WHERE userid='" & txtId.Text & "'"
            EmployeeTXT(sql)

            If dt.Rows(0).Item("userid") = txtId.Text Then
                sql = "UPDATE tbluser SET uname='" & txtname.Text & "',emailadd='" & txtemail.Text & _
                  "',username='" & txtusername.Text & "',upass='" & txtpass.Text & "',utype='" & cboType.Text & _
                  "' WHERE userid ='" & txtId.Text & "'"
                EmployeeCUD(sql)
                MsgBox("User has been updated.", , "UPDATE")

            End If
            clearAll(GroupBox1)
            autonumber()
        Catch ex As Exception 
            sql = "INSERT INTO tbluser (userid,uname,emailadd,username,upass,utype)" & _
               " VALUES ('" & txtId.Text & "','" & txtname.Text & "','" & txtemail.Text & _
               "','" & txtusername.Text & "','" & txtpass.Text & "','" & cboType.Text & "')"
            EmployeeCUD(sql)
            MsgBox("User has been saved.", , "SAVE")
            clearAll(GroupBox1)
            autonumber()
        End Try
    End Sub

    Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
        sql = "SELECT userid as Id,uname as Name,emailadd as EmailAddress,username as Username, utype as Type" & _
        " FROM  tbluser  WHERE userid Like '%" & txtsearch.Text & "%'"
        EmployeeDTG(sql, dtglist)
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Try
            Panel1.SendToBack()
            Panel2.BringToFront()
            txtId.Text = dtglist.CurrentRow.Cells(0).Value
            sql = "SELECT * FROM tbluser WHERE userid ='" & txtId.Text & "'"
            EmployeeTXT(sql)

            With dt.Rows(0)
                txtname.Text = .Item("uname")
                txtemail.Text = .Item("emailadd")
                txtusername.Text = .Item("username")
                txtpass.Text = .Item("upass")
                cboType.Text = .Item("utype")
            End With
        Catch ex As Exception
            Me.Text = ex.Message
        End Try
    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        Try
            sql = "DELETE * FROM tbluser WHERE userid ='" & dtglist.CurrentRow.Cells(0).Value & "'"
            EmployeeCUD(sql)
            MsgBox("User has been deleted.", , "DELETE")
            autonumber()
            Call tstripList_Click(sender, e)
        Catch ex As Exception
            Me.Text = ex.Message
        End Try
    End Sub
    Private Sub autonumber()
        sql = "SELECT * FROM tbluser"
        EmployeeTXT(sql)
        txtId.Text = "user" & dt.Rows.Count - 1
    End Sub
    Private Sub manageuser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtId.Enabled = False
        Call tstripList_Click(sender, e)
        autonumber()
    End Sub

    Private Sub ToolStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles ToolStrip1.ItemClicked

    End Sub
End Class