Advertisement
arlendafitranto

Frmlistpendaftar

Aug 26th, 2024 (edited)
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VisualBasic 2.59 KB | Source Code | 0 0
  1. Imports MySql.Data.MySqlClient
  2. Public Class Frmlistpendaftar
  3.     Private dataTable As DataTable
  4.     Private connString As String
  5.     Private Sub BtnKeluar_Click(sender As Object, e As EventArgs) Handles BtnKeluar.Click
  6.         Application.Exit()
  7.     End Sub
  8.  
  9.     Private Sub Frmlistpendaftar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  10.         connString = "Server=localhost;Database=pendaftaran_online;User Id=root;"
  11.  
  12.         Using conn As New MySqlConnection(connString)
  13.             Try
  14.                 conn.Open()
  15.                 Dim query As String = "SELECT * FROM user"
  16.                 Dim adapter As New MySqlDataAdapter(query, conn)
  17.                 dataTable = New DataTable()
  18.                 adapter.Fill(dataTable)
  19.  
  20.                 tableUser.DataSource = dataTable
  21.             Catch ex As MySqlException
  22.                 MessageBox.Show("Terjadi kesalahan: " & ex.Message)
  23.             Finally
  24.                 ' Menutup koneksi
  25.                conn.Close()
  26.                 Console.WriteLine("Koneksi ditutup.")
  27.             End Try
  28.         End Using
  29.     End Sub
  30.  
  31.     Private Sub ComboJurusan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboJurusan.SelectedIndexChanged
  32.     Dim selectedJurusan As String = ComboJurusan.SelectedItem.ToString()
  33.  
  34.     Dim foundRows As DataRow() = dataTable.Select("nama = '" & selectedJurusan & "'")
  35.  
  36.     If foundRows.Length > 0 Then
  37.         ' Mengakses nilai 'ukt' dari baris yang ditemukan
  38.        Dim ukt As Long = Convert.ToInt64(foundRows(0)("ukt"))
  39.         Dim formattedUkt As String = ukt.ToString("N0")
  40.  
  41.         labelUkt.Text = "Rp. " + formattedUkt
  42.     Else
  43.         MessageBox.Show("Data UKT tidak ditemukan untuk jurusan yang dipilih.")
  44.     End If
  45.  
  46.     ' Menampilkan semua data selain jurusan yang dipilih dalam DataGridView
  47.    Dim filteredRows As DataRow() = dataTable.Select("nama <> '" & selectedJurusan & "'")
  48.  
  49.     dataGridUkt.Visible = True
  50.     labelUktLain.Visible = True
  51.  
  52.     If filteredRows.Length > 0 Then
  53.         Dim filteredDataTable As New DataTable()
  54.         filteredDataTable = filteredRows.CopyToDataTable()
  55.  
  56.         dataGridUkt.DataSource = filteredDataTable
  57.         dataGridUkt.Columns("ukt").DefaultCellStyle.Format = "N0"
  58.  
  59.         ' Mengganti nilai kolom 'id' dengan nomor urut
  60.        Dim rowIndex As Integer = 1
  61.         For Each row As DataRow In filteredDataTable.Rows
  62.             row("id") = rowIndex
  63.             rowIndex += 1
  64.         Next
  65.     Else
  66.         dataGridUkt.DataSource = Nothing
  67.         MessageBox.Show("Tidak ada data lain untuk ditampilkan.")
  68.     End If
  69. End Sub
  70. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement