Welcome To ViniCeca's World

Delete this widget from your Dashboard and add your own words. This is just an example!

FORM ENTRY SURAT PESANAN

Jumat, 13 Mei 2011



Coding Entry Surat Pesanan

Imports System.Data.OleDb
Imports System.Data
Public Class frmEntrySp
Dim cnn As OleDbConnection
Dim cmmd, cmmd1, cmmd2 As OleDbCommand
Dim dReader As OleDbDataReader
Private index As Integer = 0
Private Total As Double = 0.0
Private Sub frmEntrySp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Buka koneksi
cnn = New OleDbConnection(strConn)
If cnn.State <> ConnectionState.Closed Then cnn.Close()
cnn.Open()
'Buat autonumber u surat pesanan
Dim strTmp As String = " "
Dim strValue As String = " "
Dim sql As String
sql = "SELECT * FROM SP ORDER BY NOSP DESC"
cmmd = New OleDbCommand(sql, cnn)
dReader = cmmd.ExecuteReader
If dReader.Read Then
strTmp = Mid(dReader.Item("NOSP"), 3, 5)
Else
txtNoSp.Text = "SP00001"
Exit Sub
End If
'MsgBox(strTemp)
strValue = Val(strTmp) + 1
txtNoSp.Text = "SP" & Mid("00000", 1, 5 - strValue.Length) & strValue
End Sub

Private Sub txtNoSp_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNoSp.KeyPress
If Asc(e.KeyChar) = 13 Then
BtncariSup.Focus()
End If
End Sub

Private Sub BtncariSup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtncariSup.Click
Dim popupsup As New PopSup
popupsup.ShowDialog()

If popupsup.retKdSup <> " " Then
txtKdsup.Text = popupsup.retKdSup
txtNmSup.Text = popupsup.retNmSup
txtNmSup.Focus()
End If
End Sub

Private Sub txtNmSup_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNmSup.KeyPress
If Asc(e.KeyChar) = 13 Then
btnCaribrg.Focus()
End If
End Sub

Private Sub txtJmlBeli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtJmlBeli.KeyPress
If Asc(e.KeyChar) = 13 Then
SetTotal()
txtTotal.Focus()
End If
End Sub

Private Sub txtTotal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTotal.KeyPress
If Asc(e.KeyChar) = 13 Then
btnTambah.Focus()
End If
End Sub
Sub SetTotal()
Dim a As Integer
a = CInt(txtJmlBeli.Text) * CInt(txtSatuan.Text)
txtTotal.Text = Format(CDbl(CStr(a)), "##, ####,####, ###")
'txt.Text = Format (CDbl(txt.Text), "##, ####, ####,###")
End Sub

Private Sub btnCaribrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCaribrg.Click
Dim popupbrg As New PopBrg
popupbrg.ShowDialog()

If popupbrg.retKdBrg <> "" Then
txtKdBrg.Text = popupbrg.retKdBrg
txtnmbrg.Text = popupbrg.retNmBrg
txtSatuan.Text = Format(CDbl(popupbrg.retSatuan), "##, ####, ####, ###")
txtJmlBeli.Focus()
End If
End Sub

Private Sub btnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTambah.Click
Dim Value() As String = {txtKdBrg.Text, txtnmbrg.Text, txtSatuan.Text, txtJmlBeli.Text, txtTotal.Text}
AddList(Value)
Total += CDbl(txtTotal.Text) : txtGrandtotal.Text = Format(CDbl(CStr(Total)), "##, ####, ####, ###")
txtKdBrg.Text = "" : txtnmbrg.Text = "" : txtSatuan.Text = "" : txtJmlBeli.Text = ""
txtTotal.Text = ""
txtKdBrg.Focus()
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 cmdsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsimpan.Click
Dim counter As Integer
Dim sqll, sql2 As String

Try
sqll = "INSERT INTO SP (NOSP, TGLSP, KDSUP) " & "VALUE('" & txtNoSp.Text & "','" & datetglsp.Text & "','" & txtKdsup.Text & "')"
cmmd1 = New OleDbCommand(sqll, cnn)
Dim x As Integer = cmmd1.ExecuteNonQuery

For counter = 0 To index - 1
sql2 = "INSERT INTO PESAN(TKDBRG,NOSP, JML, HRG) " & "VALUE('" & ListView1.Items(counter).SubItems(0).Text & "','" & txtNoSp.Text & "','" & ListView1.Items(counter).SubItems(3).Text & "','" & ListView1.Items(counter).SubItems(2).Text & "')"
cmmd2 = New OleDbCommand(sql2, cnn)
cmmd2.ExecuteNonQuery()
Next
If x = 1 Then
MessageBox.Show("DATA SP BERHASIL DISIMPAN")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub cmdBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBatal.Click
ListView1.Items.Clear()
index = 0 : Total = 0
txtGrandtotal.Text = ""
End Sub

Private Sub cmdKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdKeluar.Click
Me.Close()
End Sub
End Class

Free Template Blogger collection template Hot Deals BERITA_wongANteng SEO theproperty-developer

0 komentar:

Posting Komentar