Untuk membuat form seperti diatas, langkah awalnya kita harus koneksikan dari vb.net ke oracle. Dengan cara klik kanan di project => pilih bar net. lihat gambar di bawah ini. Jika sudah klik OK.
Setelah itu buatlah satu buah form dengan menekan menu projec=>klik kanan pilih add windows form. Isikan nama form dengan frmsiswa lalu buatlah desain tampilannya seperti gambar di atas. Lalu atur setiap variable yang ada pada field-fieldnya dengan nama-nama yang ada pada tabel database oracle. Kemudian masukkan kode di bawah ini :
Imports System.Data
Imports System.Data.OracleClient
Public Class frmsiswa
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bukaKoneksi()
mati()
End Sub
Private Sub mati()=>berfungsi untuk me-nonaktifkan textbox
txtnis.Enabled = False
txtnama.Enabled = False
txtalamat.Enabled = False
txttgllahir.Enabled = False
txttlp.Enabled = False
cmbpendidikan.Enabled = False
RadioButton1.Enabled = False
RadioButton2.Enabled = False
RadioButton3.Enabled = False
RadioButton4.Enabled = False
ListView1.Enabled = False
End Sub
Private Sub bersih()=>membersihkan textbox yang ada di form
txtnama.Clear()
txttgllahir.Clear()
txttlp.Clear()
txtalamat.Clear()
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
bersih()
aktif()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
Q = "select * from datasiswa "
Q &= " where nis='" & txtnis.Text & "'"
conn.Close()
conn.Open()
cmd = New OracleCommand(Q, conn)
read = cmd.ExecuteReader
If read.HasRows Then
'MsgBox("No Induk Siswa Tersebut Sudah Ada !!!")
Q = "update datasiswa "
Q &= " set "
Q &= " nama='" & txtnama.Text & "'"
Q &= " , alamat='" & txtalamat.Text & "'"
Q &= " , tgllahir='" & txttgllahir.Text & "'"
Q &= " , tlp='" & txttlp.Text & "'"
Q &= " , pendidikan = '" & cmbpendidikan.Text & "'"
If RadioButton3.Checked = True Then
Q &= " ,jurusan ='" & RadioButton3.Text & "'"
Else
Q &= ",jurusan ='" & RadioButton4.Text & "'"
End If
If RadioButton1.Checked = True Then
Q &= " ,jnskel ='" & RadioButton1.Text & "'"
Else
Q &= ",jnskel ='" & RadioButton2.Text & "'"
End If
Q &= " where nis='" & txtnis.Text & "'"
Else
Q = "insert into datasiswa values"
Q &= " ('" & txtnis.Text & "'"
Q &= " ,'" & txtnama.Text & "'"
Q &= " ,'" & txtalamat.Text & "'"
Q &= " ,'" & txttgllahir.Text & "'"
Q &= " ,'" & txttlp.Text & "'"
Q &= " ,'" & cmbpendidikan.SelectedItem & "'"
If RadioButton3.Checked = True Then
Q &= " ,'" & RadioButton3.Text & "'"
Else
Q &= ",'" & RadioButton4.Text & "'"
End If
If RadioButton1.Checked = True Then
Q &= " ,'" & RadioButton1.Text & "'"
Else
Q &= ",'" & RadioButton2.Text & "'"
End If
Q &= " )"
End If
cmd.Dispose()
read.Close()
cmd = New OracleCommand(Q, conn)
'cmd.CommandText = Q
cmd.ExecuteNonQuery()
conn.Close()
bersih()
isiDataKelList()
ListView1.Enabled = True
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
If ListView1.Items.Count < 1 Then Exit Sub
txtnis.Text = e.Item.Text
txtnama.Text = e.Item.SubItems(1).Text
txtalamat.Text = e.Item.SubItems(2).Text
txttgllahir.Text = e.Item.SubItems(3).Text
txttlp.Text = e.Item.SubItems(4).Text
RadioButton1.Text = e.Item.SubItems(5).Text
RadioButton2.Text = e.Item.SubItems(6).Text
cmbpendidikan.Text = e.Item.SubItems(7).Text
RadioButton3.Text = e.Item.SubItems(8).Text
RadioButton4.Text = e.Item.SubItems(9).Text
End Sub
Sub isiDataKelList()
Q = "select * from datasiswa "
Q &= " order by nis"
conn.Close()
conn.Open()
cmd = New OracleCommand(Q, conn)
read = cmd.ExecuteReader
ListView1.Items.Clear()
If read.HasRows Then
While read.Read
ListView1.Items.Add(read.Item("nis").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("nama").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("alamat").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("jnskel").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("tgllahir").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("tlp").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("pendidikan").ToString)
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(read.Item("jurusan").ToString)
End While
End If
conn.Close()
End Sub
Private Sub cmbpendidikan_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbpendidikan.SelectedValueChanged
'MessageBox.Show(cmbpendidikan.SelectedText)
'MessageBox.Show()
'MessageBox.Show(cmbpendidikan.SelectedValue)
'MessageBox.Show(cmbpendidikan.SelectedIndex)
If cmbpendidikan.SelectedItem = "SMA XI" Then
RadioButton3.Enabled = True
RadioButton4.Enabled = True
ElseIf cmbpendidikan.SelectedItem = "SMA XII" Then
RadioButton3.Enabled = True
RadioButton4.Enabled = True
Else
RadioButton3.Enabled = False
RadioButton4.Enabled = False
End If
End Sub
Private Sub aktif()=>untuk mengaktifkan textbox yang ada di form vb.net
txtnama.Enabled = True
txtnama.Focus()
txtalamat.Enabled = True
txttgllahir.Enabled = True
txttlp.Enabled = True
RadioButton1.Enabled = True
RadioButton2.Enabled = True
cmbpendidikan.Enabled = True
End Sub
Private Sub cmdedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdedit.Click
aktif()
isiDataKelList()
End Sub
Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
Q = "delete from datasiswa "
Q &= " where nis='" & txtnis.Text & "'"
cmd = New OracleCommand(Q, conn)
If cmd.ExecuteNonQuery = 1 Then
MsgBox("Data Berhasil Di Hapus")
Else
MsgBox("Data Gagal Di Hapus !!!")
End If
bersih()
mati()
isiDataKelList()
ListView1.Enabled = True
End Sub
Private Sub cmdcari_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcari.Click
Dim popsiswa As New searchsiswa
popsiswa.ShowDialog()
If popsiswa.popnis <> "" Then
txtnis.Text = popsiswa.popnis
txtnama.Text = popsiswa.popnama
txtalamat.Text = popsiswa.popalamat
txttgllahir.Text = popsiswa.poptgllahir
txttlp.Text = popsiswa.poptlp
cmbpendidikan.Text = popsiswa.poppendidikan
If RadioButton3.Checked = True Then
RadioButton3.Text = popsiswa.popjurusan
Else
RadioButton4.Text = popsiswa.popjurusan
End If
If RadioButton1.Checked = True Then
RadioButton1.Text = popsiswa.popjnskel
Else
RadioButton2.Text = popsiswa.popjnskel
End If
End If
End Sub
End Class
Jika anda ingin menampilkan nomor secara automatis di sebuah texbox yang ada di form anda...Silahkan lihat di tutorial autonumber Vb.net. Cara membuat popup di Vb.net silahkan klik. Sebelum kita jalankan formnya sebaiknya tekan ctrl+shift+B. Jika terjadi debug anda bisa cari kesalahan anda string anda..Apabila tidak terjadi debug tekan F5 untuk running form yang anda buat.
No comments:
Post a Comment