Advertisement
Guest User

Untitled

a guest
May 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.99 KB | None | 0 0
  1. Imports System.Data.OleDb
  2. Public Class Penjualan
  3.     Sub kosongkan()
  4.         Cmbkode.Text = ""
  5.         Lnama.Text = ""
  6.         Ltotal.Text = ""
  7.         Tdibayar.Text = ""
  8.         Lkembali.Text = ""
  9.         Lbrg.Text = ""
  10.         DGV.Rows.Clear()
  11.         Cmbkode.Focus()
  12.     End Sub
  13.     Sub notis()
  14.         cmd = New OleDbCommand("select faktur from tblpenjualan order by faktur desc", conn)
  15.         dr = cmd.ExecuteReader
  16.         dr.Read()
  17.         If Not dr.HasRows Then
  18.             Lfaktur.Text = "0000000001"
  19.         Else
  20.             Lfaktur.Text = Format(Microsoft.VisualBasic.Right(dr(0), 10) + 1, "0000000000")
  21.         End If
  22.     End Sub
  23.     Sub hitungharga()
  24.         Dim x As Integer
  25.         For baris As Integer = 0 To DGV.RowCount - 1
  26.             x = x + DGV.Rows(baris).Cells(4).Value
  27.         Next
  28.         Ltotal.Text = x
  29.     End Sub
  30.     Sub hitungbarang()
  31.         Dim y As Integer
  32.         For baris As Integer = 0 To DGV.RowCount - 1
  33.             y = y + DGV.Rows(baris).Cells(3).Value
  34.         Next
  35.         Lbrg.Text = y
  36.     End Sub
  37.     Private Sub Penjualan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  38.         Me.CenterToScreen()
  39.         Call koneksi()
  40.         Call notis()
  41.         Ltanggal.Text = Format(Today, "dd-MMMMMMMMMM-yyyy")
  42.         'KODE CUSTOMER ======================
  43.         cmd = New OleDbCommand("select*from tblcustomer", conn)
  44.         dr = cmd.ExecuteReader
  45.         Do While dr.Read
  46.             Cmbkode.Items.Add(dr(0))
  47.         Loop
  48.     End Sub
  49.     Private Sub Cmbkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmbkode.SelectedIndexChanged
  50.         cmd = New OleDbCommand("select*from tblcustomer where kode_customer='" & Cmbkode.Text & "'", conn)
  51.         dr = cmd.ExecuteReader
  52.         dr.Read()
  53.         If dr.HasRows Then
  54.             Lnama.Text = dr(1)
  55.         End If
  56.     End Sub
  57.     Private Sub DGV_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellEndEdit
  58.         If e.ColumnIndex = 0 Then
  59.             For barisatas As Integer = 0 To DGV.RowCount - 1
  60.                 For barisbawah As Integer = barisatas + 1 To DGV.RowCount - 1
  61.                     If DGV.Rows(barisbawah).Cells(0).Value = DGV.Rows(barisatas).Cells(0).Value Then
  62.                         DGV.Rows(barisatas).Cells(3).Value = DGV.Rows(barisatas).Cells(3).Value + 1
  63.                         DGV.Rows(barisatas).Cells(4).Value = DGV.Rows(barisatas).Cells(2).Value * DGV.Rows(barisatas).Cells(3).Value
  64.                         DGV.Rows.RemoveAt(barisbawah)
  65.                         Call hitungharga()
  66.                         SendKeys.Send("{down}")
  67.                         Exit Sub
  68.                     End If
  69.                 Next
  70.             Next
  71.             cmd = New OleDbCommand("select*from tblbarang where kode_barang='" & DGV.Rows(e.RowIndex).Cells(0).Value & "'", conn)
  72.             dr = cmd.ExecuteReader
  73.             dr.Read()
  74.             If dr.HasRows Then
  75.                 DGV.Rows(e.RowIndex).Cells(1).Value = dr("nama_barang")
  76.                 DGV.Rows(e.RowIndex).Cells(2).Value = dr("harga_jual")
  77.                 DGV.Rows(e.RowIndex).Cells(3).Value = 1
  78.                 DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
  79.             Else
  80.                 MsgBox("Kode Belum Daftar Gann")
  81.                 DGV.Rows(e.RowIndex).Cells(0).Value = ""
  82.                 DGV.Rows.Remove(DGV.CurrentRow)
  83.                 SendKeys.Send("{down}")
  84.             End If
  85.         End If
  86.         If e.ColumnIndex = 3 Then
  87.             Try
  88.                 If DGV.Rows(e.RowIndex).Cells(3).Value > dr.Item("stok") Then
  89.                     MsgBox("Stok hanya ada" & dr.Item("stok") & "")
  90.                     SendKeys.Send("{up}")
  91.                     DGV.Rows(e.RowIndex).Cells(3).Value = dr.Item("stok")
  92.                     DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
  93.                 Else
  94.                     DGV.Rows(e.RowIndex).Cells(4).Value = (DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value)
  95.                 End If
  96.             Catch ex As Exception
  97.                 MsgBox("Harus Angka Gan")
  98.                 SendKeys.Send("{up}")
  99.                 DGV.Rows(e.RowIndex).Cells(3).Value = 1
  100.                 DGV.Rows(e.RowIndex).Cells(4).Value = DGV.Rows(e.RowIndex).Cells(2).Value * DGV.Rows(e.RowIndex).Cells(3).Value
  101.             End Try
  102.         End If
  103.         Call hitungharga()
  104.         Call hitungbarang()
  105.     End Sub
  106.     Private Sub DGV_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DGV.KeyDown
  107.         On Error Resume Next
  108.         If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Escape Then
  109.             DGV.Rows.Remove(DGV.CurrentRow)
  110.             Call hitungharga()
  111.         End If
  112.         If e.KeyCode = Keys.Enter Then
  113.             Tdibayar.Clear()
  114.             Tdibayar.Focus()
  115.         End If
  116.     End Sub
  117.     Private Sub Tdibayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Tdibayar.KeyPress
  118.         If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or e.KeyChar = vbBack) Then '0-9
  119.             e.Handled = True
  120.         End If
  121.         If e.KeyChar = Chr(13) Then
  122.             If Val(Tdibayar.Text) < Val(Ltotal.Text) Then
  123.                 MsgBox("Pembayaran Kurang Gan")
  124.                 Exit Sub
  125.             ElseIf Val(Tdibayar.Text) >= Val(Ltotal.Text) Then
  126.                 Lkembali.Text = Val(Tdibayar.Text) - Val(Ltotal.Text)
  127.                 Button1.Focus()
  128.             End If
  129.         End If
  130.     End Sub
  131.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  132.         If Cmbkode.Text = "" Or
  133.             Tdibayar.Text = "" Then
  134.             MsgBox("Transaksi Belum Lengkap Gan")
  135.             Exit Sub
  136.         End If
  137.         Dim simpan As String = "insert into tblpenjualan values('" & Lfaktur.Text & "','" & Ltanggal.Text & "','" & Cmbkode.Text & "','" & Lbrg.Text & "','" & Ltotal.Text & "','" & Tdibayar.Text & "','" & Lkembali.Text & "','USR01')"
  138.         cmd = New OleDbCommand(simpan, conn)
  139.         cmd.ExecuteNonQuery()
  140.         For baris As Integer = 0 To DGV.RowCount - 2
  141.             Dim simpandetail As String = "insert into tbldetailjual values('" & Lfaktur.Text & "','" &
  142.                 DGV.Rows(baris).Cells(0).Value & "','" & DGV.Rows(baris).Cells(2).Value & "','" &
  143.                 DGV.Rows(baris).Cells(3).Value & "','" & DGV.Rows(baris).Cells(4).Value & "')"
  144.             cmd = New OleDbCommand(simpandetail, conn)
  145.             cmd.ExecuteNonQuery()
  146.  
  147.             cmd = New OleDbCommand("select * from tblbarang where kode_barang='" & DGV.Rows(baris).Cells(0).Value & "'", conn)
  148.             dr = cmd.ExecuteReader
  149.             dr.Read()
  150.             If dr.HasRows Then
  151.                 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 & "'"
  152.                 cmd = New OleDbCommand(kurangistok, conn)
  153.                 cmd.ExecuteNonQuery()
  154.             End If
  155.         Next
  156.         Call kosongkan()
  157.         Call notis()
  158.     End Sub
  159.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  160.         Call notis()
  161.         Call kosongkan()
  162.     End Sub
  163.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  164.         Me.Close()
  165.     End Sub
  166.     Private Sub DGV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGV.KeyPress
  167.         On Error Resume Next
  168.         If e.KeyChar = Chr(27) Then
  169.             DGV.Rows.Remove(DGV.CurrentRow)
  170.             Call hitungharga()
  171.             Call hitungbarang()
  172.         End If
  173.         If e.KeyChar = Chr(13) Then
  174.             Tdibayar.Focus()
  175.         End If
  176.     End Sub
  177. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement