VB NET Mengolah Data Master Barang
VB NET Mengolah Data Master Barang
Sub carikodeMASTER()
If TextBox1.Text = "" Then MsgBox("Kode Barang masih kosong, tentukan kode
barangnya") : Exit Sub
Try
Call koneksi()
tblMstr = Proses.ExecuteQuery(String.Format("select * from Mstr_Brg where
KodeBarang = '{0}'", TextBox1.Text))
If tblMstr.Rows.Count = 0 Then
TextBox2.Focus()
Else
BCC.Text = TextBox1.Text
TextBox2.Text = tblMstr.rows(0).item("Kelompok")
TextBox3.Text = tblMstr.Rows(0).Item("NamaBarang")
ComboBox2.Text = tblMstr.Rows(0).Item("Satuan")
AHB = tblMstr.Rows(0).Item("HargaBeli")
TextBox4.Text = Format(AHB, "###,###,###")
AHJ = tblMstr.Rows(0).Item("HargaJual")
TextBox5.Text = Format(AHJ, "###,###,###")
'AST = tblMstr.rows(0).item("StockAkhir")
SM = tblMstr.rows(0).item("StockMinimal")
TextBox6.Text = Format(SM, "##,###")
TextBox7.Text = tblMstr.rows(0).item("Gambar")
PictureBox1.ImageLocation = TextBox7.Text
Button1.Text = "Perbaharui"
'Button2.Enabled = True
End If
Catch ex As Exception
MsgBox(ex.Message)
'Button2.Enabled = False
End Try
End Sub
#Region "LABEL2"
Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TextBox2.GotFocus
Label2.Text = "Tentukan Kelompok Barang !"
End Sub
#End Region
Sub CekregMaster()
If legalapp = "NO" Then
Try
Call koneksi()
TblData = Proses.ExecuteQuery("select * from Mstr_Brg")
If TblData.Rows.Count > 4 Then
MAxRec = 5
XRegister.Show()
XRegister.MdiParent = XUtama
Exit Sub
Else
Call Simpanmaster()
Call ttpcellmstr()
Button1.Text = "Baru"
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
Else
Call Simpanmaster()
Call ttpcellmstr()
Button1.Text = "Baru"
End If
End Sub
Sub Simpanmaster()
'validtgl = String.Format("{0}/{1}/{2}", Year(DTP.Text), Month(DTP.Text),
Mid(DTP.Text, 1, 2))
AHB = TextBox4.Text.Replace("."c, "")
AHJ = TextBox5.Text.Replace("."c, "")
AST = TextBox6.Text
'asaldomem = Adepositmem
'MsgBox(Adepositmem & " vs " & asaldomem)
Try
'Call koneksi()
Dim sq As New OleDb.OleDbCommand
sq.Connection = database
sq.CommandType = CommandType.Text
sq.CommandText = String.Format("Insert into
Mstr_Brg(Kelompok,KodeBarang,NamaBarang,Satuan,HargaBeli,HargaJual,StockMinimal,gamba
r) values ('{0}','{1}','{2}','{3}',{4},{5},{6},'{7}')", TextBox2.Text, TextBox1.Text,
TextBox3.Text, ComboBox2.Text, AHB, AHJ, AST, TextBox7.Text)
sq.ExecuteNonQuery()
Label2.Text = "Data sudah tersimpan."
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Sub carikodeBrg()
If TextBox1.Text = "" Then MsgBox("Kode Barang masih kosong, tentukan kode
barangnya") : Exit Sub
Try
Call koneksi()
tblMstr = Proses.ExecuteQuery(String.Format("select * from Mstr_Brg where
KodeBarang = '{0}'", TextBox1.Text))
If tblMstr.Rows.Count = 0 Then
Call bkcellMstr()
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox2.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox1.Enabled = False
TextBox2.Focus()
Label2.Text = "Isi semua kolom dan pilih gambar barangnya !"
Else
TextBox1.Enabled = False
TextBox2.Text = tblMstr.rows(0).item("Kelompok")
TextBox3.Text = tblMstr.Rows(0).Item("NamaBarang")
ComboBox2.Text = tblMstr.Rows(0).Item("Satuan")
AHB = tblMstr.Rows(0).Item("HargaBeli")
TextBox4.Text = Format(AHB, "###,###,###")
AHJ = tblMstr.Rows(0).Item("HargaJual")
TextBox5.Text = Format(AHJ, "###,###,###")
SM = tblMstr.rows(0).item("StockMinimal")
TextBox6.Text = Format(SM, "##,###")
TextBox7.Text = tblMstr.rows(0).item("Gambar")
PictureBox1.ImageLocation = TextBox7.Text
Button1.Text = "Perbaharui"
Label2.Text = "Data sudah ada di Master, silahkan perbaiki jika ada yang
salah !"
'Button2.Enabled = True
bkcellmstr()
TextBox2.Focus()
End If
Catch ex As Exception
MsgBox(ex.Message)
'Button2.Enabled = False
End Try
End Sub
Sub bkcellmstr()
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
ComboBox2.Enabled = True
TextBox4.Enabled = True
TextBox5.Enabled = True
TextBox6.Enabled = True
End Sub
Sub ttpcellmstr()
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
ComboBox2.Enabled = False
TextBox4.Enabled = False
TextBox5.Enabled = False
TextBox6.Enabled = False
End Sub