Professional Documents
Culture Documents
SqlClient
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"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtKodeBarang.Text = "00001"
ds.Close()
End If
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
Else
bukakoneksi()
sql = "INSERT INTO tb_barang (kode_barang, nama_barang, satuan, stok) VALUES
(" &
"'" & txtKodeBarang.Text & "', " &
"'" & txtNamaBarang.Text & "', " &
"'" & txtSatuan.Text & "', " &
"'" & txtStok.Text & "' )"
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
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"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtKodeCustomer.Text = "CUS01"
ds.Close()
End If
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
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 & "' )"
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
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"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtKodeSupplier.Text = "SPL01"
ds.Close()
End If
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
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 & "' )"
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
Else
bukakoneksi()
sql = "select * from tb_user where status='" & txtUsername.Text & "'AND
password_user='" & txtPassword.Text & "'"
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
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"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtKodeUser.Text = "USR01"
ds.Close()
End If
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
Else
bukakoneksi()
sql = "INSERT INTO tb_user (kode_user, nama_user, status, password_user)
VALUES (" &
"'" & txtKodeUser.Text & "', " &
"'" & txtNamaUser.Text & "', " &
"'" & txtStatus.Text & "', " &
"'" & txtPassword.Text & "' )"
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
Sub tampildatabarang()
bukakoneksi()
sql = "select * from tb_barang"
Sub bersihkandata()
txtNomorMasuk.Text = ""
cbSupplier.DisplayMember = ""
txtjumlahmasuk.Text = ""
End Sub
Sub kodeotomatis()
bukakoneksi()
sql = "select max(no_masuk) as no_masuk from tb_barangmasuk"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtNomorMasuk.Text = "00001"
ds.Close()
End If
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
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
If jumlahdata = 0 Then
MsgBox("Anda Belum Masukkan Barang")
Else
simpanDataUtama()
simpanDetail()
End If
End Sub
Dim jumlahdata
'jumlah data berisi jumlah baris pada DataGridView1
jumlahdata = dgvDataTransaksi.RowCount - 2
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 & "'"
Try
comSQL.ExecuteNonQuery()
MsgBox("ubah data berhasil")
Catch ex As Exception
MsgBox("ubah data detil gagal")
End Try
Next
tutupkoneksi()
End Sub
Sub tampilsupplier()
bukakoneksi()
Try
sql = "select * from tb_supplier"
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
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
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
Sub tampildatabarang()
bukakoneksi()
sql = "select * from tb_barang"
Sub bersihkandata()
txtNomorKeluar.Text = ""
cbCustomer.DisplayMember = ""
End Sub
Sub kodeotomatis()
bukakoneksi()
sql = "select max(no_keluar) as no_keluar from tb_barangkeluar"
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows = 0 Then
txtNomorKeluar.Text = "00001"
ds.Close()
End If
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"
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
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
End Sub
Dim jumlahdata
jumlahdata = dgvDataTransaksi.RowCount - 2
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 & "'"
Try
comSQL.ExecuteNonQuery()
MsgBox("ubah data berhasil")
Catch ex As Exception
MsgBox("ubah data detil gagal")
End Try
Next
tutupkoneksi()
End Sub
If jumlahdata = 0 Then
MsgBox("Anda Belum Memasukkan Barang")
Else
simpanDataUtama()
simpanDetail()
End If
End Sub
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
Catch ex As Exception
MsgBox("harusangka")
SendKeys.Send("{UP}")
dgvDataTransaksi.Rows(e.RowIndex).Cells(3).Value = 0
End Try
End If
End Sub
Dim ds = comSQL.ExecuteReader
ds.Read()
If ds.HasRows Then
txtNamaCustomer.Text = ds.Item("nama_customer")
Else
Catch ex As Exception
MsgBox("EROR : " & ex.Message.ToString)
End Try
End Sub
End Class