Sunday, September 7, 2014

Ricky Andes || Setelah membuat  form input mahasiswa tahap ke - 3 adalah membuat form mencari mahasiswa yang telah tersimpan di database yg sudah kita buat sebelumnya.
Desain form - nya seperti di bawah ini :
klik gambar untuk memperbesar
untuk coding seperti biasa sudah ane siapin gan heheheh Cekidhoooot..

Imports System.Data.OleDb
Imports System.Data
Public Class Cari_MHS
    Public colnpm, colnama, colalamat, coljekel, coltgl_daftar, colmijus As String
    Dim cnn As OleDbConnection
    Dim cmmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim ds1 As New DataSet
    Dim dv1 As New DataView
    Sub Clear_data()
        While Val(Counter.Text) > 0
            ListView1.Items(0).Remove()
            Counter.Text = Val(Counter.Text) - 1

        End While
    End Sub
    Private Sub pilih()
        Try

            colnpm = ListView1.SelectedItems(0).SubItems(0).Text.ToString
            colnama = ListView1.SelectedItems(0).SubItems(1).Text.ToString
            coljekel = ListView1.SelectedItems(0).SubItems(2).Text.ToString
            colalamat = ListView1.SelectedItems(0).SubItems(3).Text.ToString
            coltgl_daftar = ListView1.SelectedItems(0).SubItems(4).Text.ToString
            colmijus = ListView1.SelectedItems(0).SubItems(5).Text.ToString
            If Btnok.Capture = True Then
                Tampil.Show()

            End If


        Catch ex As Exception
            MsgBox("Anda belum memilih", MsgBoxStyle.Information)

        End Try
    End Sub
    Private Sub pilih1()
        Try

            colnpm = ListView1.SelectedItems(0).SubItems(0).Text.ToString
            colnama = ListView1.SelectedItems(0).SubItems(1).Text.ToString
            coljekel = ListView1.SelectedItems(0).SubItems(2).Text.ToString
            colalamat = ListView1.SelectedItems(0).SubItems(3).Text.ToString
            coltgl_daftar = ListView1.SelectedItems(0).SubItems(4).Text.ToString
            colmijus = ListView1.SelectedItems(0).SubItems(5).Text.ToString
            Tampil.Show()


        Catch ex As Exception
            MsgBox("Anda belum memilih", MsgBoxStyle.Information)

        End Try
    End Sub
    Public Sub List_data()
        Clear_data()

        Dim sqlx As String
        Dim x As Integer

        sqlx = "select * from mhs where npm like '%" & Trim(txtmahasiswa.Text) & "%' or nama like '%" & Trim(txtmahasiswa.Text) & _
        "%' or jekel like '%" & Trim(txtmahasiswa.Text) & "%' or alamat like '%" & Trim(txtmahasiswa.Text) & "%' or tgl_daftar like '%" & Trim(txtmahasiswa.Text) & "%' or mijus like '%" & Trim(txtmahasiswa.Text) & "%'"

        cnn = New OleDbConnection(KONEKSI)
        If cnn.State <> ConnectionState.Closed Then cnn.Close()
        cnn.Open()
        cmmd = New OleDbCommand(sqlx, cnn)
        dr = cmmd.ExecuteReader
        Try

            While dr.Read = True
                x = Val(Counter.Text)
                Counter.Text = Str(Val(Counter.Text) + 1) & "record"

                With ListView1
                    .Items.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                    .Items(ListView1.Items.Count - 1).SubItems.Add("")
                  
                    .Items(x).SubItems(0).Text = dr.GetString(0)
                    .Items(x).SubItems(1).Text = dr.GetString(1)
                    .Items(x).SubItems(2).Text = dr.GetString(2)
                    .Items(x).SubItems(3).Text = dr.GetString(3)
                    .Items(x).SubItems(4).Text = dr.GetValue(4)
                    .Items(x).SubItems(5).Text = dr.GetString(5)



                End With
            End While
        Finally
            dr.Close()

        End Try
        cnn.Close()

    End Sub


    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

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

    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.SelectedIndices.Count > 0 Then
            Dim itemNo As Integer = ListView1.SelectedIndices(0)
            lblnpm.Text = ListView1.Items(itemNo).SubItems(0).Text
            lblnama.Text = ListView1.Items(itemNo).SubItems(1).Text
            lbljekel.Text = ListView1.Items(itemNo).SubItems(2).Text
            lblalamat.Text = ListView1.Items(itemNo).SubItems(3).Text
            lbltgl.Text = ListView1.Items(itemNo).SubItems(4).Text
            lblmijus.Text = ListView1.Items(itemNo).SubItems(5).Text

        End If
    End Sub

    Private Sub txtmahasiswa_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtmahasiswa.TextChanged
        Call List_data()
    End Sub

    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Tampil.txtnpm.Text = lblnpm.Text
        Tampil.txtnama.Text = lblnama.Text
        Tampil.cmbjekel.Text = lbljekel.Text
        Tampil.txtalamat.Text = lblalamat.Text
        Tampil.Dtanggal.Value = DateTimePicker1.Value
        Tampil.cmbmijus.Text = lblmijus.Text
        Tampil.Show()
    End Sub
End Class


#Semoga membantu dan terima kasih hehehe

0 comments:

Post a Comment