Imports Oracle.DataAccess.Client
Public Class Form1
Dim currentid As String
Dim terkoneksi As Boolean
Dim conn As New OracleConnection()
Private Sub btnconnect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnconnect.Click
Dim tns As String
If (btnconnect.Text = "Connect") Then
Try
tns = "Data source =(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP) (HOST= localhost) (PORT = 1521)) (CONNECT_DATA =(SERVER = DEDICATED) (SERVICE_NAME= XE)));User id = system;Password = ekosupriyanto"
conn = New Oracle.DataAccess.Client.OracleConnection(tns)
conn.Open()
terkoneksi = True
btnconnect.Text = "disConnect"
MessageBox.Show("Koneksi VB Oracle Sukses !!!!!", "information", MessageBoxButtons.OK, MessageBoxIcon.Information)
btnShow_Click(sender, e)
Catch ex As Exception
MessageBox.Show("disKoneksi VB Oracle Gagal !!!", "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error)
conn.Close()
btnconnect.Text = "Connect"
End Try
Else
btnconnect.Text = "Connect"
conn.Close()
MessageBox.Show("koneksi VB Oracle Sukses !!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
conn.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If MessageBox.Show("Keluar sekarang??", "Confirm Closing", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
btndelete.Enabled = False
btnupdate.Enabled = False
cbnama_semen.SelectedIndex = 0
cbtanggal_masuk_barang.SelectedIndex = 0
btnconnect_Click(sender, e)
End Sub
Private Sub btnshow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnshow.Click
Dim kueri As String
kueri = "select * from tabel_suplier"
Try
'tampilkan
Dim da As New OracleDataAdapter(kueri, conn)
Dim ds As New DataSet()
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
'Msgbox("Query berhasil")
Catch ex As Exception
MsgBox("Query gagal" & ex.Message)
End Try
End Sub
Private Sub btninsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btninsert.Click
Dim kueri As String
Dim cmd As OracleCommand
kueri = "insert into tabel_suplier values"
kueri &= " ('" & txtid_supplier.Text & "'"
kueri &= " ,'" & txtnama_supplier.Text & "'"
kueri &= " ,'" & txtalamat.Text & "'"
If rblaki.Checked = True Then
kueri &= " ,'" & rblaki.Text & "'"
Else
kueri &= ",'" & rbperempuan.Text & "'"
End If
kueri &= ",'" & txtjumlah.Text & "'"
kueri &= ",'" & cbtanggal_masuk_barang.SelectedItem & "'"
kueri &= ",'" & txtstatus.Text & "'"
kueri &= ",'" & cbnama_semen.SelectedItem & "'"
kueri &= ")"
'Label5.Text = kueri
'Label7.Text = kueri
Try
'tampilkan
cmd = New OracleCommand(kueri, conn)
cmd.ExecuteNonQuery()
MsgBox("Query berhasil")
btnshow_Click(sender, e)
Catch ex As Exception
MsgBox("Query gagal" & ex.Message)
End Try
End Sub
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtid_supplier.Text = DataGridView1.Item(0, i).Value
currentid = DataGridView1.Item(0, i).Value
txtnama_supplier.Text = DataGridView1.Item(1, i).Value
txtalamat.Text = DataGridView1.Item(2, i).Value
If (rblaki.Text = DataGridView1.Item(3, i).Value) Then rblaki.Checked = True Else rbperempuan.Checked = True
cbnama_semen.Text = DataGridView1.Item(4, i).Value
txtjumlah.Text = DataGridView1.Item(5, i).Value
cbtanggal_masuk_barang.Text = DataGridView1.Item(6, i).Value
txtstatus.Text = DataGridView1.Item(7, i).Value
btndelete.Enabled = True
btnupdate.Enabled = True
End Sub
Private Sub btnupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Dim kueri As String
Dim cmd As OracleCommand
kueri = "update tabel_supplier "
kueri &= " set "
kueri &= " id_supplier='" & txtid_supplier.Text & "'"
kueri &= " , nama_supplier='" & txtnama_supplier.Text & "'"
kueri &= " , alamat='" & txtalamat.Text & "'"
If rblaki.Checked = True Then
kueri &= " ,jenis_kelamin='" & rblaki.Text & "'"
Else
kueri &= ", jenis_kelamin='" & rbperempuan.Text & "'"
End If
kueri &= " , jumlah='" & txtjumlah.Text & "'"
kueri &= " , tanggal_masuk_barang='" & cbtanggal_masuk_barang.Text & "'"
kueri &= " , status= '" & txtstatus.Text & "'"
kueri &= " , nama_semen= '" & cbnama_semen.Text & "'"
kueri &= " where id_supplier='" & currentid & "'"
Try
cmd = New OracleCommand(kueri, conn)
cmd.ExecuteNonQuery()
MsgBox("Query berhasil")
btnshow_Click(sender, e)
Catch ex As Exception
MsgBox("Query gagal" & ex.Message)
End Try
End Sub
Private Sub btndelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndelete.Click
Dim kueri As String
Dim cmd As OracleCommand
kueri = "delete from tabel_suplier "
kueri &= " where id_supplier='" & currentid & "'"
If MessageBox.Show("Data dengan id_supplier: " & currentid & " ingin dihapus????", "Confirm Closing", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Try
cmd = New OracleCommand(kueri, conn)
cmd.ExecuteNonQuery()
MsgBox("Query berhasil")
btnshow_Click(sender, e)
Catch ex As Exception
MsgBox("Query gagal" & ex.Message)
End Try
End If
End Sub
End Class
Tidak ada komentar:
Posting Komentar