Imports MySql.Data.MySqlClient Public Class useradd Public sCon As MySqlConnection = New MySqlConnection Public sComand As MySqlDataAdapter = New MySqlDataAdapter Public ds As DataSet = New DataSet Dim scrollVal As Integer Dim pagingAdapter As MySqlDataAdapter Dim pagingDS As DataSet Dim pagingDS2 As DataSet 'Private sRecord_Count As Integer Dim conn As MySqlConnection Dim cmd As MySqlCommand Dim dr As MySqlDataReader Private Sub User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call Fillist() End Sub Private Sub conns() Try conn = New MySqlConnection("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706") conn.Open() Catch ex As Exception MessageBox.Show("Please Close to finish update 5 seconds & Open the program again. Or contact the programmer", "Loading Dashboard", MessageBoxButtons.OK, MessageBoxIcon.Error) End End Try End Sub Sub Fillist() 'eluser,elpass,elrole conns() cmd = New MySqlCommand("SELECT * FROM elusersdb", conn) dr = cmd.ExecuteReader ListView1.Items.Clear() While (dr.Read()) With ListView1.Items.Add(dr("eluser")) .Subitems.add(dr("eluser")) .Subitems.add(dr("elpass")) .Subitems.add(dr("elrole")) End With End While dr.Close() conclos() conn.Close() End Sub Private Function Encrypt(ByVal s As String, ByVal v As Long) As String Dim tmp As String Dim total As String For i = 1 To Len(s) tmp = Mid(s, i, 1) tmp = Asc(tmp) + v tmp = Chr(tmp) total = total & tmp Next i Encrypt = total End Function Private Function Decrypt(ByVal s As String, ByVal v As Long) As String Dim tmp As String Dim total As String For i = 1 To Len(s) tmp = Mid(s, i, 1) tmp = Asc(tmp) - v tmp = Chr(tmp) total = total & tmp Next i Decrypt = total End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If txtname.Text = "" Or txtuser.Text = "" Or txtpas.Text = "" Or cmbLevel.Text = "" Then MsgBox("Please fill all information.", MsgBoxStyle.Critical, "Fill") txtname.Focus() Else If txtpas.TextLength <= 5 Then MsgBox("Password must be 6 or more characters", MsgBoxStyle.Critical, "Password") txtpas.Focus() txtcon.Text = "" Else If txtpas.Text = txtcon.Text Then Call SaveData() Call ClearData() Call Fillist() Else MsgBox("Password not match, please check your password.", MsgBoxStyle.Critical, "Password") txtcon.Text = "" txtpas.Focus() End If End If End If CheckBox1.Checked = False End Sub Private Sub SaveData() conns() cmd = New MySqlCommand("Insert into elusersdb (eluser,elpass,elrole) Values ('" & txtuser.Text & "', '" & Encryptel(txtpas.Text, 1) & "'," _ & "'" & cmbLevel.Text & "')", conn) cmd.ExecuteNonQuery() conclos() End Sub Private Sub ClearData() txtcon.Text = "" txtname.Text = "" txtpas.Text = "" txtuser.Text = "" cmbLevel.Text = "" CheckBox1.Enabled = False End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Call Fillist() Call ClearData() txtname.Focus() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If txtpas.TextLength <= 5 Then MsgBox("Password must be 6 or more characters", MsgBoxStyle.Critical, "Password") txtpas.Focus() txtcon.Text = "" Else If txtpas.Text = txtcon.Text Then conns() cmd = New MySqlCommand("Update elusersdb set eluser = '" & txtname.Text & "'," _ & "elpass ='" & Encryptel(txtcon.Text, 1) & "', elrole ='" & cmbLevel.Text & "' where eluser = '" & txtuser.Text & "'", conn) cmd.ExecuteNonQuery() Call Fillist() Else MsgBox("Password not match, please check your password.", MsgBoxStyle.Critical, "Password") txtcon.Text = "" txtpas.Focus() End If End If CheckBox1.Checked = False conclos() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If MsgBox("Are you sure do you want to delete?", CType(MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Exclamation, MsgBoxStyle), "Delete") = MsgBoxResult.Yes Then Call conns() cmd = New MySqlCommand("Delete from elusersdb where eluser = '" & txtuser.Text & "'", conn) cmd.ExecuteNonQuery() MsgBox("User Successfully Deleted", MsgBoxStyle.Information, "Deleted") Call ClearData() Call Fillist() End If CheckBox1.Checked = False conclos() End Sub Private Sub ListView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick With ListView1.SelectedItems(0) txtname.Text = .SubItems(0).Text txtuser.Text = .SubItems(1).Text txtpas.Text = .SubItems(2).Text txtcon.Text = .SubItems(2).Text cmbLevel.Text = .SubItems(3).Text End With CheckBox1.Enabled = True CheckBox1.Checked = False End Sub 'Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click ' Dim pass As String ' pass = txtpas.Text ' MsgBox("Username: " & txtuser.Text & "; Password: " & Decryptel(pass, 1), MsgBoxStyle.Information, "User Account") 'End Sub Private Sub CheckBox1_CheckedChanged_1(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged If CheckBox1.Checked Then On Error Resume Next Call conns() cmd = New MySqlCommand("Select * from elusersdb where eluser= '" & txtuser.Text & "' and elpass = '" & Decryptel(txtpas.Text, 1) & "'", conn) dr = cmd.ExecuteReader If (dr.Read()) Then txtpas.Text = dr("Password") txtcon.Text = dr("Password") End If Dim pass, pass2 As String pass = txtpas.Text pass2 = txtcon.Text txtpas.Text = Decryptel(pass, 1) txtcon.Text = Decryptel(pass2, 1) txtpas.PasswordChar = Nothing txtcon.PasswordChar = Nothing Else Dim pass, pass2 As String pass = txtpas.Text pass2 = txtcon.Text txtpas.Text = Encryptel(pass, 1) txtpas.PasswordChar = "*" txtcon.Text = Encryptel(pass2, 1) txtcon.PasswordChar = "*" End If conclos() End Sub End Class