Sabtu, 06 Oktober 2012

Latihan 14

Deskripsi Latihan 14

1. Objek Datagridview
terdapat satu objek datagridview di dalam form ini. gunanya adalah untuk menampilkan tabel yang berisi data mahasiswa baru yang sudah diinput di dalam script

2. Objek groupbox
terdapat 4 objek groupbox di form ini. masing-masing berjudul Urutkan Berdasarkan, Filter Berdasarkan, Filter dengan Menggabungkan, & Pengaturan Warna

3. objek radiobutton
terdapat 4 objek radiobutton pada form ini. keempat objek tersebut diletakkan pada groupbox Urutkan Berdasarkan. fungsi dari masing-masing radiobutton untuk mengurutkan isi dari tabel yang ada di datagriview sesuai dengan kondisi yang diberikan pada masing-masing radiobutton.

4. objek datetimepicker
terdapat 2 objek datetimepicker di form ini. masing-masing di groupbox filter berdasarkan & groupbox filter dengan menggabungkan.

5. objek textbox
terdapat 6 objek textbox dalam form ini. textox tersebut bertujuan memasukkan syarat-syarat tertentu untuk memfilter isi dari tabel yang ada di datagridview

6. objek tombol
terdapat 2 objek tombol. masing-masing terdapat di groupbox Filter dengan Menggabungkan & groupbox pengaturan warna

even :
Form_Load, TextChanged, CheckedChanged, ButtonClick

script unik :
- script untuk memfilter data pada tabel yang ada di data grid view dengan syarat-syarat tertentu
abc.RowFilter = "GajiOrtu >=" & Val(b1_46110008.Text)
abc.RowFilter = "Kelas <> '" & b2_46110008.Text & "'"
abc.RowFilter = "TanggalLahir < #" & b3_46110008.Value.Day & "/" & b3_46110008.Value.Month & "/" & b3_46110008.Value.Year & "#"
abc.RowFilter = "Nama Like '%" & b4_46110008.Text & "%'"


Pembuatan Form
1. buka Microsoft Visual Studio anda
2. bukalah file kumpulan latihan anda
3. pilih menu project lalu klik add windows form
4. drag objek dari menu toolbox anda. susun hingga menjadi form seperti form pada gambar dibawah ini.


5. pertama-tama, buat dulu dimensi untuk DataTeble dan DataView
 Dim xxx As New DataTable
Dim abc As New DataView

6. masukkan script berikut untuk membuat tabel pada datgridview

Private Sub Latihan_14_46110008_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xxx.Columns.Add(New DataColumn("Stambuk", GetType(String)))
        xxx.Columns.Add(New DataColumn("Nama", GetType(String)))
        xxx.Columns.Add(New DataColumn("JenisKelamin", GetType(String)))
        xxx.Columns.Add(New DataColumn("TanggalLahir", GetType(String)))
        xxx.Columns.Add(New DataColumn("GajiOrtu", GetType(Double)))
        xxx.Columns.Add(New DataColumn("Kelas", GetType(String)))

        xxx.Rows.Add("46112003", "Nurawalia M", "P", "04/12/1994", 3000000, "1AD4")
        xxx.Rows.Add("46120023", "Puspita Susilawati Ridjal", "P", "01/01/1994", 4000000, "1AD4")
        xxx.Rows.Add("46110018", "Rose Anne Tarida Situmorang", "P", "01/12/1994", 5000000, "1AD4")
        xxx.Rows.Add("46112004", "Siti Khaerunnisa", "P", "28/03/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112015", "Irmayanti", "P", "23/09/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112011", "Delsi Tifani Lan", "P", "24/12/1994", 2000000, "1AD4")
        xxx.Rows.Add("46112027", "Reny Rita Waty Djafar", "P", "26/07/1993", 3000000, "1AD4")
        xxx.Rows.Add("46112002", "Dewi Sartika", "P", "10/02/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112004", "Anita Rahmah Muhtadin", "P", "07/12/1994", 5000000, "1AD4")
        xxx.Rows.Add("46112021", "Rafidah", "P", "05/06/1994", 500000, "1AD4")
        xxx.Rows.Add("46112009", "Eka Yuli Astuti", "P", "07/08/1994", 2000000, "1AD4")
        xxx.Rows.Add("46112025", "Fitri Amalia Islamiati", "P", "26/03/1995", 4000000, "1AD4")
        xxx.Rows.Add("46112014", "Mariana", "P", "22/06/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112013", "A. Muh. Lutfi Ahmad", "L", "10/10/1993", 4000000, "1AD4")
        xxx.Rows.Add("46112008", "Nanda Ardilia Pratama", "L", "01/08/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112022", "Liliani Paelongan", "P", "25/05/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112007", "Andi Rabiah", "L", "07/09/1994", 1000000, "1AD4")
        xxx.Rows.Add("46112001", "Rizka Awalia Mustakim", "P", "07/10/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112005", "Mardhotillah", "P", "13/01/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112017", "Camelia Indulgenssya Gundung", "P", "14/09/1994", 2000000, "1AD4")
        xxx.Rows.Add("46112028", "Nur Salim Rusdi", "L", "12/04/1994", 1500000, "1AD4")
        xxx.Rows.Add("46112026", "Muhammad Khaidir", "L", "26/12/1993", 3000000, "1AD4")
        xxx.Rows.Add("46112020", "Sukriani Karunia Rahma", "P", "01/12/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112006", "Rezky Tri Utami", "P", "03/07/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112029", "Azwar Arfah", "L", "03/04/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112016", "Dyah Sukma Anggraini", "P", "10/05/1994", 3500000, "1AD4")
        xxx.Rows.Add("46112010", "Nur Indah Purnamasari", "P", "22/07/1994", 2500000, "1AD4")
        xxx.Rows.Add("46112012", "Nurul Qadri Musra", "L", "24/08/1994", 3000000, "1AD4")
        xxx.Rows.Add("46112055", "Reni Anggraeni", "P", "12/10/1994", 1500000, "1BD4")
        xxx.Rows.Add("46112042", "Faradhiba Zainal Putri", "P", "04/12/1993", 3000000, "1BD4")
        xxx.Rows.Add("46112054", "Rahmi Ani", "P", "30/11/1994", 2000000, "1BD4")
        xxx.Rows.Add("46112043", "Remon Agit Rimang", "L", "06/01/1995", 3000000, "1BD4")
        xxx.Rows.Add("46112032", "Abd. Rahman", "L", "08/10/1994", 1500000, "1BD4")
        xxx.Rows.Add("46112057", "I Ketut Yuda Sadpwa", "L", "02/05/1993", 4500000, "1BD4")
        xxx.Rows.Add("46112037", "Herianto", "L", "08/12/1993", 3000000, "1BD4")
        xxx.Rows.Add("46112058", "citra amalia ramadhani", "L", "16/02/1995", 3000000, "1BD4")
        xxx.Rows.Add("46112050", "Andi Akbar", "L", "26/11/1994", 2000000, "1BD4")
        xxx.Rows.Add("46112034", "Gamaliel Giovani Rafael Nong", "L", "06/08/1993", 3700000, "1BD4")
        xxx.Rows.Add("46112047", "Hasmawati", "P", "22/11/1994", 5000000, "1BD4")
        xxx.Rows.Add("46112038", "Viorensi S", "P", "13/10/1994", 2000000, "1BD4")
        xxx.Rows.Add("46112046", "Andini Hayrunnisyah", "P", "27/06/1994", 1500000, "1BD4")
        xxx.Rows.Add("46112031", "Irmayanti", "P", "02/05/1994", 1000000, "1BD4")
        xxx.Rows.Add("46112039", "Carissa Evan Anthen", "P", "23/10/1994", 6000000, "1BD4")
        xxx.Rows.Add("46112052", "Aprianto Sandy", "L", "11/04/1993", 3000000, "1BD4")
        xxx.Rows.Add("46112049", "Muhammad Farid Syah", "L", "20/01/1995", 5000000, "1BD4")
        xxx.Rows.Add("46112033", "Maulanan Ibrahim", "L", "10/04/1994", 1000000, "1BD4")
        xxx.Rows.Add("46112035", "Herpita Tohura", "P", "24/10/1993", 700000, "1BD4")
        xxx.Rows.Add("46112048", "Udin Pranata", "L", "29/01/1993", 1000000, "1BD4")
        xxx.Rows.Add("46112051", "Afrisca Fraktiani Rante", "P", "13/04/1995", 5000000, "1BD4")
        xxx.Rows.Add("46112056", "Kartini Widyasita", "P", "21/04/1993", 4650000, "1BD4")
        xxx.Rows.Add("46112045", "Abdul Qawwam Nurjaya", "L", "26/11/1994", 3500000, "1BD4")
        xxx.Rows.Add("46112040", "Tommy Paunganan", "L", "22/02/1993", 2000000, "1BD4")
        xxx.Rows.Add("46112053", "Khusnul Khatimah A", "P", "27/08/1994", 3000000, "1BD4")
        xxx.Rows.Add("46112041", "Nida Hazimah Ulfah", "P", "24/09/1995", 5000000, "1BD4")
        xxx.Rows.Add("46112044", "Ulfah Nas", "P", "26/01/1994", 5000000, "1BD4")
        xxx.Rows.Add("46112036", "Hasmiati Hajar", "P", "17/05/1994", 5000000, "1BD4")
        xxx.Rows.Add("36112001", "Fitri", "P", "20/10/1994", 5000000, "1AD3")
        xxx.Rows.Add("36112002", "andri prianto tukan", "L", "26/04/1994", 2000000, "1BD3")
        xxx.Rows.Add("36112003", "Fathin Ammar Asidik", "L", "29/06/1994", 6800000, "1AD3")
        xxx.Rows.Add("36112004", "Endah Mariadi", "P", "07/11/1994", 7500000, "1AD3")
        xxx.Rows.Add("36112005", "Mawar Aztanti", "P", "01/06/1993", 4000000, "1AD3")
        xxx.Rows.Add("36112006", "Izmi Istiqamah", "P", "04/11/1994", 7000000, "1AD3")
        xxx.Rows.Add("36112007", "Imran Novrin Ruslim", "L", "21/11/1994", 1000000, "1AD3")
        xxx.Rows.Add("36112008", "Adbul Malik", "L", "09/11/1993", 2500000, "1AD3")
        xxx.Rows.Add("36112010", "Yulianti", "P", "28/09/1994", 2500000, "1AD3")
        xxx.Rows.Add("36112011", "Zulfitra Qadar Yasin", "L", "10/03/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112012", "Sri Aprianti", "P", "05/04/1994", 4000000, "1AD3")
        xxx.Rows.Add("36112013", "Noviantri Paembonan", "P", "19/11/1994", 6000000, "1AD3")
        xxx.Rows.Add("36112016", "Andi Jusma Nilam Sari", "P", "02/09/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112017", "Dana Abrian", "L", "04/10/1994", 5000000, "1AD3")
        xxx.Rows.Add("36112018", "Kurniawati", "P", "11/10/1994", 2000000, "1AD3")
        xxx.Rows.Add("36112020", "Bernard Talebong", "P", "01/10/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112023", "Andi Arhami Hamzah", "P", "28/06/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112024", "Syahrul Kamal", "L", "18/10/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112027", "Nurul Rezki Susanti", "P", "24/09/1994", 5000000, "1AD3")
        xxx.Rows.Add("36112059", "Ummul Hayyul Qayyum", "P", "01/12/1993", 3500000, "1AD3")
        xxx.Rows.Add("36112022", "Rismawati", "P", "07/09/1994", 900000, "1AD3")
        xxx.Rows.Add("36112026", "Melinda Rizkawati", "P", "07/05/1994", 2000000, "1AD3")
        xxx.Rows.Add("36112025", "Ivana Olivia Aser", "P", "14/01/1993", 6000000, "1AD3")
        xxx.Rows.Add("36112021", "Sulaipah", "P", "28/09/1994", 1000000, "1AD3")
        xxx.Rows.Add("36112061", "Rahmat Adi Pratama", "L", "21/04/1994", 10000000, "1AD3")
        xxx.Rows.Add("36112060", "Nita", "P", "04/01/1995", 2500000, "1AD3")
        xxx.Rows.Add("36112019", "Kharisma Yusuf", "P", "14/06/1994", 4000000, "1AD3")
        xxx.Rows.Add("36112014", "A. Rahmawaty", "P", "04/04/1994", 5000000, "1AD3")
        xxx.Rows.Add("36112015", "Danela Mangintek", "P", "06/11/1994", 3000000, "1AD3")
        xxx.Rows.Add("36112009", "Rahmaniah", "P", "19/01/1994", 2500000, "1AD3")
        xxx.Rows.Add("36112057", "Reenaldy Alchudri Azsagaf", "L", "03/05/1994", 10000000, "1BD3")
        xxx.Rows.Add("36112039", "Andi Syahril", "L", "02/10/1994", 2000000, "1BD3")
        xxx.Rows.Add("36112051", "Muhammad Adhe Anugrah", "L", "31/08/1993", 5000000, "1BD3")
        xxx.Rows.Add("36112042", "Sukmawati Amir", "P", "13/04/1994", 6000000, "1BD3")
        xxx.Rows.Add("36112019", "Dian Eka Puteri", "P", "11/11/1993", 1000000, "1BD3")
        xxx.Rows.Add("36112048", "Tri Wahyuni", "P", "11/11/1994", 800000, "1BD3")
        xxx.Rows.Add("36112047", "A. Dian Pelita Waty", "P", "05/05/1994", 3000000, "1BD3")
        xxx.Rows.Add("36112028", "Mu'minat Nur", "P", "17/05/1995", 5000000, "1BD3")
        xxx.Rows.Add("36112038", "Andi Anggi Fadliyah", "P", "15/08/1994", 1500000, "1BD3")
        xxx.Rows.Add("36112033", "A. Syasya Annisa Ausan", "P", "08/08/1994", 7000000, "1BD3")
        xxx.Rows.Add("36112044", "Muhammad Fachri Sani", "L", "02/02/1994", 5000000, "1BD3")
        xxx.Rows.Add("36112053", "Resky Yonada Ahmad", "P", "22/03/1994", 1500000, "1BD3")
        xxx.Rows.Add("36112029", "Trinayanti", "P", "03/06/1992", 3000000, "1BD3")
        xxx.Rows.Add("36112041", "Musyarafah Asis", "L", "13/07/1994", 6000000, "1BD3")
        xxx.Rows.Add("36112055", "Achmad Rezky Satria Perdana", "L", "17/12/1993", 3000000, "1BD3")
        xxx.Rows.Add("36112040", "Fibra Yoseph P", "P", "27/03/1995", 6000000, "1BD3")
        xxx.Rows.Add("36112045", "Ibnu Affan Al-Mufar'id", "L", "05/08/1994", 8000000, "1BD3")
        xxx.Rows.Add("36112030", "Sri Widya Ayu Wandini", "P", "01/06/1994", 5000000, "1BD3")
        xxx.Rows.Add("36112046", "Sri Wahyuni Hafid", "P", "25/12/1994", 11000000, "1BD3")
        xxx.Rows.Add("36112032", "Rosita Satri", "P", "06/12/1994", 3000000, "1BD3")
        xxx.Rows.Add("36112052", "Sabri", "L", "24/07/1993", 700000, "1BD3")
        xxx.Rows.Add("36112049", "Alfin Riani Bandaso", "P", "11/04/1994", 3000000, "1BD3")
        xxx.Rows.Add("36112036", "Nurmilasari", "P", "06/07/1993", 2000000, "1BD3")
        xxx.Rows.Add("36112035", "Tri Arismunandar", "L", "09/12/1993", 1000000, "1BD3")
        xxx.Rows.Add("36112031", "Nur Indahsari Idris", "P", "28/08/1994", 5000000, "1BD3")
        xxx.Rows.Add("36112037", "Ismawati", "P", "01/08/1994", 900000, "1BD3")
        xxx.Rows.Add("36112034", "Rezky Arianti", "P", "27/01/1994", 3000000, "1BD3")
        xxx.Rows.Add("36112043", "Artis Susan", "P", "29/10/1993", 5000000, "1BD3")
        xxx.Rows.Add("36112054", "Ade Apriathis Rantelino", "L", "27/04/1994", 3000000, "1BD3")

        abc = xxx.DefaultView

        dgv_46110008.DataSource = abc
    End Sub


6. masukkan script di bawah ini, untuk syarat mengurutkan data yang ada di tabel

Private Sub a1_46110008_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a1_46110008.CheckedChanged
        If a1_46110008.Checked = True Then
            abc.Sort = "Stambuk"
        End If
    End Sub

    Private Sub a2_46110008_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a2_46110008.CheckedChanged
        If a2_46110008.Checked = True Then
            abc.Sort = "Kelas desc"
        End If
    End Sub

    Private Sub a3_46110008_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a3_46110008.CheckedChanged
        If a3_46110008.Checked = True Then
            abc.Sort = "Kelas, TanggalLahir"
        End If
    End Sub

    Private Sub a4_46110008_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a4_46110008.CheckedChanged
        If a4_46110008.Checked = True Then
            abc.Sort = "GajiOrtu desc"
        End If
    End Sub


7. lalu, masukkan script berikut untuk pilihan filter yang ada di groupbox Filter Berdasarkan

Private Sub b1_46110008_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1_46110008.TextChanged
        abc.RowFilter = "GajiOrtu >=" & Val(b1_46110008.Text)
    End Sub

    Private Sub b2_46110008_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b2_46110008.TextChanged
        abc.RowFilter = "Kelas <> '" & b2_46110008.Text & "'"
    End Sub

    Private Sub b3_46110008_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3_46110008.ValueChanged
        abc.RowFilter = "TanggalLahir < #" & b3_46110008.Value.Day & "/" & b3_46110008.Value.Month & "/" & b3_46110008.Value.Year & "#"
    End Sub

    Private Sub b4_46110008_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b4_46110008.TextChanged
        abc.RowFilter = "Nama Like '%" & b4_46110008.Text & "%'"
    End Sub


8. masukkan script berikut untuk tombol filter gabungan

Private Sub filter_46110008_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles filter_46110008.Click
        abc.RowFilter = "GajiOrtu >=" & Val(c1_46110008.Text) & " And Kelas <> '" & c2_46110008.Text & "' And TanggalLahir < #" & c3_46110008.Value.Day & "/" & c3_46110008.Value.Month & "/" & c3_46110008.Value.Year & "# And Nama Like '%" & c4_46110008.Text & "%'"
    End Sub


9. dan terakhir, masukkan script pada tombol pengaturan warna tabel

 Private Sub warna_46110008_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles warna_46110008.Click
        For Each x As DataGridViewRow In dgv_46110008.Rows
            If x.Cells("GajiOrtu").Value > 6000000 Then
                x.DefaultCellStyle.BackColor = Label9.BackColor
            ElseIf x.Cells("GajiOrtu").Value > 5000000 Then
                x.DefaultCellStyle.BackColor = Label11.BackColor
            ElseIf x.Cells("GajiOrtu").Value > 4000000 Then
                x.DefaultCellStyle.BackColor = Label12.BackColor
            ElseIf x.Cells("GajiOrtu").Value > 3000000 Then
                x.DefaultCellStyle.BackColor = Label10.BackColor
            ElseIf x.Cells("GajiOrtu").Value > 2000000 Then
                x.DefaultCellStyle.BackColor = Label13.BackColor
            Else
                x.DefaultCellStyle.BackColor = Label14.BackColor
            End If
        Next
    End Sub


10. save all, lalu tekan tombo, debug atau f5 untuk menjalankan form yang sudah anda buat.




Tidak ada komentar:

Posting Komentar