You are on page 1of 4

Imports System.Data.

SqlClient Public Class Form1 Private conn As SqlConnection Private cmd As SqlCommand Private da As SqlDataAdapter Private ds As DataSet Private bs As BindingSource Sub ClearBinding() txtKode_Customer.DataBindings.Clear() txtNama_Customer.DataBindings.Clear() txtAlamat_Customer.DataBindings.Clear() End Sub Sub AddBinding() ClearBinding() txtKode_Customer.DataBindings.Add("Text", bs, "kode_customer") txtNama_Customer.DataBindings.Add("Text", bs, "nama_customer") txtAlamat_Customer.DataBindings.Add("Text", bs, "alamat_customer") End Sub Dim subtotal, total As Integer Private conn As SqlConnection Private cmd As SqlCommand Dim dtadapter As SqlDataAdapter Public Sub insertcustomer() Dim strsql = "insert into Customer values ('" & txtKode_Customer.Text & "','" & txtNama_Customer.Text & "','" & txtAlamat_Customer.Text & "')" Try Dim hasil As String cmd = New SqlCommand(strsql, conn) cmd.Connection = conn conn.Open() hasil = cmd.ExecuteNonQuery() If (hasil > 0) Then MessageBox.Show("data customer dengan kode " & txtKode_Customer. Text & " berhasil di simpan") Else MessageBox.Show("data customer dengan kode " & txtKode_Customer. Text & " tidak berhasil di simpan") End If Catch sqlex As SqlException MessageBox.Show("error : " & sqlex.Message) End Try cmd.Connection.Close() cmd.Dispose() End Sub Public Sub insertpenjualan() Dim strsql = "insert into Jual values ('" & txtKode_Barang.Text & "','" & txtNama_Barang.Text & "','" & txtJml.Text & "','" & txtSatuan.Text & "','" & t xtSubTotal.Text & "','" & txtKode_Customer.Text & "')" Try Dim hasil As String cmd = New SqlCommand(strsql, conn) cmd.Connection = conn conn.Open() hasil = cmd.ExecuteNonQuery() If (hasil > 0) Then MessageBox.Show("data barang dengan kode " & txtKode_Barang.Text

& " berhasil di simpan") Else MessageBox.Show("data barang dengan kode " & txtKode_Barang.Text & " tidak berhasil di simpan") End If Catch sqlex As SqlException MessageBox.Show("error : " & sqlex.Message) End Try cmd.Connection.Close() cmd.Dispose() End Sub Public Sub selectcustomer() dtadapter = New SqlDataAdapter("select*from Customer ", conn) Dim tbdata As New DataTable tbdata.Clear() dtadapter.Fill(tbdata) dgc.DataSource = tbdata dgc.Refresh() End Sub Public Sub selectpenjualan() dtadapter = New SqlDataAdapter("select Kode_Customer, Kode_Barang, Nama_ Barang, Jml, Satuan, Subtotal from Jual where Kode_Customer = " & txtKode_Custom er.Text & "", conn) Dim tbdata As New DataTable tbdata.Clear() dtadapter.Fill(tbdata) dgp.DataSource = tbdata dgp.Refresh() End Sub Public Sub tombol(ByVal aktif As Boolean) btTambah_Customer.Enabled = aktif btTambah.Enabled = Not aktif btHapus.Enabled = Not aktif End Sub Public Sub tomboltambahcustomer(ByVal aktif As Boolean) btTambah.Enabled = aktif btHapus.Enabled = Not aktif End Sub Public Sub tomboltambahbarang(ByVal aktif As Boolean) btHapus.Enabled = aktif End Sub Public Sub textcontrol(ByVal aktif As Boolean) txtKode_Barang.Enabled = Not aktif txtNama_Barang.Enabled = Not aktif txtJml.Enabled = Not aktif txtSatuan.Enabled = Not aktif txtSubTotal.Enabled = Not aktif txtTotal.Enabled = Not aktif End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles MyBase.Load Dim strconn = My.Settings.penjualan conn = New SqlConnection(strconn) tombol(True) textcontrol(True) End Sub Private Sub btTambah_Customer_Click(ByVal sender As System.Object, ByVal e A s System.EventArgs) Handles btTambah_Customer.Click, Button1.Click

tomboltambahcustomer(True) insertcustomer() selectcustomer() textcontrol(False) btTambah_Customer.Enabled = False End Sub Private Sub btTambah_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles btTambah.Click subtotal = txtSubTotal.Text total = total + subtotal txtTotal.Text = total tomboltambahbarang(True) insertpenjualan() selectpenjualan() txtKode_Barang.Text = "" txtNama_Barang.Text = "" txtJml.Text = "" txtSatuan.Text = "" txtSubTotal.Text = "" End Sub Private Sub txtSatuan_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSatuan.TextChanged Dim jml, satuan As Integer jml = Val(txtJml.Text) satuan = Val(txtSatuan.Text) subtotal = Val(txtSubTotal.Text) subtotal = jml * satuan txtSubTotal.Text = subtotal End Sub Private Sub btHapus_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles btHapus.Click If MessageBox.Show("delete data Kode_Barang " & txtKode_Barang.Text & " ?", "konfirmasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Wi ndows.Forms.DialogResult.No Then Exit Sub End If Dim strsql = "delete from Jual where Kode_Barang='" & txtKode_Barang.Tex t & "'" cmd = New SqlCommand(strsql, conn) cmd.Connection = conn selectpenjualan() Try conn.Open() cmd.ExecuteNonQuery() MessageBox.Show("data dengan kode " & txtKode_Barang.Text & " berhas il di hapus") Catch sqlex As SqlException MessageBox.Show(" sql error : " & sqlex.Message) Catch ex As Exception

MessageBox.Show(" error " & ex.Message) Finally txtKode_Barang.Clear() txtNama_Barang.Clear() txtJml.Clear() txtSatuan.Clear() cmd.Dispose() conn.Close() End Try End Sub Private Sub txtNama_Barang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNama_Barang.TextChanged End Sub End Class

You might also like