Anda di halaman 1dari 26

Imports System.Data.

OleDb
Public Class frmMasterProduct
Public KodeBarang As String
Public NamaBarang As String
Public HargaBeli As String
Public HargaJual As String
Public Stock As String
Public Satuan As String
Public Ukuran As String
Public Status As String
Private Sub PosisiList()
Try
With lvProduct.Columns
.Add("Kode", 50)
.Add("Nama Barang", 150)
.Add("Harga Beli", 90, HorizontalAlignment.Right)
.Add("Harga Jual", 90, HorizontalAlignment.Right)
.Add("Stock", 55, HorizontalAlignment.Right)
.Add("Satuan", 60)
.Add("Ukuran", 60)
.Add("ket", 50)
End With
Catch ex As Exception
End Try
End Sub
Private Sub IsiList()
Try
Query = "SELECT *FROM MASTERPRODUCT ORDER BY Nama_Barang ASC"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
lvProduct.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvProduct
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(2))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(3))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(4))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(5))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(6))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(7))
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub
#Region "Konsep Struktur"
'Untuk membersihkan atribut'
Public Sub Baru()
Try
KodeBarang = ""
NamaBarang = ""
HargaBeli = "0"
HargaJual = "0"
Stock = "0"
Satuan = "0"
Ukuran = ""
Status = "YA"
Catch ex As Exception
End Try
End Sub

'Untuk menyimpan data'


Public Function SimpanData()
Try
Query = "INSERT into MASTERPRODUCT VALUES('" & KodeBarang & "', '" &
NamaBarang & "', '" & HargaBeli & "', '" & HargaJual & "', '" & Stock & "', '" & Satuan &
"', '" & Ukuran & "', '" & Status & "')"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
MsgBox("Data dengan kode ini sudah ada", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Pesan")
Return Query
End Try
End Function

'Untuk edit data'


Public Function EditData()
Try
Query = "UPDATE MASTERPRODUCT SET Nama_Barang = '" & NamaBarang & "',
Harga_Beli = '" & HargaBeli & "', Harga_Jual = '" & HargaJual & "', Stock = '" & Stock &
"', Satuan = '" & Satuan & "', Ukuran = '" & Ukuran & "', Keterangan = '" & Status & "'
WHERE Kode_Barang = '" & KodeBarang & "'"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
Return 0
End Try
End Function

'Untuk hapus data'


Public Function HapusData()
Try
Query = "DELETE FROM MASTERPRODUCT WHERE Kode_Barang = '" & KodeBarang & "'"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
Return 0
End Try
End Function

'Untuk menghancurkan objek'


Public Sub Keluar()
Try
Dispose()
Catch ex As Exception
End Try
End Sub
#End Region
Private Sub AmbilDataDariListView()
Try
With lvProduct.SelectedItems
txtkode.Enabled = False
txtkode.Text = .Item(0).SubItems(0).Text
txtnama.Text = .Item(0).SubItems(1).Text
txthargabeli.Text = .Item(0).SubItems(2).Text
txthargajual.Text = .Item(0).SubItems(3).Text
txtstock.Text = .Item(0).SubItems(4).Text
txtsatuan.Text = .Item(0).SubItems(5).Text
txtukuran.Text = .Item(0).SubItems(6).Text
cboket.Text = .Item(0).SubItems(7).Text
End With
Catch ex As Exception
End Try
End Sub

Private Sub BersihkanIsian()


Try
txtkode.Clear()
txtkode.Enabled = True
txtkode.Focus()
txtnama.Clear()
txthargabeli.Clear()
txthargajual.Clear()
txtstock.Clear()
txtsatuan.Clear()
txtukuran.Clear()
cboket.Text = "YA"
cmdSimpan.Enabled = True
cmdEdit.Enabled = False
cmdHapus.Enabled = False
Catch ex As Exception
End Try
End Sub
Public Sub CariKodeBarang()
Try
Query = "SELECT * FROM MASTERPRODUCT WHERE Kode_Barang = '" & txtkode.Text &
"'"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)

If dsData.Tables(0).Rows.Count - 1 Then
txtnama.Clear()
txthargabeli.Clear()
txthargajual.Clear()
txtstock.Clear()
txtsatuan.Clear()
txtukuran.Clear()
cboket.Text = "YA"
txtnama.Focus()
Else
txtkode.Text = dsData.Tables(0).Rows(0).Item(0)
txtnama.Text = dsData.Tables(0).Rows(0).Item(1)
txthargabeli.Text = dsData.Tables(0).Rows(0).Item(2)
txthargajual.Text = dsData.Tables(0).Rows(0).Item(3)
txtstock.Text = dsData.Tables(0).Rows(0).Item(4)
txtsatuan.Text = dsData.Tables(0).Rows(0).Item(5)
txtukuran.Text = dsData.Tables(0).Rows(0).Item(6)
cboket.Text = dsData.Tables(0).Rows(0).Item(7)
End If
Catch ex As Exception

End Try
End Sub
Private Sub Kunci()
txtkode.Enabled = False
txtnama.Enabled = False
txthargabeli.Enabled = False
txthargajual.Enabled = False
txtstock.Enabled = False
txtsatuan.Enabled = False
txtukuran.Enabled = False
cboket.Enabled = False
End Sub
Private Sub Unkunci()
txtkode.Enabled = True
txtnama.Enabled = True
txthargabeli.Enabled = True
txthargajual.Enabled = True
txtstock.Enabled = True
txtsatuan.Enabled = True
txtukuran.Enabled = True
cboket.Enabled = True
End Sub
Private Sub txtkode_TextChanged(sender As Object, e As EventArgs) Handles
txtkode.TextChanged

End Sub

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


txtnama.TextChanged

End Sub

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


MyBase.Load
Try
Kunci()
KoneksiKeAcess()
PosisiList()
IsiList()
cmdedit.Enabled = False
cmdhapus.Enabled = False
cmdsimpan.Enabled = False
Catch ex As Exception
MsgBox("Koneksi ke Database gagal...", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Konfirmasi")
End Try
End Sub

Private Sub lvProduct_Click(sender As Object, e As EventArgs) Handles lvProduct.Click


Try
cmdsimpan.Enabled = False
cmdedit.Enabled = True
cmdhapus.Enabled = True
Catch ex As Exception

End Try
End Sub

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


lvProduct.SelectedIndexChanged
Try
AmbilDataDariListView()
Catch ex As Exception

End Try
End Sub

Private Sub cmdtambah_Click(sender As Object, e As EventArgs) Handles cmdtambah.Click


Try
Unkunci()
Baru()
IsiList()
txtkode.Enabled = True
txtkode.Focus()
cmdsimpan.Enabled = True
cmdedit.Enabled = True
cmdhapus.Enabled = False
Catch ex As Exception
End Try
End Sub

Private Sub cmdsimpan_Click(sender As Object, e As EventArgs) Handles cmdsimpan.Click


Try
If txtkode.Text = "" Then
MsgBox("Kode tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Information")
txtnama.Focus()
Else
If txtnama.Text = "" Then
MsgBox("nama barang tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Information")
txtnama.Focus()
Else
If Len(txthargabeli.Text) = 0 Then txthargabeli.Text = 0
If Len(txthargajual.Text) = 0 Then txthargajual.Text = 0
If Len(txtstock.Text) = 0 Then txtstock.Text = 0
KodeBarang = txtkode.Text
NamaBarang = txtnama.Text
HargaBeli = txthargabeli.Text
HargaJual = txthargajual.Text
Stock = txtstock.Text
Satuan = txtsatuan.Text
Ukuran = txtukuran.Text
Status = cboket.Text
SimpanData()
IsiList()
BersihkanIsian()
End If
End If

Catch ex As Exception
MsgBox("Data dengan kode ini sudah ada", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Konfirmasi")
End Try
End Sub

Private Sub cmdedit_Click(sender As Object, e As EventArgs) Handles cmdedit.Click


Try
Dim A As String

If txtkode.Text = "" Then


MsgBox("Pilih data yang akan di-edit", MsgBoxStyle.Information +
MsgBoxStyle.OkOnly, "Pesan")
Else
A = MsgBox("Benar akan di-edit", MsgBoxStyle.Question +
MsgBoxStyle.OkCancel, "Informasi")
Select Case A
Case vbCancel
BersihkanIsian()
Exit Sub
Case vbOK
Try
If Len(txthargabeli.Text) = 0 Then txthargabeli.Text = 0
If Len(txthargajual.Text) = 0 Then txthargajual.Text = 0
If Len(txtstock.Text) = 0 Then txtstock.Text = 0
KodeBarang = txtkode.Text
NamaBarang = txtnama.Text
HargaBeli = txthargabeli.Text
HargaJual = txthargajual.Text
Stock = txtstock.Text
Satuan = txtsatuan.Text
Ukuran = txtukuran.Text
Status = cboket.Text
EditData()
IsiList()
BersihkanIsian()
txtkode.Enabled = True
txtkode.Focus()
Catch ex As Exception
End Try
End Select
End If
Catch ex As Exception
End Try
End Sub

Private Sub cmdhapus_Click(sender As Object, e As EventArgs) Handles cmdhapus.Click


Try
If (txtkode.Text) = "" Then
MsgBox("Pilih data yang dihapus", MsgBoxStyle.Information +
MsgBoxStyle.OkOnly, "Hapus data")
Exit Sub
Else
Dim A As String
A = MsgBox("benar akan dihapus...", MsgBoxStyle.OkCancel, "Konfirmasi")
Select Case A
Case vbCancel
BersihkanIsian()
Exit Sub
Case vbOK
KodeBarang = txtkode.Text
HapusData()
IsiList()
BersihkanIsian()
End Select
End If
Catch ex As Exception
End Try
End Sub

Private Sub cmdkeluar_Click(sender As Object, e As EventArgs) Handles cmdkeluar.Click


Keluar()
End Sub

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


txtdata.TextChanged
Try
Query = "SELECT * FROM MASTERPRODUCT WHERE KodeBarang Like '" & txtdata.Text
& "%" & "' ORDER BY KodeBarang"

daData = New OleDbDataAdapter(Query, conn)


dsData = New DataSet
daData.Fill(dsData)
lvProduct.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvProduct
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(Format(dsData.Tables(0).Rows(a).Item(2),
"###,###"))
.Items(a).SubItems.Add(Format(dsData.Tables(0).Rows(a).Item(3),
"###,###"))
.Items(a).SubItems.Add(Format(dsData.Tables(0).Rows(a).Item(4),
"###,###"))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(5))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(6))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(7))
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub

Private Sub txtstock_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtstock.KeyPress
If e.KeyChar = Chr(13) Then
If txtstock.Text = "" Then
MsgBox("Stock barang masih kosong, silahkan diisi",
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Konfirmasi")
txtstock.Focus()
Else
txtsatuan.Focus()
End If
End If
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then
e.Handled = True
End If
End Sub

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


cboket.SelectedIndexChanged

End Sub
End Class
Public Class FrmMenuUtama

Shared Property ToolStripStatusLabel1 As Object

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

End Sub

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


Handles DataCustomerToolStripMenuItem1.Click
frmCustomer.ShowDialog()
End Sub

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


Handles DataStockBarangToolStripMenuItem1.Click
frmMasterProduct.ShowDialog()
End Sub

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


Handles NamaUsahaToolStripMenuItem1.Click
Frmnamausaha.ShowDialog()
End Sub

Private Sub MenuStrip1_ItemClicked(sender As Object, e As


ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

End Sub
End Class
3. PENJUALAN

BARIS

1. Txtkodeproduct
2. txtnamabarang
3. txthargajual
4. txtjumlah

5. txtsatuan

6. txtsubtotal
Imports System.Data.OleDb
Public Class frmPenjualan
Public NoIvoice As String
Public TglInvoice As Date
Public Kodeuser As String
Public KodeCustomer As String
Public KodeBarang As String
Public Jumlah As Double
Public Harga As Double
Dim mKodeBarang As String
Private Sub PosisiList()
Try
With lvProduct.Columns
.Add("No.Invoice", 50)
.Add("kode", 100)
.Add("Alamat", 180)
.Add("Kota", 100)
.Add("No.Telepon", 90)
End With
Catch ex As Exception
End Try
End Sub

Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

End Sub

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

End Sub
Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles
txttotalbayar.TextChanged

End Sub

Shared Function txtharga() As Object


Throw New NotImplementedException
End Function

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

End Sub
End Class

Imports System.Data.OleDb
Public Class frmSubCustomer
Private Sub PosisiList()
Try
With lvDataCustomer.Columns
.Add("Kode", 50)
.Add("Nama Customer", 100)
.Add("Alamat", 180)
.Add("Kota", 100)
.Add("No.Telepon", 90)
End With
Catch ex As Exception
End Try
End Sub
Private Sub IsiList()
Try
Query = "SELECT *FROM MASTERCUSTOMER ORDER BY Nama_Customer ASC"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
lvDataCustomer.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvDataCustomer
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(2))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(3))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(4))
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub

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


Try
KoneksiKeAcess()
PosisiList()
IsiList()
Catch ex As Exception

End Try
End Sub
Private Sub Kirimdata()
Try
With lvDataCustomer.SelectedItems
frmPenjualan.txtkode.Text = .Item(0).SubItems(0).Text
frmPenjualan.txtnama.Text = .Item(0).SubItems(1).Text
frmPenjualan.txtalamat.Text = .Item(0).SubItems(2).Text
frmPenjualan.txtkota.Text = .Item(0).SubItems(3).Text
frmPenjualan.txtnotelpon.Text = .Item(0).SubItems(4).Text
End With
Catch ex As Exception

End Try
End Sub

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


lvDataCustomer.DoubleClick
Try
Kirimdata()
Dispose()
Catch ex As Exception

End Try
End Sub

Private Sub lvDataCustomer_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


lvDataCustomer.KeyPress
If e.KeyChar = Chr(13) Then
Kirimdata()
Dispose()
End If

End Sub

Private Sub lvDataCustomer_KeyUp(sender As Object, e As KeyEventArgs) Handles


lvDataCustomer.KeyUp
If e.KeyCode = Keys.Escape Then
Dispose()
End If
End Sub

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


Handles lvDataCustomer.SelectedIndexChanged

End Sub

Private Sub cmbkeluar_Click(sender As Object, e As EventArgs) Handles cmbkeluar.Click


Me.Dispose()
End Sub

Private Sub cmdya_Click(sender As Object, e As EventArgs) Handles cmdya.Click


Try
Kirimdata()
Dispose()
Catch ex As Exception

End Try
End Sub

End Class

Imports System.Data.OleDb
Public Class frmSubProduct

Private Sub PosisiList()


Try
With lvDataProduct.Columns
.Add("Kode", 50)
.Add("Nama Barang", 150)
.Add("HargaJual", 100, HorizontalAlignment.Right)
End With
Catch ex As Exception
End Try
End Sub
Private Sub IsiList()
Try
Query = "SELECT *FROM MASTERPRODUCT ORDER BY Nama_Barang ASC"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
lvDataProduct.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvDataProduct
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(Format(dsData.Tables(0).Rows(a).Item(3),
"###.###")
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub
Private Sub Kirimdata()
Try
With lvDataProduct.SelectedItems
frmPenjualan.txtkode.Text = .Item(0).SubItems(0).Text
frmPenjualan.txtnama.Text = .Item(0).SubItems(1).Text
frmPenjualan.txthargajual.text = .Item(0).SubItems(0).Text
End With
Catch ex As Exception

End Try
End Sub

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


Me.Activated
Try
txtdata.Focus()
Catch ex As Exception

End Try
End Sub
Private Sub frmSubProduct_FormClosed(sender As Object, e As FormClosedEventArgs)
Handles Me.FormClosed
Me.Dispose()
End Sub

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


Try
KoneksiKeAcess()
PosisiList()
IsiList()
Catch ex As Exception

End Try
End Sub

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


lvDataProduct.DoubleClick
Try
Kirimdata()
Me.Dispose()
Catch ex As Exception

End Try
End Sub

Private Sub lvDataProduct_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


lvDataProduct.KeyPress
If e.KeyChar = Chr(13) Then
Kirimdata()
Me.Dispose()
End If
End Sub

Private Sub lvDataProduct_KeyUp(sender As Object, e As KeyEventArgs) Handles


lvDataProduct.KeyUp
If e.KeyCode = Keys.Escape Then
Dispose()
End If
End Sub

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


Handles lvDataProduct.SelectedIndexChanged

End Sub

Private Sub cbokriteria_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


cbokriteria.KeyPress
If e.KeyChar = Chr(13) Then
If cbokriteria.Text = "" Then
MsgBox("pilih kriteria")
cbokriteria.Focus()
Else
txtdata.Focus()
End If
End If
End Sub
Private Sub cbokriteria_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles cbokriteria.SelectedIndexChanged

End Sub

Private Sub txtdata_KeyPress(sender As Object, e As KeyPressEventArgs) Handles


txtdata.KeyPress
If e.KeyChar = Chr(13) Then
lvDataProduct.Focus()
End If
End Sub

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


txtdata.TextChanged
Try
If cbokriteria.Text = "Kode" Then
Query = "SELECT KodeBarang, NamaBarang, HargaJual FROM MASTERPRODUCT
WHERE KodeBarang Like '" & txtdata.Text & "%" & "' ORDER BY KodeBarang"
Else
Query = "SELECT KodeBarang, NamaBarang, HargaJual FROM MASTERPRODUCT
WHERE KodeBarang Like '" & txtdata.Text & "%" & "' ORDER BY KodeBarang"
End If

daData = New OleDbDataAdapter(Query, conn)


dsData = New DataSet
daData.Fill(dsData)
lvDataProduct.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvDataProduct
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(Format(dsData.Tables(0).Rows(a).Item(2),
"###,###"))

If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub

Private Sub cmbya_Click(sender As Object, e As EventArgs) Handles cmbya.Click


Try
Kirimdata()
Dispose()
Catch ex As Exception

End Try
End Sub

Private Sub cmbkeluar_Click(sender As Object, e As EventArgs) Handles cmbkeluar.Click


Me.Dispose()
End Sub
End Class

Imports System.Data.OleDb
Public Class frmCustomer
Public KodeCustomer As String
Public NamaCustomer As String
Public Alamat As String
Public Kota As String
Public NoTelpon As String

Private Sub PosisiList()


Try
With lvCustomer.Columns
.Add("Kode", 50)
.Add("Nama Customer", 100)
.Add("Alamat", 180)
.Add("Kota", 100)
.Add("No.Telepon", 90)
End With
Catch ex As Exception
End Try
End Sub
Private Sub IsiList()
Try
Query = "SELECT *FROM MASTERCUSTOMER ORDER BY Nama_Customer ASC"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
lvCustomer.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvCustomer
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(2))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(3))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(4))
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub

#Region "Konsep Struktur"


'Untuk membersihkan atribut'
Public Sub Baru()
Try
KodeCustomer = ""
NamaCustomer = ""
Alamat = ""
Kota = ""
NoTelpon = ""
Catch ex As Exception
End Try
End Sub

'Untuk menyimpan data'


Public Function SimpanData()
Try
Query = "INSERT into MASTERCUSTOMER VALUES('" & KodeCustomer & "', '" &
NamaCustomer & "', '" & Alamat & "', '" & Kota & "', '" & NoTelpon & "')"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
MsgBox("Data dengan kode ini sudah ada", MsgBoxStyle.Exclamation +
MsgBoxStyle.OkOnly, "Pesan")
Return Query
End Try
End Function

'Untuk edit data'


Public Function EditData()
Try
Query = "UPDATE MASTERCUSTOMER SET Nama_Customer = '" & NamaCustomer & "',
Alamat = '" & Alamat & "', Kota = '" & Kota & "', NoTelpon = '" & NoTelpon & "' WHERE
Kode_Customer = '" & KodeCustomer & "'"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
Return 0
End Try
End Function

'Untuk hapus data'


Public Function HapusData()
Try
Query = "DELETE FROM MASTERCUSTOMER WHERE Kode_Customer = '" & KodeCustomer &
"'"
daData = New OleDbDataAdapter(Query, conn)
dsData = New DataSet
daData.Fill(dsData)
Return Query
Catch ex As Exception
Return 0
End Try
End Function

'Untuk menghancurkan objek'


Public Sub Keluar()
Try
Dispose()
Catch ex As Exception
End Try
End Sub
#End Region

Private Sub AmbilDataDariListView()


Try
With lvCustomer.SelectedItems
txtkode.Enabled = False
txtkode.Text = .Item(0).SubItems(0).Text
txtnama.Text = .Item(0).SubItems(1).Text
txtalamat.Text = .Item(0).SubItems(2).Text
txtkota.Text = .Item(0).SubItems(3).Text
txtnotelpon.Text = .Item(0).SubItems(4).Text
End With
Catch ex As Exception
End Try
End Sub

Private Sub BersihkanIsian()


Try
txtkode.Clear()
txtkode.Enabled = True
txtkode.Focus()
txtnama.Clear()
txtalamat.Clear()
txtkota.Clear()
txtnotelpon.Clear()
cmdSimpan.Enabled = True
cmdEdit.Enabled = False
cmdHapus.Enabled = False
Catch ex As Exception
End Try
End Sub
Private Sub frmCustomer_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Activated
txtkode.Focus()
End Sub

Private Sub frmCustomer_FormClosed(ByVal sender As Object, ByVal e As


System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
End Sub
Private Sub Kunci()
txtkode.Enabled = False
txtnama.Enabled = False
txtalamat.Enabled = False
txtkota.Enabled = False
txtnotelpon.Enabled = False

End Sub
Private Sub Unkunci()
txtkode.Enabled = True
txtnama.Enabled = True
txtalamat.Enabled = True
txtkota.Enabled = True
txtnotelpon.Enabled = True
End Sub
Private Sub frmCustomer_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Kunci()
KoneksiKeAcess()
PosisiList()
IsiList()
cmdEdit.Enabled = False
cmdHapus.Enabled = False
cmdSimpan.Enabled = False
Catch ex As Exception
End Try
End Sub
Private Sub txtkode_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtkode.KeyPress
If e.KeyChar = Chr(13) Then
If txtkode.Text = "" Then
MsgBox("Kode tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Pesan")
txtkode.Focus()
Else
txtnama.Focus()
End If
End If
End Sub

Private Sub txtnama_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtnama.KeyPress
If e.KeyChar = Chr(13) Then
If txtnama.Text = "" Then
MsgBox("Nama customer tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Pesan")
txtnama.Focus()
Else
txtalamat.Focus()
End If
End If
End Sub

Private Sub txtalamat_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtalamat.KeyPress
If e.KeyChar = Chr(13) Then
If txtalamat.Text = "" Then
MsgBox("Alamat tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Pesan")
txtalamat.Focus()
Else
txtkota.Focus()
End If
End If
End Sub

Private Sub txtkota_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtkota.KeyPress
If e.KeyChar = Chr(13) Then
If txtkota.Text = "" Then
MsgBox("Kota tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Pesan")
txtkota.Focus()
Else
txtnotelpon.Focus()
End If
End If
End Sub

Private Sub txtnotelpon_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles txtnotelpon.KeyPress
If e.KeyChar = Chr(13) Then
If txtnotelpon.Text = "" Then
MsgBox("No.Telepon tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Pesan")
txtnotelpon.Focus()
Else
If txtnama.Enabled = False Then
cmdEdit.Focus()
Else
cmdSimpan.Focus()
End If
End If
End If
End Sub

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


lvCustomer.Click
Try
cmdsimpan.Enabled = False
cmdedit.Enabled = True
cmdhapus.Enabled = True
Catch ex As Exception

End Try
End Sub
Private Sub lvcustomer_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles lvCustomer.KeyPress
If e.KeyChar = Chr(13) Then
txtnama.Focus()
End If
End Sub

Private Sub lvcustomer_KeyUp(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyEventArgs) Handles lvCustomer.KeyUp
If e.KeyCode = Keys.Escape Then
BersihkanIsian()
End If
End Sub

Private Sub cmdKeluar_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles cmdKeluar.Click
Keluar()
End Sub

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


cmdsimpan.Click
Try
If txtkode.Text = "" Then
MsgBox("Kode tidak boleh kosong", MsgBoxStyle.Critical +
MsgBoxStyle.OkOnly, "Information")
txtnama.Focus()
Else
'Memanggil Prosedur Simpan Data
KodeCustomer = txtkode.Text
NamaCustomer = txtnama.Text
Alamat = txtalamat.Text
Kota = txtkota.Text
NoTelpon = txtnotelpon.Text
SimpanData()
IsiList()
BersihkanIsian()
End If
Catch ex As Exception
End Try

End Sub

Private Sub cmdedit_Click_1(sender As Object, e As EventArgs) Handles cmdedit.Click


Try
Dim A As String

If txtkode.Text = "" Then


MsgBox("Pilih data yang akan di-edit", MsgBoxStyle.Information +
MsgBoxStyle.OkOnly, "Pesan")
Else
A = MsgBox("Benar akan di-edit", MsgBoxStyle.Question +
MsgBoxStyle.OkCancel, "Informasi")
Select Case A
Case vbCancel
BersihkanIsian()
Exit Sub
Case vbOK
Try
KodeCustomer = txtkode.Text
NamaCustomer = txtnama.Text
Alamat = txtalamat.Text
Kota = txtkota.Text
NoTelpon = txtnotelpon.Text
EditData()
IsiList()
BersihkanIsian()
Catch ex As Exception
End Try
End Select
End If
Catch ex As Exception
End Try

End Sub

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


cmdtambah.Click

Try
Unkunci()
Baru()
txtkode.Text = KodeCustomer
txtnama.Text = NamaCustomer
txtalamat.Text = Alamat
txtkota.Text = Kota
txtnotelpon.Text = NoTelpon
txtkode.Enabled = True
txtkode.Focus()
cmdsimpan.Enabled = True
cmdedit.Enabled = True
cmdhapus.Enabled = False
Catch ex As Exception
End Try

End Sub

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


txtdata1.TextChanged
Try
' If cboKriteria.Text = "Kode Customer" Then
' Query = "SELECT * FROM MasterCustomer WHERE KodeCustomer Like '" &
txtData.Text & "%" & "' ORDER BY KodeCustomer"
' Else
Query = "SELECT * FROM MasterCustomer WHERE NamaCustomer Like '" &
txtdata1.Text & "%" & "' ORDER BY NamaCustomer"
'End If

daData = New OleDbDataAdapter(Query, conn)


dsData = New DataSet
daData.Fill(dsData)
lvCustomer.Items.Clear()
For a = 0 To dsData.Tables(0).Rows.Count - 1
With lvCustomer
.Items.Add(dsData.Tables(0).Rows(a).Item(0))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(1))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(2))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(3))
.Items(a).SubItems.Add(dsData.Tables(0).Rows(a).Item(4))
If (a Mod 2 = 0) Then
.Items(a).BackColor = Color.LightSteelBlue
Else
.Items(a).BackColor = Color.Lavender
End If
End With
Next
Catch ex As Exception

End Try
End Sub

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


lvCustomer.SelectedIndexChanged
Try
AmbilDataDariListView()
Catch ex As Exception

End Try
End Sub

Private Sub cmdhapus_Click_1(sender As Object, e As EventArgs) Handles cmdhapus.Click


Try
If (txtkode.Text) = "" Then
MsgBox("Pilih data yang dihapus", MsgBoxStyle.Information +
MsgBoxStyle.OkOnly, "Hapus data")
Exit Sub
Else
Dim A As String

A = MsgBox("Benar akan dihapus..." & txtkode.Text & " : " & txtnama.Text
& " : " & txtalamat.Text & " : " & txtkota.Text & " : " & txtnotelpon.Text,
MsgBoxStyle.OkCancel, "Hapus Data")
Select Case A
Case vbCancel
BersihkanIsian()
Exit Sub
Case vbOK
'Memanggil Prosedur Hapus Data
KodeCustomer = txtkode.Text
HapusData()
IsiList()
BersihkanIsian()
End Select
End If
Catch ex As Exception
End Try
End Sub
Private Sub cmdkeluar_Click_1(sender As Object, e As EventArgs) Handles
cmdkeluar.Click

End Sub
End Class

Anda mungkin juga menyukai