Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Modul 9 Membuat Form Pesanan

Awali selalu pekerjaan dgn doa, mudah-mudahan diberi kemudahan dan dapat memberikan manfaat

Buat form baru dengan cara pilih menu Project kemudian pilih Add Windows Form beri nama : Form Pesanan, tentukan pula lokasi penyimpanan (sesuai aturan lab) Project baru anda seharusnya telah memiliki 1 buah Form : Form1. Atur property Form1 mengikuti tabel 9.1 Control Properties Form1 Name Text WindowState Nilai FrmPsn Form Pesanan Normal Tabel 9.1

Form Pesanan Isikan kode berikut ini:


Imports System.Data.OleDb Imports System.Data Public Class Pesanan Dim cnn As OleDbConnection Dim cmmd, cmmd1, cmmd2 As OleDbCommand Dim dreder As OleDbDataReader Private index As Integer = 0 Private Total As Double = 0.0 Dim lengthText As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim popupang As New Popupcustomer popupang.ShowDialog() If popupang.retKode <> "" Then TextBox1.Text = popupang.retKode TextBox2.Text = popupang.retNama TextBox3.Text = popupang.retalamat Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom 1

TextBox4.Text = popupang.rettlp TextBox1.Focus() End If End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Dim popupang As New Popupbarang popupang.ShowDialog() If popupang.retKode <> "" Then TextBox5.Text = popupang.retKode TextBox7.Text = popupang.retNama TextBox6.Text = popupang.rethrg TextBox9.Text = popupang.retsatuan TextBox1.Focus() End If End Sub Sub AddList(ByVal Value() As String) Dim subIndex As Integer ListView1.Items.Add("") For subIndex = 0 To 4 ListView1.Items(index).SubItems.Add("") ListView1.Items(index).SubItems(subIndex).Text = Value(subIndex) Next index = index + 1 End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Value() As String = {TextBox5.Text, TextBox7.Text, TextBox8.Text, TextBox6.Text, TextBox11.Text} AddList(Value) Total += CDbl(CStr(TextBox11.Text)) txtgrandtotal.Text = CDbl(CStr(Total)) lblterbilang.Text = "(" & Terbilang(txtgrandtotal.Text) & "Rupiah" & ")" txtdp.Focus() : TextBox11.Text = "" End Sub Sub settotal() Dim a As Integer a = CInt(TextBox8.Text) * CInt(TextBox6.Text) TextBox11.Text = a txtgrandtotal.Text = CDbl(CStr(a)) End Sub Public Function Terbilang(ByVal nilai As Long) As String Dim bilangan As String() = {"", "Satu", "Dua", "Tiga", "Empat", "Lima", _ "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas"} If nilai < 12 Then Return " " & bilangan(nilai) ElseIf nilai < 20 Then Return Terbilang(nilai - 10) & " Belas" ElseIf nilai < 100 Then Return (Terbilang(CInt((nilai \ 10))) & " Puluh") + Terbilang(nilai Mod 10) ElseIf nilai < 200 Then Return " Seratus" & Terbilang(nilai - 100) ElseIf nilai < 1000 Then Return (Terbilang(CInt((nilai \ 100))) & " Ratus") + Terbilang(nilai Mod 100) Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom 2

ElseIf nilai < 2000 Then Return " Seribu" & Terbilang(nilai - 1000) ElseIf nilai < 1000000 Then Return (Terbilang(CInt((nilai \ 1000))) & " Ribu") + Terbilang(nilai Mod 1000) ElseIf nilai < 1000000000 Then Return (Terbilang(CInt((nilai \ 1000000))) & " Juta") + Terbilang(nilai Mod 1000000) ElseIf nilai < 1000000000000 Then Return (Terbilang(CInt((nilai \ 1000000000))) & " Milyar") + Terbilang(nilai Mod 1000000000) ElseIf nilai < 1000000000000000 Then Return (Terbilang(CInt((nilai \ 1000000000000))) & " Trilyun") + Terbilang(nilai Mod 1000000000000) Else Return "" End If End Function Private Sub Pesanan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cnn = New OleDbConnection(conn) If cnn.State <> ConnectionState.Closed Then cnn.Close() cnn.Open() Dim strtemp As String = "" Dim strvalue As String = "" Dim sql As String sql = "select * from Pesan order by No_Pesan desc" cmmd = New OleDbCommand(sql, cnn) dreder = cmmd.ExecuteReader If dreder.Read Then strtemp = Mid(dreder.Item("No_Pesan"), 3, 5) Else TextBox10.Text = "ES0001" Exit Sub End If strvalue = Val(strtemp) + 1 TextBox10.Text = "ES" & Mid("000", 1, 5 - strvalue.Length) & strvalue cnn = New OleDbConnection(conn) If cnn.State <> ConnectionState.Closed Then cnn.Close() cnn.Open() Button1.Focus() End Sub Private Sub txtdp_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdp.TextChanged txtkembali.Text = txtgrandtotal.Text - txtdp.Text End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) TextBox5.Text = "" TextBox7.Text = "" TextBox6.Text = "" TextBox8.Text = "" TextBox11.Text = "" End Sub Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress If Asc(e.KeyChar) = 13 Then Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom 3

settotal() Button2.Focus() End If End Sub Sub addlist1(ByVal value() As String) ListView1.Items.Add("") For subindex = 0 To 4 ListView1.Items(index).SubItems.Add("") ListView1.Items(index).SubItems(subindex).Text = value(subindex) Next index = index + 1 End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim value() As String = {TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text} addlist1(value) Total += CDbl(TextBox6.Text) : TextBox11.Text = Format(CDbl(CStr(Total)), "##,####,####,###") TextBox6.Text = "" : TextBox5.Text = "" : TextBox7.Text = "" : TextBox9.Text = "" TextBox8.Text = "" TextBox5.Focus() End Sub Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Me.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim sql, sql2 As String cnn.Close() Dim strtemp As String = "" Dim strvalue As String = "" Try sql = "insert into SP(no_sp,tgl_sp,kd_plg)" & "values('" & TextBox10.Text & "','" & DateTimePicker1.Text & "','" & TextBox1.Text & "')" objcommand = New OleDbCommand cnn.Open() objcommand.CommandType = CommandType.Text objcommand.CommandText = sql cmmd = New OleDbCommand(sql, cnn) Dim x1 As Integer = cmmd.ExecuteNonQuery If x1 = 1 Then MessageBox.Show("DATA SP BERHASIL DISIMPAN") Else MessageBox.Show("GAGAL MENYIMPAN DATA BARANG") End If cnn.Close() sql2 = "insert into pesan(kd_brg,no_pesan,jml_psn,harga,tgl_sp,kd_customer)" & "values('" & TextBox5.Text & "','" & TextBox10.Text & "','" & TextBox8.Text & "','" & TextBox6.Text & "','" & DateTimePicker1.Text & "','" & TextBox1.Text & "')" objcommand = New OleDbCommand cnn.Open() objcommand.CommandType = CommandType.Text objcommand.CommandText = sql2 Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom 4

cmmd = New OleDbCommand(sql2, cnn) Dim x As Integer = cmmd.ExecuteNonQuery If x = 1 Then MessageBox.Show("DATA PENJUALAN BERHASIL DISIMPAN") sql = "select * from Pesan order by NO_Pesan desc" cmmd = New OleDbCommand(sql, cnn) dreder = cmmd.ExecuteReader If dreder.Read Then strtemp = Mid(dreder.Item("NO_Pesan"), 3, 5) Else TextBox10.Text = "ES0001" Exit Sub End If strvalue = Val(strtemp) + 1 TextBox10.Text = "ES" & Mid("000", 1, 5 - strvalue.Length) & strvalue Button1.Focus() cnn.Close() Else MessageBox.Show("GAGAL MENYIMPAN DATA BARANG") End If cnn.Close() Catch ex As Exception MsgBox(ex.Message) End Try bersih() End Sub Sub bersih() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" TextBox11.Text = "" txtgrandtotal.Text = "" txtkembali.Text = "" txtdp.Text = "" TextBox1.Focus() End Sub Private Sub TextBox10_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox10.KeyPress If Asc(e.KeyChar) = 13 Then cnn.Close() cnn.Open() cmmd = New OleDbCommand("select * from pesan where no_pesan='" & TextBox10.Text & "'", cnn) dreder = cmmd.ExecuteReader If dreder.Read Then 'JIKA DATA DITEMUKAN TextBox1.Text = dreder.Item("kd_customer") TextBox5.Text = dreder.Item("kd_brg") TextBox8.Text = dreder.Item("jml_psn") TextBox6.Text = dreder.Item("harga") DateTimePicker1.Text = dreder.Item("tgl_sp") TextBox1.Focus() Else TextBox1.Focus() Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom 5

TextBox5.Text = "" TextBox6.Text = "" DateTimePicker1.Text = "" End If cnn.Close() End If End Sub Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress If Asc(e.KeyChar) = 13 Then cnn.Close() cnn.Open() cmmd = New OleDbCommand("select * from dtbrg where kdbrg='" & TextBox5.Text & "'", cnn) dreder = cmmd.ExecuteReader If dreder.Read Then 'JIKA DATA DITEMUKAN TextBox5.Text = dreder.Item("kdbrg") TextBox7.Text = dreder.Item("nmbrg") TextBox6.Text = dreder.Item("hrg") TextBox9.Text = dreder.Item("satuan") TextBox5.Focus() Else TextBox5.Focus() TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox9.Text = "" End If cnn.Close() End If End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Asc(e.KeyChar) = 13 Then cnn.Close() cnn.Open() cmmd = New OleDbCommand("select * from dtcustomer where kd_customer='" & TextBox1.Text & "'", cnn) dreder = cmmd.ExecuteReader If dreder.Read Then 'JIKA DATA DITEMUKAN TextBox1.Text = dreder.Item("kd_customer") TextBox2.Text = dreder.Item("nm_customer") TextBox3.Text = dreder.Item("almt") TextBox4.Text = dreder.Item("tlp") TextBox2.Focus() Else TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" End If cnn.Close() End If End Sub End Class

Modul Praktikum BP II (VB.Net) / Erik Perdana I, S.Kom

You might also like