Advertisement
Guest User

Untitled

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