Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class Penjualan
- Sub kosongkan()
- Cmbkode.Text = ""
- Lnama.Text = ""
- Ltotal.Text = ""
- Tdibayar.Text = ""
- Lkembali.Text = ""
- Lbrg.Text = ""
- DGV.Rows.Clear()
- Cmbkode.Focus()
- End Sub
- Sub notis()
- cmd = New OleDbCommand("select faktur from tblpenjualan order by faktur desc", conn)
- dr = cmd.ExecuteReader
- dr.Read()
- If Not dr.HasRows Then
- Lfaktur.Text = "0000000001"
- Else
- Lfaktur.Text = Format(Microsoft.VisualBasic.Right(dr(0), 10) + 1, "0000000000")
- End If
- End Sub
- Sub hitungharga()
- Dim x As Integer
- For baris As Integer = 0 To DGV.RowCount - 1
- x = x + DGV.Rows(baris).Cells(4).Value
- Next
- Ltotal.Text = x
- End Sub
- Sub hitungbarang()
- Dim y As Integer
- For baris As Integer = 0 To DGV.RowCount - 1
- y = y + DGV.Rows(baris).Cells(3).Value
- Next
- Lbrg.Text = y
- End Sub
- Private Sub Penjualan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Me.CenterToScreen()
- Call koneksi()
- Call notis()
- Ltanggal.Text = Format(Today, "dd-MMMMMMMMMM-yyyy")
- 'KODE CUSTOMER ======================
- cmd = New OleDbCommand("select*from tblcustomer", conn)
- dr = cmd.ExecuteReader
- Do While dr.Read
- Cmbkode.Items.Add(dr(0))
- Loop
- End Sub
- Private Sub Cmbkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmbkode.SelectedIndexChanged
- cmd = New OleDbCommand("select*from tblcustomer where kode_customer='" & Cmbkode.Text & "'", conn)
- dr = cmd.ExecuteReader
- dr.Read()
- If dr.HasRows Then
- Lnama.Text = dr(1)
- End If
- End Sub
- Private Sub DGV_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellEndEdit
- If e.ColumnIndex = 0 Then
- For barisatas As Integer = 0 To DGV.RowCount - 1
- For barisbawah As Integer = barisatas + 1 To DGV.RowCount - 1
- If DGV.Rows(barisbawah).Cells(0).Value = DGV.Rows(barisatas).Cells(0).Value Then
- DGV.Rows(barisatas).Cells(3).Value = DGV.Rows(barisatas).Cells(3).Value + 1
- DGV.Rows(barisatas).Cells(4).Value = DGV.Rows(barisatas).Cells(2).Value * DGV.Rows(barisatas).Cells(3).Value
- DGV.Rows.RemoveAt(barisbawah)
- Call hitungharga()
- SendKeys.Send("{down}")
- Exit Sub
- End If
- Next
- Next
- cmd = New OleDbCommand("select*from tblbarang where kode_barang='" & DGV.Rows(e.RowIndex).Cells(0).Value & "'", conn)
- dr = cmd.ExecuteReader
- dr.Read()
- If dr.HasRows Then
- DGV.Rows(e.RowIndex).Cells(1).Value = dr("nama_barang")
- DGV.Rows(e.RowIndex).Cells(2).Value = dr("harga_jual")
- DGV.Rows(e.RowIndex).Cells(3).Value = 1
- DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
- Else
- MsgBox("Kode Belum Daftar Gann")
- DGV.Rows(e.RowIndex).Cells(0).Value = ""
- DGV.Rows.Remove(DGV.CurrentRow)
- SendKeys.Send("{down}")
- End If
- End If
- If e.ColumnIndex = 3 Then
- Try
- If DGV.Rows(e.RowIndex).Cells(3).Value > dr.Item("stok") Then
- MsgBox("Stok hanya ada" & dr.Item("stok") & "")
- SendKeys.Send("{up}")
- DGV.Rows(e.RowIndex).Cells(3).Value = dr.Item("stok")
- DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
- Else
- DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
- End If
- Catch ex As Exception
- MsgBox("Harus Angka Gan")
- SendKeys.Send("{up}")
- DGV.Rows(e.RowIndex).Cells(3).Value = 1
- DGV.Rows(e.RowIndex).Cells(4).Value = DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value
- End Try
- End If
- Call hitungharga()
- Call hitungbarang()
- End Sub
- Private Sub DGV_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DGV.KeyDown
- On Error Resume Next
- If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Escape Then
- DGV.Rows.Remove(DGV.CurrentRow)
- Call hitungharga()
- End If
- If e.KeyCode = Keys.Enter Then
- Tdibayar.Clear()
- Tdibayar.Focus()
- End If
- End Sub
- Private Sub Tdibayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Tdibayar.KeyPress
- If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or e.KeyChar = vbBack) Then '0-9
- e.Handled = True
- End If
- If e.KeyChar = Chr(13) Then
- If Val(Tdibayar.Text) < Val(Ltotal.Text) Then
- MsgBox("Pembayaran Kurang Gan")
- Exit Sub
- ElseIf Val(Tdibayar.Text) >= Val(Ltotal.Text) Then
- Lkembali.Text = Val(Tdibayar.Text) - Val(Ltotal.Text)
- Button1.Focus()
- End If
- End If
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- If Cmbkode.Text = "" Or
- Tdibayar.Text = "" Then
- MsgBox("Transaksi Belum Lengkap Gan")
- Exit Sub
- End If
- Dim simpan As String = "insert into tblpenjualan values('" & Lfaktur.Text & "','" & Ltanggal.Text & "','" & Cmbkode.Text & "','" & Lbrg.Text & "','" & Ltotal.Text & "','" & Tdibayar.Text & "','" & Lkembali.Text & "','USR01')"
- cmd = New OleDbCommand(simpan, conn)
- cmd.ExecuteNonQuery()
- For baris As Integer = 0 To DGV.RowCount - 2
- Dim simpandetail As String = "insert into tbldetailjual values('" & Lfaktur.Text & "','" &
- DGV.Rows(baris).Cells(0).Value & "','" & DGV.Rows(baris).Cells(2).Value & "','" &
- DGV.Rows(baris).Cells(3).Value & "','" & DGV.Rows(baris).Cells(4).Value & "')"
- cmd = New OleDbCommand(simpandetail, conn)
- cmd.ExecuteNonQuery()
- cmd = New OleDbCommand("select * from tblbarang where kode_barang='" & DGV.Rows(baris).Cells(0).Value & "'", conn)
- dr = cmd.ExecuteReader
- dr.Read()
- If dr.HasRows Then
- Dim kurangistok As String = "update tblbarang set stok='" & dr.Item("stok") - DGV.Rows(baris).Cells(3).Value & "' where kode_barang ='" & DGV.Rows(baris).Cells(0).Value & "'"
- cmd = New OleDbCommand(kurangistok, conn)
- cmd.ExecuteNonQuery()
- End If
- Next
- Call kosongkan()
- Call notis()
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Call notis()
- Call kosongkan()
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- Me.Close()
- End Sub
- Private Sub DGV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGV.KeyPress
- On Error Resume Next
- If e.KeyChar = Chr(27) Then
- DGV.Rows.Remove(DGV.CurrentRow)
- Call hitungharga()
- Call hitungbarang()
- End If
- If e.KeyChar = Chr(13) Then
- Tdibayar.Focus()
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement