0% found this document useful (0 votes)
85 views

Program Form Po 1. Form Po: Txtnopo

This document describes a program for managing purchase orders (POs) using Visual Basic and a MySQL database. It includes: 1. A PO form for data entry and listing items 2. A class for generating automated PO numbers 3. Methods for retrieving, calculating, and saving PO data to the database
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Program Form Po 1. Form Po: Txtnopo

This document describes a program for managing purchase orders (POs) using Visual Basic and a MySQL database. It includes: 1. A PO form for data entry and listing items 2. A class for generating automated PO numbers 3. Methods for retrieving, calculating, and saving PO data to the database
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Program Form PO

1. Form PO

txtNoPo

TxtKdSpl Beri Nama Property Name Nya dengan CariSpl

txtNmSpl

txtAlamat
txtTglPO

TxtTelepon

CariBrg CmdAdd

TxtKdbrg txtNmBrg TxtSatuan TxtHarga txtQty TxtJmlHarga

Lisview1

CmdCetak Cdmbatal CmdKeluar

TxtGt
2. Class PO
Imports MySql.Data.MySqlClient
Public Class ClassPO
Public Function kodeotomatis()
Dim th As String
th = Right(Format(Now, "dd-MM-yyyy"), 2)
Dim mycmd As New MySqlCommand
Dim myconnection As New koneksi
Dim myreader As MySqlDataReader

mycmd.CommandText = "select max(right(NoPo,3)) as kode from PO order by NoPo asc"


mycmd.Connection = myconnection.open
myreader = mycmd.ExecuteReader
With myreader
If .Read Then
Return th & "PO" & Format(Val(myreader("kode").ToString) + 1, "000")
Else
Return th & "PO001"
End If
End With
mycmd.Connection.Close()
End Function
End Class

3. Listing Program FormPO


Imports MySql.Data.MySqlClient
Public Class PO
Dim kelasPO As New ClassPO
Dim a As Integer
Dim JmlList As Integer
Private Sub Awal()
TxtNoPo.Clear()
txtTglPo.Value = Now
txtKdSpl.Clear()
txtNmSpl.Clear()
TxtAlamat.Clear()
txtTelepon.Clear()
txtKdBrg.Clear()
txtNmbrg.Clear()
TxtSatuan.Clear()
txtQty.Text = 0
txtJmlHarga.Text = 0
TxtGt.Text = 0
TxtNoPo.Text = kelasPO.kodeotomatis
End Sub
Private Sub PO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Awal()
End Sub

Private Sub kdSpl_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


txtKdSpl.TextChanged
DataSupplier()
End Sub

Private Sub cmdbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbatal.Click


Awal()
End Sub

Public Sub databarang()


Dim MyCmd As New MySqlCommand
Dim MyKoneksi As New koneksi
Dim MyReader As MySqlDataReader

MyCmd.CommandText = "select * from barang where kdbrg='" & txtKdBrg.Text & "'"
MyCmd.Connection = MyKoneksi.open
MyReader = MyCmd.ExecuteReader
If MyReader.Read = True Then
txtNmbrg.Text = MyReader("Nmbrg").ToString
TxtSatuan.Text = MyReader("Satuan").ToString
txtHarga.Text = MyReader("Harga").ToString
End If
End Sub

Public Sub DataSupplier()


Dim MyCmd As New MySqlCommand
Dim MyKoneksi As New koneksi
Dim MyReader As MySqlDataReader

MyCmd.CommandText = "select * from Supplier where kdSpl='" & txtKdSpl.Text & "'"
MyCmd.Connection = MyKoneksi.open
MyReader = MyCmd.ExecuteReader
If MyReader.Read = True Then
txtNmSpl.Text = MyReader("NmSpl").ToString
TxtAlamat.Text = MyReader("Alamat").ToString
txtTelepon.Text = MyReader("Telepon").ToString
End If
End Sub
Public Sub HitungTotal()
Dim ttlpesan As Integer = 0
Dim ttlharga As Integer = 0
JmlList = ListView1.Items.Count - 1
Dim i As Integer
For i = 0 To JmlList
ttlpesan = ttlpesan + ListView1.Items(i).SubItems(4).Text
ttlharga = ttlharga + ListView1.Items(i).SubItems(5).Text
Next i
TxtGt.Text = (ttlpesan)
TxtGt.Text = (ttlharga)
TxtGt.Text = Format(CDbl(ttlpesan), "###,###,###,###")
TxtGt.Text = Format(CDbl(ttlharga), "###,###,###,###")
End Sub

Private Sub txtQty_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles


txtQty.KeyPress
If Asc(e.KeyChar) = 13 Then
If txtQty.Text = "0" Then
MsgBox("Isi Jumlah PO...!!!", MsgBoxStyle.Critical, "Pesan")
Else
txtJmlHarga.Enabled = True
txtJmlHarga.Focus()
End If
End If
End Sub
Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
If txtKdBrg.Text = "" Then
MsgBox("isi Data barang dengan lengkap")
txtKdBrg.Focus()
ElseIf Val(txtQty.Text) = 0 Then
MsgBox("Jumlah/Qty Harus Di Isi")
txtQty.Focus()
ElseIf Val(txtHarga.Text) = 0 Then
MsgBox("Harga Harus Di Isi")
txtHarga.Focus()
Else
Dim lis As String = ListView1.Items.Count - 1
Dim s As Integer
For s = 0 To lis
If ListView1.Items(s).SubItems(1).Text = txtKdBrg.Text Then
MsgBox("Data Barang sudah ada")
Exit Sub
End If
Next
Dim i As ListViewItem
a = a + 1
i = ListView1.Items.Add(a)
With i
Dim hrgapsn As Integer
Dim jmlpsn As Integer
.SubItems.Add(txtKdBrg.Text.Trim)
.SubItems.Add(txtNmbrg.Text.Trim)
.SubItems.Add(TxtSatuan.Text.Trim)
.SubItems.Add(txtHarga.Text.Trim)
.SubItems.Add(txtQty.Text.Trim)
hrgapsn = Val(txtQty.Text) * Val(txtHarga.Text)
.SubItems.Add(hrgapsn)
.SubItems.Add(txtJmlHarga.Text)
jmlpsn = txtQty.Text
End With

txtQty.Text = 0
txtJmlHarga.Text = 0
txtKdBrg.Clear()
TxtSatuan.Clear()
txtNmbrg.Clear()
HitungTotal()
End If
End Sub
Private Sub cmdCetak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCetak.Click
Dim MyCmd As New MySqlCommand
Dim MyKoneksi As New koneksi
Dim MyReader As MySqlDataReader
MyCmd.CommandText = "select NoPo from PO where NoPo='" & Trim(TxtNoPo.Text) & "'"
MyCmd.Connection = MyKoneksi.open
MyReader = MyCmd.ExecuteReader

If MyReader.Read() = False Then


MyCmd.Connection.Close()
MyCmd.CommandText = "insert into PO values ('" & TxtNoPo.Text & "', '" & Format(txtTglPo.Value, "yyyy-
MM-dd") & "','" & txtKdSpl.Text & "')"
MyCmd.Connection = MyKoneksi.open
MyCmd.ExecuteNonQuery()
MyCmd.Connection.Close()

Dim i As Integer
JmlList = ListView1.Items.Count - 1
i = 0
For i = 0 To JmlList
MyCmd.CommandText = "select * from Detil_po where NoPo='" & TxtNoPo.Text & "' and kdbrg='" &
txtKdBrg.Text & "'"
MyCmd.Connection = MyKoneksi.open
myreader = MyCmd.ExecuteReader
If myreader.Read = False Then
MyCmd.Connection.Close()
MyCmd.CommandText = "INSERT into Detil_po(NoPo,kdbrg,Qty,HrgPO) values('" & TxtNoPo.Text & "','"
& ListView1.Items(i).SubItems(1).Text & "','" & ListView1.Items(i).SubItems(4).Text & "','" &
ListView1.Items(i).SubItems(5).Text & "')"
MyCmd.Connection = MyKoneksi.open
MyCmd.ExecuteNonQuery()
MyCmd.Connection.Close()
MsgBox("Data Sudah Di Simpan")
Else
MyCmd.Connection.Close()
MyCmd.CommandText = "update Detil_po set Qty='" & ListView1.Items(i).SubItems(4).Text &
"',HrgPO='" & ListView1.Items(i).SubItems(5).Text & "' where NoPo='" & TxtNoPo.Text & "' and kdbrg='" &
ListView1.Items(i).SubItems(1).Text & "'"
MyCmd.Connection = MyKoneksi.open
MyCmd.ExecuteNonQuery()
MyCmd.Connection.Close()
Return
End If
Next i
Else
MyCmd.Connection.Close()
MyCmd.CommandText = "update PO set TglPo='" & Format(txtTglPo.Value, "yyyy-MM-dd") & "'kdSpl='" &
txtKdSpl.Text & "' where NoPo='" & TxtNoPo.Text & "'"
MyCmd.Connection = MyKoneksi.open
MyCmd.ExecuteNonQuery()
MyCmd.Connection.Close()
MsgBox("Data Berhasil diubah...!!!")
End If
ListView1.Items.Clear()
End Sub
Private Sub cmdkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdkeluar.Click
Me.Dispose()
End Sub

Private Sub txtKdBrg_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


txtKdBrg.TextChanged
databarang()
End Sub

Private Sub CariBrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CariBrg.Click


daftarbarang.Show()
End Sub

Private Sub txtHarga_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles


txtHarga.KeyPress
If Asc(e.KeyChar) = 13 Then
If txtHarga.Text = "0" Then
MsgBox("Isi Harga PO...!!!", MsgBoxStyle.Critical, "Pesan")
txtHarga.Focus()
Else
txtQty.Focus()
End If
End If
End Sub

Private Sub txtQty_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


txtQty.TextChanged
On Error Resume Next
txtJmlHarga.Text = txtHarga.Text * txtQty.Text
End Sub

Private Sub txtHarga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


txtHarga.TextChanged
On Error Resume Next
txtJmlHarga.Text = txtHarga.Text * txtQty.Text
End Sub

End Class

‘ Catatan: Tulisan yang Berwarna seperti ini ditulis dalam 1 baris

You might also like