Public Class AddUser

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

        If txtname.Text = Nothing Then

            MsgBox("Name is required", MsgBoxStyle.OkCancel)

        ElseIf txtlastname.Text = Nothing Then

            MsgBox("Last Name is required", MsgBoxStyle.OkCancel)

        ElseIf txtmname.Text = Nothing Then

            MsgBox("Middle Name is required", MsgBoxStyle.OkCancel)

        ElseIf txtusername.Text = Nothing Then

            MsgBox("UserName is required", MsgBoxStyle.OkCancel)

        Else

            If txtpasswor.Text = Nothing And confirm.Text = Nothing Then

                MsgBox("Username or Password missing, please enter Username/Password")

                txtpasswor.Text = ""
                confirm.Text = ""

            Else

                If txtpasswor.Text = confirm.Text Then

                    sql_add = "INSERT INTO Table1 (NameOfUser, MiddleNameOfUser, LastNameOfUser, UserUserName, UserPassword) values ('" & txtlastname.Text & "' , '" & txtmname.Text & "' , '" & txtname.Text & "' ,'" & txtusername.Text & "' ,'" & txtpasswor.Text & "')"

                    mySQL(sql_add)

                    MsgBox("New user has been added to your database.")


                    sql_display = "SELECT Table1.User_ID as [User ID], Table1.NameOfUser as [Name], Table1.MiddleNameOfUser as [Middle Name], Table1.LastNameOfUser as [Last Name], Table1.UserUserName as [Username] FROM Table1"

                    mySQL_new(sql_display, DataGridView1)

                    cleartext(GroupBox2, "txt")

                    Me.Hide()

                Else

                    MsgBox("Password did not match.")

                    txtpasswor.Text = ""
                    confirm.Text = ""

                End If

            End If

        End If

    End Sub

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

        cleartext(GroupBox2, "txt")


    End Sub

   

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

        btnsave.Show()
        DataGridView1.Show()

        sql_display = "SELECT Table1.User_ID as [User ID], Table1.NameOfUser as [Name], Table1.MiddleNameOfUser as [Middle Name], Table1.LastNameOfUser as [Last Name], Table1.UserUserName as [Username] FROM Table1"

        mySQL_new(sql_display, DataGridView1)


    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        DataGridView1.Show()

        sql_display = "SELECT Table1.User_ID as [User ID], Table1.NameOfUser as [Name], Table1.MiddleNameOfUser as [Middle Name], Table1.LastNameOfUser as [Last Name], Table1.UserUserName as [Username] FROM Table1 where Table1.NameOfUser LIKE '" & TextBox3.Text & "%'"

        mySQL_new(sql_display, DataGridView1)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ejbdelete("Delete * from Table1 where User_ID= " & lbl.Text & "")
        sql_display = "SELECT Table1.User_ID as [User ID], Table1.NameOfUser as [Name], Table1.MiddleNameOfUser as [Middle Name], Table1.LastNameOfUser as [Last Name], Table1.UserUserName as [Username] FROM Table1"

        mySQL_new(sql_display, DataGridView1)
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        lbl.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString
        txtname.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString
        txtmname.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString
        txtlastname.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString
        txtusername.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If txtpasswor.Text = Nothing And confirm.Text = Nothing Then

            MsgBox("Username or Password missing, please enter Username/Password")

        Else

            If txtpasswor.Text = confirm.Text Then

                ejbupdate("UPDATE Table1 set NameOfUser ='" & txtname.Text & "' , MiddleNameOfUser = '" & txtmname.Text & "', LastNameOfUser = '" & txtlastname.Text & _
                          "', UserUserName = '" & txtusername.Text & "', UserPassword = '" & txtpasswor.Text & _
                         "' where User_ID = " & lbl.Text & "")

                cleartext(GroupBox2, "txt")





                sql_display = "SELECT Table1.User_ID as [User ID], Table1.NameOfUser as [Name], Table1.MiddleNameOfUser as [Middle Name], Table1.LastNameOfUser as [Last Name], Table1.UserUserName as [Username] FROM Table1"

                mySQL_new(sql_display, DataGridView1)

            Else

                MsgBox("Password did not match.")

                txtpasswor.Text = ""
                confirm.Text = ""

                Button1.Enabled = True

            End If

        End If
    End Sub
End Class