Imports System.IO Imports MySql.Data.MySqlClient Imports System.Text Public Class updatemasterlist Public sCon As MySqlConnection = New MySqlConnection Public sComand As MySqlDataAdapter = New MySqlDataAdapter Public ds As DataSet = New DataSet Dim table As New DataTable() 'Dim conn As MySqlConnection Dim cmd As MySqlCommand Dim dr As MySqlDataReader Dim scrollVal As Integer Dim pagingAdapter As MySqlDataAdapter Dim pagingDS As DataSet Dim pagingDS2 As DataSet Dim connectionString As New MySqlConnection("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706") '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 ' MsgBox(ex.Message) ' End Try 'End Sub Private Sub hhldata_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed conn1.Close() conn1.Dispose() connectionString.Close() connectionString.Dispose() MySqlConnection.ClearAllPools() End Sub Private Sub updatemasterlist_Load(sender As Object, e As EventArgs) Handles MyBase.Load Call conns() table.Columns.Add("No.", Type.GetType("System.String")) table.Columns.Add("Name", Type.GetType("System.String")) table.Columns.Add("Address", Type.GetType("System.String")) 'table.Columns.Add("Birthday", Type.GetType("System.String")) 'table.Columns.Add("Gender", Type.GetType("System.String")) 'table.Columns.Add("Precinct", Type.GetType("System.String")) 'table.Columns.Add("Status", Type.GetType("System.String")) 'table.Columns.Add("Last Name", Type.GetType("System.String")) 'table.Columns.Add("Age", Type.GetType("System.Int32")) ' set the datatable as datasource DataGridView1.DataSource = table selectbargy2() conn1.Close() conn1.Dispose() connectionString.Close() connectionString.Dispose() MySqlConnection.ClearAllPools() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'savedata() End Sub Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click 'savedata2() saveBCCofPCC() End Sub Private Sub saveBCCofPCC() Try Dim connection As New MySqlConnection Dim command As New MySqlCommand connection.ConnectionString = "server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706" command.CommandText = "INSERT INTO bccofpcc (pccidno, bccname) VALUES (@d1,@d2)" command.Parameters.Add("@d1", MySqlDbType.VarChar) command.Parameters.Add("@d2", MySqlDbType.VarChar) 'command.Parameters.Add("@d3", MySqlDbType.VarChar) 'command.Parameters.Add("@d4", MySqlDbType.VarChar) 'command.Parameters.Add("@d5", MySqlDbType.VarChar) 'command.Parameters.Add("@d6", MySqlDbType.VarChar) ''command.Parameters.Add("@d7", MySqlDbType.VarChar) connection.Open() command.Connection = connection For i As Integer = 0 To DataGridView1.Rows.Count - 1 'command.Parameters.AddWithValue("@name1", DataGridView1.Rows(i).Cells(0).Value) 'command.Parameters.AddWithValue("@idno1", DataGridView1.Rows(i).Cells(1).Value) command.Parameters("@d1").Value = DataGridView1.Rows(i).Cells(0).Value command.Parameters("@d2").Value = DataGridView1.Rows(i).Cells(4).Value 'command.Parameters("@d3").Value = DataGridView1.Rows(i).Cells(2).Value 'command.Parameters("@d4").Value = DataGridView1.Rows(i).Cells(3).Value 'command.Parameters("@d5").Value = ComboBox1.Text 'command.Parameters("@d6").Value = TextBox1.Text 'command.Parameters(6).Value = DataGridView1.Rows(i).Cells(0).Value command.ExecuteNonQuery() Next MessageBox.Show("Rows saved successfully") Catch ex As Exception MsgBox(ex.Message) Finally End Try conn1.Close() conn1.Dispose() End Sub Private Sub savedata2() Try Dim connection As New MySqlConnection Dim command As New MySqlCommand connection.ConnectionString = "server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706" command.CommandText = "INSERT INTO masterlist2 (vno, vlegend, vname, vaddress, vbarangay, vprecintno) VALUES (@d1,@d2,@d3,@d4,@d5,@d6)" command.Parameters.Add("@d1", MySqlDbType.VarChar) command.Parameters.Add("@d2", MySqlDbType.VarChar) command.Parameters.Add("@d3", MySqlDbType.VarChar) command.Parameters.Add("@d4", MySqlDbType.VarChar) command.Parameters.Add("@d5", MySqlDbType.VarChar) command.Parameters.Add("@d6", MySqlDbType.VarChar) 'command.Parameters.Add("@d7", MySqlDbType.VarChar) connection.Open() command.Connection = connection For i As Integer = 0 To DataGridView1.Rows.Count - 1 'command.Parameters.AddWithValue("@name1", DataGridView1.Rows(i).Cells(0).Value) 'command.Parameters.AddWithValue("@idno1", DataGridView1.Rows(i).Cells(1).Value) command.Parameters("@d1").Value = DataGridView1.Rows(i).Cells(0).Value command.Parameters("@d2").Value = DataGridView1.Rows(i).Cells(1).Value command.Parameters("@d3").Value = DataGridView1.Rows(i).Cells(2).Value command.Parameters("@d4").Value = DataGridView1.Rows(i).Cells(3).Value command.Parameters("@d5").Value = ComboBox1.Text command.Parameters("@d6").Value = TextBox1.Text 'command.Parameters(6).Value = DataGridView1.Rows(i).Cells(0).Value command.ExecuteNonQuery() Next MessageBox.Show("Rows saved successfully") Catch ex As Exception MsgBox(ex.Message) Finally End Try conn1.Close() conn1.Dispose() End Sub Private Sub selectbargy2() Dim adapter As New MySqlDataAdapter("SELECT * FROM purok ORDER BY barangay ASC", connectionString) Dim table As New DataTable() adapter.Fill(table) ComboBox1.DataSource = table ComboBox1.ValueMember = "barangay" ComboBox1.DisplayMember = "barangay" Dim lst = (From row In table.AsEnumerable Select row.Field(Of String)(2)).Distinct.ToList ComboBox1.DataSource = lst connectionString.Close() connectionString.Dispose() End Sub Private Sub update2() Call conns() cmd = New MySqlCommand("Update emplist set empphoto = '" & TextBox1.Text & "'", conn1) cmd.ExecuteNonQuery() conn1.Close() conn1.Dispose() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 'importText() importfromtable() End Sub Private Sub importfromtable() Try conns() cmd = New MySqlCommand("SELECT * FROM pco ORDER BY names ASC", conn1) cmd.ExecuteNonQuery() conn1.Close() pagingAdapter = New MySqlDataAdapter(cmd) pagingDS = New DataSet() pagingDS2 = New DataSet() conn1.Open() 'pagingAdapter.Fill(pagingDS2, "pco_table") 'pagingAdapter.Fill(pagingDS, scrollVal, 10, "pco_table") pagingAdapter.Fill(pagingDS, "pco_table") conn1.Close() DataGridView1.DataSource = pagingDS DataGridView1.DataMember = "pco_table" With DataGridView1 .Columns(0).HeaderCell.Value = "ID" .Columns(1).HeaderCell.Value = "Name" .Columns(2).HeaderCell.Value = "Purok" .Columns(3).HeaderCell.Value = "Barangay" .Columns(4).HeaderCell.Value = "BCC" .Columns(7).HeaderCell.Value = "Status" End With DataGridView1.Columns.Item("id").Visible = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.Columns.Item("names").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.Columns.Item("purok").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.Columns.Item("barangay").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.Columns.Item("bcc").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.Columns.Item("boo").Visible = False DataGridView1.Columns.Item("contact").Visible = False DataGridView1.Columns.Item("status").AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells DataGridView1.DefaultCellStyle.Font = New Font("arial", 12) 'DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill 'DataGridView1.Dock = DockStyle.Fill Catch ex As Exception ' MsgBox(ex.Message) Finally End Try conclos() End Sub Private Sub importText() Try OpenFileDialog1.Title = "Please select a file" OpenFileDialog1.InitialDirectory = "C:\Users\Administrator\Documents\2025 caraga\caraga-list of voters\2025\names export" OpenFileDialog1.Filter = "txt|*.txt" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then 'Do things here, the path is stored in openFileDialog1.Filename 'If no files were selected, openFileDialog1.Filename is "" TextBox3.Text = OpenFileDialog1.FileName End If 'Dim contents As String = System.IO.File.ReadAllText("C:\MyFile.txt", System.Text.Encoding.UTF8) Dim lines() As String Dim vals() As String ' get lines from the text file 'lines = System.IO.File.ReadAllLines("" & TextBox3.Text & "", System.Text.Encoding.UTF8) lines = System.IO.File.ReadAllLines("" & TextBox3.Text & "", System.Text.Encoding.UTF7) For i As Integer = 0 To lines.Length - 1 Step +1 ' lines vals = lines(i).ToString().Split("|") Dim row(vals.Length - 1) As String For j As Integer = 0 To vals.Length - 1 Step +1 ' columns row(j) = vals(j).Trim() Next j table.Rows.Add(row) Next i Catch ex As Exception 'MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim writer As New StreamWriter("C:\Users\Administrator\Documents\YAKI\CARAGA\caraga-list of voters\expo2\BACKUPmasterlist1.txt") For i As Integer = 0 To DataGridView1.Rows.Count - 2 Step +1 For j As Integer = 0 To DataGridView1.Columns.Count - 1 Step +1 ' if last column If j = DataGridView1.Columns.Count - 1 Then writer.Write(vbTab & DataGridView1.Rows(i).Cells(j).Value.ToString()) Else writer.Write(vbTab & DataGridView1.Rows(i).Cells(j).Value.ToString() & vbTab & "|") End If Next j writer.WriteLine("") Next i writer.Close() MessageBox.Show("Data Exported") End Sub Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click 'updateall2() 'updatenamesOnly() 'savedataNotinList() updatebccofpcc() End Sub Private Sub updatebccofpcc() For i As Integer = 0 To DataGridView1.Rows.Count - 1 Call conns() Dim cmd4 As New MySqlCommand("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706", conn1) cmd4.CommandText = "update bccofpcc SET bccbrgy = '" & DataGridView1.Rows(i).Cells(3).Value & "', bccpurok = '" & DataGridView1.Rows(i).Cells(2).Value & "' WHERE pccidno = '" & DataGridView1.Rows(i).Cells(0).Value & "' AND bccname = '" & DataGridView1.Rows(i).Cells(4).Value & "'" 'conn.Open() cmd4.ExecuteNonQuery() conclos() Next MsgBox("Successfully Updated", MsgBoxStyle.Information, "Update") End Sub Private Sub updatenamesOnly() 'For i As Integer = 0 To DataGridView1.Rows.Count - 1 ' Call conns() ' cmd = New MySqlCommand("SELECT * FROM full_data_nametes1 where name = '" & DataGridView1.Rows(i).Cells(1).Value & "' AND barangay = '" & ComboBox1.Text & "'", conn1) ' dr = cmd.ExecuteReader ' If (dr.Read) Then ' Else For i As Integer = 0 To DataGridView1.Rows.Count - 1 Call conns() Dim cmd4 As New MySqlCommand("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706", conn1) cmd4.CommandText = "update full_data_nametes1 SET name = '" & DataGridView1.Rows(i).Cells(1).Value & "' WHERE number = '" & DataGridView1.Rows(i).Cells(0).Value & "' AND barangay = '" & ComboBox1.Text & "'" 'conn.Open() cmd4.ExecuteNonQuery() conclos() Next 'MsgBox("Successfully Updated", MsgBoxStyle.Information, "Update") 'findletters() 'End If 'Next '=============================================================== 'Try ' For i As Integer = 0 To DataGridView1.Rows.Count - 1 ' Call conns() ' cmd = New MySqlCommand("SELECT * FROM full_data_nametes1 where name = '" & DataGridView1.Rows(i).Cells(1).Value & "' AND barangay = '" & ComboBox1.Text & "'", conn1) ' dr = cmd.ExecuteReader ' If (dr.Read) Then ' 'MessageBox.Show("Rows match") ' conn1.Close() ' 'dr.Close() ' Call conns() ' Dim cmd4 As New MySqlCommand("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706", conn1) ' cmd4.CommandText = "update full_data_nametes1 SET name = '" & DataGridView1.Rows(i).Cells(1).Value & "' WHERE name = '" & DataGridView1.Rows(i).Cells(1).Value & "' AND barangay = '" & ComboBox1.Text & "'" ' 'conn.Open() ' cmd4.ExecuteNonQuery() ' 'conn.Close() ' 'MessageBox.Show("NAME ALREADY IN PCC", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error) ' Else ' 'dr.Close() ' 'savedataNotinList() ' End If ' dr.Close() ' conclos() ' Next ' MessageBox.Show("Rows updated successfully") 'Catch ex As Exception ' MsgBox(ex.Message) 'Finally ' conn1.Close() ' conn1.Dispose() 'End Try End Sub Private Sub savedataNotinList() Try For i As Integer = 0 To DataGridView1.Rows.Count - 1 Call conns() cmd = New MySqlCommand("SELECT * FROM full_data_nametes1 where number = '" & DataGridView1.Rows(i).Cells(0).Value & "' AND barangay = '" & ComboBox1.Text & "'", conn1) dr = cmd.ExecuteReader If (dr.Read) Then Else Dim connection As New MySqlConnection Dim command As New MySqlCommand connection.ConnectionString = "server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706" command.CommandText = "INSERT INTO full_data_nametes1 ( number, name, address, birthday, Gender, precinct_number, barangay) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7)" command.Parameters.Add("@d1", MySqlDbType.VarChar) command.Parameters.Add("@d2", MySqlDbType.VarChar) command.Parameters.Add("@d3", MySqlDbType.VarChar) command.Parameters.Add("@d4", MySqlDbType.VarChar) command.Parameters.Add("@d5", MySqlDbType.VarChar) command.Parameters.Add("@d6", MySqlDbType.VarChar) command.Parameters.Add("@d7", MySqlDbType.VarChar) connection.Open() command.Connection = connection 'command.Parameters.AddWithValue("@name1", DataGridView1.Rows(i).Cells(0).Value) 'command.Parameters.AddWithValue("@idno1", DataGridView1.Rows(i).Cells(1).Value) command.Parameters("@d1").Value = DataGridView1.Rows(i).Cells(0).Value command.Parameters("@d2").Value = DataGridView1.Rows(i).Cells(1).Value command.Parameters("@d3").Value = DataGridView1.Rows(i).Cells(2).Value command.Parameters("@d4").Value = DataGridView1.Rows(i).Cells(3).Value command.Parameters("@d5").Value = DataGridView1.Rows(i).Cells(4).Value command.Parameters("@d6").Value = DataGridView1.Rows(i).Cells(5).Value command.Parameters("@d7").Value = ComboBox1.Text command.ExecuteNonQuery() connection.Close() End If Next dr.Close() conn1.Close() MessageBox.Show("Rows saved successfully") Catch ex As Exception MsgBox(ex.Message) Finally conn1.Close() conn1.Dispose() End Try End Sub Private Sub updateall2() Try For i As Integer = 0 To DataGridView1.Rows.Count - 1 Call conns() cmd = New MySqlCommand("SELECT * FROM masterlist2 where vname = '" & DataGridView1.Rows(i).Cells(2).Value & "'", conn1) dr = cmd.ExecuteReader If (dr.Read) Then 'MessageBox.Show("Rows match") 'conn.Close() dr.Close() Dim cmd4 As New MySqlCommand("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706", conn1) cmd4.CommandText = "update masterlist2 set vprecintno='" & TextBox1.Text & "' where vname = '" & DataGridView1.Rows(i).Cells(2).Value & "'" 'conn.Open() cmd4.ExecuteNonQuery() 'conn.Close() ' MessageBox.Show("NAME ALREADY IN PCC", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr.Close() savedata() End If conclos() Next MessageBox.Show("Rows updated successfully") Catch ex As Exception MsgBox(ex.Message) Finally conn1.Close() conn1.Dispose() End Try End Sub Private Sub addnum() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click 'update2() 'updateall() End Sub Private Sub loaddataa() End Sub Private Sub updateall() Try For i As Integer = 0 To DataGridView1.Rows.Count - 1 Call conns() cmd = New MySqlCommand("SELECT * FROM full_data where name LIKE '%" & DataGridView1.Rows(i).Cells(1).Value & "%'", conn1) dr = cmd.ExecuteReader If (dr.Read) Then 'MessageBox.Show("Rows match") 'conn.Close() dr.Close() Dim cmd4 As New MySqlCommand("server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706", conn1) cmd4.CommandText = "update full_data set address='" & DataGridView1.Rows(i).Cells(2).Value & "',birthday='" & DataGridView1.Rows(i).Cells(3).Value & "',Gender='" & DataGridView1.Rows(i).Cells(4).Value & "',precinct_number='" & DataGridView1.Rows(i).Cells(5).Value & "' where name='" & DataGridView1.Rows(i).Cells(1).Value & "'" 'conn.Open() cmd4.ExecuteNonQuery() 'conn.Close() ' MessageBox.Show("NAME ALREADY IN PCC", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error) Else dr.Close() savedata() End If Next MessageBox.Show("Rows updated successfully") Catch ex As Exception MsgBox(ex.Message) Finally conn1.Close() conn1.Dispose() End Try End Sub Private Sub savedata() Try Dim connection As New MySqlConnection Dim command As New MySqlCommand connection.ConnectionString = "server=10.10.0.6;user id=corpadmin;password=admincorp2024;database=caragavotersdb;port=3706" command.CommandText = "INSERT INTO full_data (name, address, birthday, Gender, precinct_number, barangay, number) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7)" command.Parameters.Add("@d1", MySqlDbType.VarChar) command.Parameters.Add("@d2", MySqlDbType.VarChar) command.Parameters.Add("@d3", MySqlDbType.VarChar) command.Parameters.Add("@d4", MySqlDbType.VarChar) command.Parameters.Add("@d5", MySqlDbType.VarChar) command.Parameters.Add("@d6", MySqlDbType.VarChar) command.Parameters.Add("@d7", MySqlDbType.VarChar) connection.Open() command.Connection = connection For i As Integer = 0 To DataGridView1.Rows.Count - 1 'command.Parameters.AddWithValue("@name1", DataGridView1.Rows(i).Cells(0).Value) 'command.Parameters.AddWithValue("@idno1", DataGridView1.Rows(i).Cells(1).Value) command.Parameters(0).Value = DataGridView1.Rows(i).Cells(1).Value command.Parameters(1).Value = DataGridView1.Rows(i).Cells(2).Value command.Parameters(2).Value = DataGridView1.Rows(i).Cells(3).Value command.Parameters(3).Value = DataGridView1.Rows(i).Cells(4).Value command.Parameters(4).Value = DataGridView1.Rows(i).Cells(5).Value command.Parameters(5).Value = ComboBox1.Text command.Parameters(6).Value = DataGridView1.Rows(i).Cells(0).Value command.ExecuteNonQuery() Next MessageBox.Show("Rows saved successfully") Catch ex As Exception MsgBox(ex.Message) Finally conn1.Close() conn1.Dispose() End Try End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click MasterlistandOldList.Show() End Sub Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.DoubleClick ' Dim OpenFileDialog1 As FileDialog OpenFileDialog1.InitialDirectory = "c:\" OpenFileDialog1.Filter = "Document files (*.txt)|*.txt|All files (*.*)|*.*" OpenFileDialog1.FilterIndex = 2 OpenFileDialog1.RestoreDirectory = True OpenFileDialog1.Title = "Open a Text File" OpenFileDialog1.ShowDialog() 'TextBox3.Text = OpenFileDialog1.FileName.ToString TextBox3.Text = New FileInfo(OpenFileDialog1.FileName).Name End Sub Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click DataGridView1.DataSource.clear() End Sub Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click List_of_X.Show() End Sub Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click UpdateLetterInNames.Show() End Sub Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click cardNoAssign.Show() End Sub End Class