You are on page 1of 23

Imports System.Data.

SqlClient

Public Class FormBarang


Sub tampildata()
bukakoneksi()
sql = "select * from tb_barang"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtKodeBarang.Text = ""
txtNamaBarang.Text = ""
txtSatuan.Text = ""
txtStok.Text = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(kode_barang) as kode_barang from tb_barang"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
txtKodeBarang.Text = "00001"
ds.Close()
End If

If Not ds.HasRows Then


txtKodeBarang.Text = "" + "00001"
ds.Close()
Else
txtKodeBarang.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("kode_barang").ToString, 5, 1)) + 1
If Len(txtKodeBarang.Text) = 1 Then
txtKodeBarang.Text = "0000" & txtKodeBarang.Text & ""
ElseIf Len(txtKodeBarang.Text) = 2 Then
txtKodeBarang.Text = "000" & txtKodeBarang.Text & ""
ElseIf Len(txtKodeBarang.Text) = 3 Then
txtKodeBarang.Text = "00" & txtKodeBarang.Text & ""
ElseIf Len(txtKodeBarang.Text) = 4 Then
txtKodeBarang.Text = "0" & txtKodeBarang.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnHapus.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnHapus.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Private Sub FormBarang_Load(sender As Object, e As EventArgs) Handles MyBase.Load


tampildata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


If txtNamaBarang.Text = "" Or
txtSatuan.Text = "" Or
txtStok.Text = "" Then

MsgBox("Data Tidak Boleh Kosong!")

Else
bukakoneksi()
sql = "INSERT INTO tb_barang (kode_barang, nama_barang, satuan, stok) VALUES
(" &
"'" & txtKodeBarang.Text & "', " &
"'" & txtNamaBarang.Text & "', " &
"'" & txtSatuan.Text & "', " &
"'" & txtStok.Text & "' )"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
MsgBox("Simpan Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End If
End Sub

Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click


bukakoneksi()
sql = "delete from tb_barang where kode_barang='" & txtKodeBarang.Text & "'"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Hapus Data Berhasil")
Catch ex As Exception
MsgBox("Hapus Data Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub DataGridView1_Click(sender As Object, e As EventArgs) Handles


DataGridView1.Click
Dim jumlahdata
jumlahdata = DataGridView1.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")

Else

Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtKodeBarang.Text = DataGridView1.Item(0, i).Value.ToString
txtNamaBarang.Text = DataGridView1.Item(1, i).Value.ToString
txtSatuan.Text = DataGridView1.Item(2, i).Value.ToString
txtStok.Text = DataGridView1.Item(3, i).Value.ToString
End If
tombolaktif()
btnSimpan.Enabled = False
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click


Me.Close()
End Sub

Private Sub txtCariData_TextChanged(sender As Object, e As EventArgs)


bukakoneksi()
sql = "select * from tb_barang where nama_barang like '%" & txtCariData.Text &
"%'" &
"OR kode_barang like '%" & txtCariData.Text & "%'" &
"OR satuan like '%" & txtCariData.Text & "%'" &
"OR stok like '%" & txtCariData.Text & "%'"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub
End Class
Imports System.Data.SqlClient

Public Class FormCustomer


Sub tampildata()
bukakoneksi()
sql = "select * from tb_customer"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtKodeCustomer.Text = ""
txtNamaCustomer.Text = ""
txtAlamat.Text = ""
txtTelepon.Text = ""
txtContactPerson.Text = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(kode_customer) as kode_customer from tb_customer"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
txtKodeCustomer.Text = "CUS01"
ds.Close()
End If

If Not ds.HasRows Then


txtKodeCustomer.Text = "CUS" + "01"
ds.Close()

Else
txtKodeCustomer.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("kode_customer").ToString, 4, 2)) + 1
If Len(txtKodeCustomer.Text) = 1 Then
txtKodeCustomer.Text = "CUS0" & txtKodeCustomer.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnHapus.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnHapus.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Private Sub FormCustomer_Load(sender As Object, e As EventArgs) Handles Me.Load


tampildata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


If txtNamaCustomer.Text = "" Or
txtAlamat.Text = "" Or
txtTelepon.Text = "" Or
txtContactPerson.Text = "" Then

MsgBox("Data Tidak Boleh Kosong!")

Else
bukakoneksi()
sql = "INSERT INTO tb_customer (kode_customer, nama_customer,
alamat_customer, telp_customer, pic_customer) VALUES (" &
"'" & txtKodeCustomer.Text & "', " &
"'" & txtNamaCustomer.Text & "', " &
"'" & txtAlamat.Text & "', " &
"'" & txtTelepon.Text & "', " &
"'" & txtContactPerson.Text & "' )"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
MsgBox("Simpan Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End If
End Sub

Private Sub DataGridView1_Click(sender As Object, e As EventArgs) Handles


DataGridView1.Click
Dim jumlahdata
jumlahdata = DataGridView1.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")

Else
Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtKodeCustomer.Text = DataGridView1.Item(0, i).Value.ToString
txtNamaCustomer.Text = DataGridView1.Item(1, i).Value.ToString
txtAlamat.Text = DataGridView1.Item(2, i).Value.ToString
txtTelepon.Text = DataGridView1.Item(3, i).Value.ToString
txtContactPerson.Text = DataGridView1.Item(4, i).Value.ToString
End If
tombolaktif()
btnSimpan.Enabled = False
End Sub

Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click


bukakoneksi()
sql = "delete from tb_customer where kode_customer='" & txtKodeCustomer.Text &
"'"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Hapus Data Berhasil")
Catch ex As Exception
MsgBox("Hapus Data Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click


Me.Close()
End Sub

Private Sub txtCariData_TextChanged(sender As Object, e As EventArgs) Handles


txtCariData.TextChanged
bukakoneksi()
sql = "select * from tb_customer where nama_customer like '%" & txtCariData.Text
& "%'" &
"OR kode_customer like '%" & txtCariData.Text & "%'" &
"OR alamat_customer like '%" & txtCariData.Text & "%'" &
"OR telp_customer like '%" & txtCariData.Text & "%'" &
"OR pic_customer like '%" & txtCariData.Text & "%'"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub
End Class
Imports System.Data.SqlClient

Public Class FormSupplier


Sub tampildata()
bukakoneksi()
sql = "select * from tb_supplier"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtKodeSupplier.Text = ""
txtNamaSupplier.Text = ""
txtAlamat.Text = ""
txtTelepon.Text = ""
txtContactPerson.Text = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(kode_supplier) as kode_supplier from tb_supplier"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
txtKodeSupplier.Text = "SPL01"
ds.Close()
End If

If Not ds.HasRows Then


txtKodeSupplier.Text = "SPL" + "01"
ds.Close()

Else
txtKodeSupplier.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("kode_supplier").ToString, 4, 2)) + 1
If Len(txtKodeSupplier.Text) = 1 Then
txtKodeSupplier.Text = "SPL0" & txtKodeSupplier.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnHapus.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnHapus.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Private Sub FormSupplier_Load(sender As Object, e As EventArgs) Handles Me.Load


tampildata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


If txtNamaSupplier.Text = "" Or
txtAlamat.Text = "" Or
txtTelepon.Text = "" Or
txtContactPerson.Text = "" Then

MsgBox("Data Tidak Boleh Kosong!")

Else
bukakoneksi()
sql = "INSERT INTO tb_supplier (kode_supplier, nama_supplier,
alamat_supplier, telp_supplier, pic_supplier) VALUES (" &
"'" & txtKodeSupplier.Text & "', " &
"'" & txtNamaSupplier.Text & "', " &
"'" & txtAlamat.Text & "', " &
"'" & txtTelepon.Text & "', " &
"'" & txtContactPerson.Text & "' )"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
MsgBox("Simpan Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End If
End Sub

Private Sub DataGridView1_Click(sender As Object, e As EventArgs) Handles


DataGridView1.Click
Dim jumlahdata
jumlahdata = DataGridView1.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")
Else

Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtKodeSupplier.Text = DataGridView1.Item(0, i).Value.ToString
txtNamaSupplier.Text = DataGridView1.Item(1, i).Value.ToString
txtAlamat.Text = DataGridView1.Item(2, i).Value.ToString
txtTelepon.Text = DataGridView1.Item(3, i).Value.ToString
txtContactPerson.Text = DataGridView1.Item(4, i).Value.ToString
End If
tombolaktif()
btnSimpan.Enabled = False
End Sub

Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click


bukakoneksi()
sql = "delete from tb_supplier where kode_supplier='" & txtKodeSupplier.Text &
"'"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Hapus Data Berhasil")
Catch ex As Exception
MsgBox("Hapus Data Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click


Me.Close()
End Sub

Private Sub txtCariData_TextChanged(sender As Object, e As EventArgs) Handles


txtCariData.TextChanged
bukakoneksi()
sql = "select * from tb_supplier where nama_supplier like '%" & txtCariData.Text
& "%'" &
"OR kode_supplier like '%" & txtCariData.Text & "%'" &
"OR alamat_supplier like '%" & txtCariData.Text & "%'" &
"OR telp_supplier like '%" & txtCariData.Text & "%'" &
"OR pic_supplier like '%" & txtCariData.Text & "%'"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub
End Class
Imports System.Data.SqlClient

Public Class FormLogin

Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click


If txtUsername.Text = "" Or
txtPassword.Text = "" Then

MsgBox("Data Tidak Boleh Kosong!")

Else

bukakoneksi()
sql = "select * from tb_user where status='" & txtUsername.Text & "'AND
password_user='" & txtPassword.Text & "'"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
MsgBox("Username atau Password Salah")
End If
tutupkoneksi()
FormMenuUtama.Show()
Me.Hide()
End If
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click


txtUsername.Text = ""
txtPassword.Text = ""
End Sub
End Class
Imports System.Data.SqlClient

Public Class FormUser


Sub tampildata()
bukakoneksi()
sql = "select * from tb_user"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtKodeUser.Text = ""
txtNamaUser.Text = ""
txtStatus.Text = ""
txtPassword.Text = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(kode_user) as kode_user from tb_user"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
txtKodeUser.Text = "USR01"
ds.Close()
End If

If Not ds.HasRows Then


txtKodeUser.Text = "USR" + "01"
ds.Close()
Else
txtKodeUser.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("kode_user").ToString, 4, 2)) + 1
If Len(txtKodeUser.Text) = 1 Then
txtKodeUser.Text = "USR0" & txtKodeUser.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnHapus.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnHapus.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Private Sub FormUser_Load(sender As Object, e As EventArgs) Handles Me.Load


tampildata()
kodeotomatis()
btnHapus.Enabled = False
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


If txtNamaUser.Text = "" Or
txtStatus.Text = "" Or
txtPassword.Text = "" Then

MsgBox("Data Tidak Boleh Kosong!")

Else
bukakoneksi()
sql = "INSERT INTO tb_user (kode_user, nama_user, status, password_user)
VALUES (" &
"'" & txtKodeUser.Text & "', " &
"'" & txtNamaUser.Text & "', " &
"'" & txtStatus.Text & "', " &
"'" & txtPassword.Text & "' )"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
MsgBox("Simpan Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End If
End Sub

Private Sub btnHapus_Click(sender As Object, e As EventArgs) Handles btnHapus.Click


bukakoneksi()
sql = "delete from tb_user where kode_user='" & txtKodeUser.Text & "'"

comSQL = New SqlCommand(sql, conn)


Try
comSQL.ExecuteNonQuery()
MsgBox("Hapus Data Berhasil")
Catch ex As Exception
MsgBox("Hapus Data Gagal" & ex.Message.ToString)
End Try
tutupkoneksi()
tampildata()
bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub DataGridView1_Click(sender As Object, e As EventArgs) Handles


DataGridView1.Click
Dim jumlahdata
jumlahdata = DataGridView1.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")

Else

Dim i As Integer
i = DataGridView1.CurrentRow.Index
txtKodeUser.Text = DataGridView1.Item(0, i).Value.ToString
txtNamaUser.Text = DataGridView1.Item(1, i).Value.ToString
txtStatus.Text = DataGridView1.Item(2, i).Value.ToString
txtPassword.Text = DataGridView1.Item(3, i).Value.ToString
End If
tombolaktif()
btnSimpan.Enabled = False
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
btnHapus.Enabled = False
End Sub

Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click


Me.Close()
End Sub

Private Sub txtCariData_TextChanged(sender As Object, e As EventArgs)


bukakoneksi()
sql = "select * from tb_user where nama_user like '%" & txtCariData.Text & "%'" &
"OR kode_user like '%" & txtCariData.Text & "%'" &
"OR status like '%" & txtCariData.Text & "%'" &
"OR password_user like '%" & txtCariData.Text & "%'"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


DataGridView1.DataSource = dt
Next
tutupkoneksi()
End Sub
End Class
Imports System.Data.SqlClient

Public Class FormBarangMasuk


Sub tampildata()
bukakoneksi()
sql = "select * from tb_barangmasuk"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


dgvDataTransaksi.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub tampildatabarang()
bukakoneksi()
sql = "select * from tb_barang"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


dgvDataBarang.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtNomorMasuk.Text = ""
cbSupplier.DisplayMember = ""
txtjumlahmasuk.Text = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(no_masuk) as no_masuk from tb_barangmasuk"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtNomorMasuk.Text = "00001"
ds.Close()
End If

If Not ds.HasRows Then


txtNomorMasuk.Text = "" + "00001"
ds.Close()

Else
txtNomorMasuk.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("no_masuk").ToString, 5, 0)) + 1
If Len(txtNomorMasuk.Text) = 1 Then
txtNomorMasuk.Text = "0000" & txtNomorMasuk.Text & ""
ElseIf Len(txtNomorMasuk.Text) = 2 Then
txtNomorMasuk.Text = "000" & txtNomorMasuk.Text & ""
ElseIf Len(txtNomorMasuk.Text) = 3 Then
txtNomorMasuk.Text = "00" & txtNomorMasuk.Text & ""
ElseIf Len(txtNomorMasuk.Text) = 4 Then
txtNomorMasuk.Text = "0" & txtNomorMasuk.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Private Sub FormBarangMasuk_Load(sender As Object, e As EventArgs) Handles Me.Load


tampildatabarang()
kodeotomatis()
tombolaktif()
tampilsupplier()
End Sub

Private Sub simpanDataUtama()

bukakoneksi() 'memanggil koneksi

Dim tanggalmasuk = Format(dtpTanggalMasuk.Value, "yyyy-MM-dd")

sql = "INSERT INTO tb_barangmasuk(no_masuk, tgl_masuk, total_masuk,


kode_supplier) VALUES (" &
"'" & txtNomorMasuk.Text & "', " &
"'" & tanggalmasuk & "', " &
"'" & lblTotalMasuk.Text & "', " &
"'" & cbSupplier.Text & "' )"

comSQL = New SqlCommand(sql, conn) 'variabel comSQL sebagai SqlCommand dari


sql dan conn

Try
'jika comSQL berhasil dieksekusi maka ...
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
'jika comSQL gagal dieksekusi maka ....
MsgBox("Simpan gagal" & ex.Message.ToString)
End Try
tutupkoneksi() 'menghentikan koneksi

End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


Dim jumlahdata
'jumlah data berisi jumlah baris pada DataGridView1
jumlahdata = dgvDataTransaksi.RowCount

If jumlahdata = 0 Then
MsgBox("Anda Belum Masukkan Barang")

Else

simpanDataUtama()
simpanDetail()

End If
End Sub

Private Sub simpanDetail() 'digunakan untuk menyimpan detil peminjaman


bukakoneksi()

Dim jumlahdata
'jumlah data berisi jumlah baris pada DataGridView1
jumlahdata = dgvDataTransaksi.RowCount - 2

'melakukan perulangan untuk menyimpan detil


For x As Integer = 0 To jumlahdata
Dim kode_barang = dgvDataTransaksi.Item(0, x).Value
Dim jml_masuk = dgvDataTransaksi.Item(3, x).Value
sql = "INSERT INTO tb_detailmasuk(no_masuk, kode_barang, jml_masuk) VALUES
( " &
"'" & txtNomorMasuk.Text & "'," &
"'" & kode_barang & "'," &
"'" & jml_masuk & "')"
comSQL = New SqlCommand(sql, conn)

Try
comSQL.ExecuteNonQuery()
MsgBox("simpan berhasil")
Catch ex As Exception
MsgBox("simpan detil gagal")
End Try

'update stokbarang
sql = "update tb_barang set " &
"stok=stok+'" & jml_masuk & "'where kode_barang='" & kode_barang & "'"

comSQL = New SqlCommand(sql, conn)

Try
comSQL.ExecuteNonQuery()
MsgBox("ubah data berhasil")
Catch ex As Exception
MsgBox("ubah data detil gagal")
End Try
Next

tutupkoneksi()
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
End Sub
Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click
Me.Close()
End Sub

Private Sub txtCariData_TextChanged(sender As Object, e As EventArgs) Handles


txtCariData.TextChanged
bukakoneksi()
sql = "select * from tb_barangmasuk where tgl_masuk like '%" & txtCariData.Text &
"%'" &
"OR no_masuk like '%" & txtCariData.Text & "%'" &
"OR total_masuk like '%" & txtCariData.Text & "%'" &
"OR kode_supplier like '%" & txtCariData.Text & "%'" &
"OR kode_user like '%" & txtCariData.Text & "%'"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


dgvDataTransaksi.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub tampilsupplier()
bukakoneksi()
Try
sql = "select * from tb_supplier"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)

cbSupplier.DataSource = ds.Tables(0)

cbSupplier.DisplayMember = "kode_supplier"
cbSupplier.ValueMember = "kode_supplier"
Catch ex As Exception
MsgBox("EROR : " & ex.Message.ToString)
End Try
tutupkoneksi()
End Sub

Private Sub dgvDataBarang_Click(sender As Object, e As EventArgs) Handles


dgvDataBarang.Click
Dim jumlahdata
jumlahdata = dgvDataBarang.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")

Else

Dim i As Integer
i = dgvDataBarang.CurrentRow.Index

dgvDataTransaksi.Rows.Add(dgvDataBarang.Item(0, i).Value.ToString,
dgvDataBarang.Item(1, i).Value.ToString, dgvDataBarang.Item(3, i).Value.ToString, 0,
dgvDataBarang.Item(3, i).Value.ToString)
End If
End Sub

Sub totalmasuk()
Dim hitung As Integer = 0
For baris As Integer = 0 To dgvDataTransaksi.RowCount - 1
hitung = hitung + dgvDataTransaksi.Rows(baris).Cells(3).Value
Next
lblTotalMasuk.Text = hitung
End Sub

Private Sub dgvDataTransaksi_CellEndEdit(sender As Object, e As


DataGridViewCellEventArgs) Handles dgvDataTransaksi.CellEndEdit
If e.ColumnIndex = 3 Then
Try
Dim stok As Integer = dgvDataTransaksi.Rows(e.RowIndex).Cells(2).Value
Dim jumlahmasuk As Integer =
dgvDataTransaksi.Rows(e.RowIndex).Cells(3).Value

dgvDataTransaksi.Rows(e.RowIndex).Cells(4).Value = stok + jumlahmasuk


totalmasuk()
Catch ex As Exception
MsgBox("harus angka")
SendKeys.Send("{UP}")
dgvDataTransaksi.Rows(e.RowIndex).Cells(3).Value = 0
End Try
End If
End Sub

Private Sub cbSupplier_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


cbSupplier.SelectedIndexChanged
bukakoneksi()
Try
sql = "select * from tb_supplier where kode_supplier='" & cbSupplier.Text &
"'"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows Then
txtNamaSupplier.Text = ds.Item("nama_supplier")

Else
MsgBox("kode supplier tidak terdaftar")
End If

Catch ex As Exception
MsgBox("EROR : " & ex.Message.ToString)
End Try
tutupkoneksi()
End Sub

End Class
Imports System.Data.SqlClient

Public Class FormBarangKeluar


Sub tampildata()
bukakoneksi()
sql = "select * from tb_barangkeluar"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


dgvDataTransaksi.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub tampildatabarang()
bukakoneksi()
sql = "select * from tb_barang"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)
Dim dt As New DataTable

For Each dt In ds.Tables


dgvDataBarang.DataSource = dt
Next
tutupkoneksi()
End Sub

Sub bersihkandata()
txtNomorKeluar.Text = ""
cbCustomer.DisplayMember = ""
End Sub

Sub kodeotomatis()
bukakoneksi()
sql = "select max(no_keluar) as no_keluar from tb_barangkeluar"

comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows = 0 Then
txtNomorKeluar.Text = "00001"
ds.Close()
End If

If Not ds.HasRows Then


txtNomorKeluar.Text = "" + "00001"
ds.Close()

Else
txtNomorKeluar.Text =
Val(Microsoft.VisualBasic.Mid(ds.Item("no_keluar").ToString, 5, 0)) + 1
If Len(txtNomorKeluar.Text) = 1 Then
txtNomorKeluar.Text = "0000" & txtNomorKeluar.Text & ""
ElseIf Len(txtNomorKeluar.Text) = 2 Then
txtNomorKeluar.Text = "000" & txtNomorKeluar.Text & ""
ElseIf Len(txtNomorKeluar.Text) = 3 Then
txtNomorKeluar.Text = "00" & txtNomorKeluar.Text & ""
ElseIf Len(txtNomorKeluar.Text) = 4 Then
txtNomorKeluar.Text = "0" & txtNomorKeluar.Text & ""
End If
ds.Close()
End If
tutupkoneksi()
End Sub

Sub tombolaktif()
btnBatal.Enabled = True
btnSimpan.Enabled = True
btnTutup.Enabled = True
End Sub

Sub tombolnonaktif()
btnBatal.Enabled = False
btnSimpan.Enabled = False
btnTutup.Enabled = False
End Sub

Sub tampilcustomer()
bukakoneksi()
Try
sql = "select * from tb_customer"

Dim da As New SqlDataAdapter(sql, conn)


Dim ds As New DataSet
da.Fill(ds)

cbCustomer.DataSource = ds.Tables(0)

cbCustomer.DisplayMember = "kode_customer"
cbCustomer.ValueMember = "kode_customer"
Catch ex As Exception
MsgBox("EROR : " & ex.Message.ToString)
End Try
tutupkoneksi()
End Sub

Private Sub FormBarangKeluar_Load(sender As Object, e As EventArgs) Handles Me.Load


tampildata()
tampildatabarang()
kodeotomatis()
tombolaktif()
tampilcustomer()
End Sub

Private Sub simpanDataUtama()

bukakoneksi() 'memanggil koneksi

Dim tanggalkeluar = Format(dtpTanggalKeluar.Value, "yyyy-MM-dd")


sql = "INSERT INTO tb_barangmasuk(no_masuk, tgl_masuk, total_masuk,
kode_supplier) VALUES (" &
"'" & txtNomorKeluar.Text & "', " &
"'" & tanggalkeluar & "', " &
"'" & lblTotalKeluar.Text & "', " &
"'" & cbCustomer.Text & "' )"

comSQL = New SqlCommand(sql, conn) 'variabel comSQL sebagai SqlCommand dari sql
dan conn

Try
'jika comSQL berhasil dieksekusi maka ...
comSQL.ExecuteNonQuery()
MsgBox("Simpan Berhasil")
Catch ex As Exception
'jika comSQL gagal dieksekusi maka ....
MsgBox("Simpan gagal" & ex.Message.ToString)
End Try

tutupkoneksi() 'menghentikan koneksi

End Sub

Private Sub simpanDetail()


bukakoneksi()

Dim jumlahdata
jumlahdata = dgvDataTransaksi.RowCount - 2

For x As Integer = 0 To jumlahdata


Dim kodebarang = dgvDataTransaksi.Item(0, x).Value
Dim jmlkeluar = dgvDataTransaksi.Item(3, x).Value
sql = "INSERT INTO tb_detailkeluar(no_keluar, kode_barang, jml_keluar) VALUES
( " &
"'" & txtNomorKeluar.Text & "'," &
"'" & kodebarang & "'," &
"'" & jmlkeluar & "')"
comSQL = New SqlCommand(sql, conn)

Try
comSQL.ExecuteNonQuery()
MsgBox("simpan berhasil")
Catch ex As Exception
MsgBox("simpan detil gagal")
End Try

'update stokbarang
sql = "update tb_barang set " &
"stok=stok-'" & jmlkeluar & "'where kode_barang='" & kodebarang & "'"

comSQL = New SqlCommand(sql, conn)

Try
comSQL.ExecuteNonQuery()
MsgBox("ubah data berhasil")
Catch ex As Exception
MsgBox("ubah data detil gagal")
End Try
Next

tutupkoneksi()
End Sub

Private Sub btnSimpan_Click(sender As Object, e As EventArgs) Handles btnSimpan.Click


Dim jumlahdata
jumlahdata = dgvDataTransaksi.RowCount

If jumlahdata = 0 Then
MsgBox("Anda Belum Memasukkan Barang")
Else
simpanDataUtama()
simpanDetail()
End If
End Sub

Private Sub btnBatal_Click(sender As Object, e As EventArgs) Handles btnBatal.Click


bersihkandata()
kodeotomatis()
tombolaktif()
End Sub

Private Sub btnTutup_Click(sender As Object, e As EventArgs) Handles btnTutup.Click


Me.Close()
End Sub

Private Sub dgvDataBarang_Click(sender As Object, e As EventArgs) Handles


dgvDataBarang.Click
Dim jumlahdata
jumlahdata = dgvDataBarang.RowCount

If jumlahdata = 0 Then
MsgBox("Data Kosong")

Else

Dim i As Integer
i = dgvDataBarang.CurrentRow.Index

dgvDataTransaksi.Rows.Add(dgvDataBarang.Item(0, i).Value.ToString,
dgvDataBarang.Item(1, i).Value.ToString, dgvDataBarang.Item(3, i).Value.ToString, 0,
dgvDataBarang.Item(3, i).Value.ToString)
End If
End Sub

Sub totalkeluar()
Dim hitung As Integer = 0
For baris As Integer = 0 To dgvDataTransaksi.RowCount - 1
hitung = hitung + dgvDataTransaksi.Rows(baris).Cells(3).Value
Next
lblTotalKeluar.Text = hitung
End Sub

Private Sub dgvDataTransaksi_CellEndEdit(sender As Object, e As


DataGridViewCellEventArgs) Handles dgvDataTransaksi.CellEndEdit
If e.ColumnIndex = 3 Then
Try
Dim stok As Integer = dgvDataTransaksi.Rows(e.RowIndex).Cells(2).Value
Dim jmlkeluar As Integer =
dgvDataTransaksi.Rows(e.RowIndex).Cells(3).Value

dgvDataTransaksi.Rows(e.RowIndex).Cells(4).Value = stok + jmlkeluar

Catch ex As Exception
MsgBox("harusangka")
SendKeys.Send("{UP}")
dgvDataTransaksi.Rows(e.RowIndex).Cells(3).Value = 0
End Try
End If
End Sub

Private Sub cbCustomer_SelectedIndexChanged(sender As Object, e As EventArgs) Handles


cbCustomer.SelectedIndexChanged
bukakoneksi()
Try
sql = "select * from tb_customer where kode_customer='" & cbCustomer.Text &
"'"
comSQL = New SqlCommand(sql, conn)

Dim ds = comSQL.ExecuteReader
ds.Read()

If ds.HasRows Then
txtNamaCustomer.Text = ds.Item("nama_customer")

Else

MsgBox("kode supplier tidak terdaftar")


End If

Catch ex As Exception
MsgBox("EROR : " & ex.Message.ToString)

End Try
End Sub
End Class

You might also like