APLIKASI PENJUALAN PEMBELIAN DAN LAPORAN LABA RUGI

 

TAHAPAN PEMBUATAN APLIKASI

  1. Membuat project
  2. Membuat database dan beberapa tabel

 

 

3.     Bentuk Relasi Tabel

 

 

4.     MEMBUAT MODULE KONEKSI

 

Imports System.Data.SqlClient

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

 

Module Module1

 

    Public CONN As SqlConnection

    Public DA As SqlDataAdapter

    Public DS As DataSet

    Public CMD As SqlCommand

    Public DR As SqlDataReader

 

    Public Sub Koneksi()

        CONN = New SqlConnection("data source=.\sqlexpress;initial catalog=labarugidb;integrated security=true")

        CONN.Open()

    End Sub

End Module

 

5.     Membuat Form Login

 

 

Imports System.Data.SqlClient

 

Public Class Login

 

    Dim Hitung As Integer = 0

 

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        Call Koneksi()

        CMD = New SqlCommand("select * from tbluser where nama_user='" & TNama.Text & "' and pwd_user='" & TPassword.Text & "'", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            MsgBox("Login gagal")

            Hitung = Hitung + 1

            If Hitung > 2 Then

                End

            End If

            Exit Sub

        Else

            If TPassword.Text <> DR.Item("pwd_user") Then

                MsgBox("password salah")

                TPassword.Focus()

                Exit Sub

            End If

            Me.Visible = False

            MenuUtama.Show()

 

            MenuUtama.Panel1.Text = DR.Item("kode_user")

            MenuUtama.Panel2.Text = DR.Item("nama_user")

            MenuUtama.Panel3.Text = DR.Item("status_user")

            MenuUtama.Panel4.Text = Format(Today, "MMMM") & " " & Format(Today, "yyyy")

 

            If MenuUtama.Panel3.Text <> "ADMIN" Then

                MenuUtama.UserToolStripMenuItem.Visible = False

                MenuUtama.Button1.Visible = False

 

            End If

        End If

    End Sub

 

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

        Me.Close()

    End Sub

 

    Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Koneksi()

        CMD = New SqlCommand("select * from tbluser wHere status_user='ADMIN'", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            TNama.Text = DR.Item("nama_user")

            TPassword.Text = DR.Item("pwd_user")

        Else

            TNama.Clear()

            TPassword.Clear()

        End If

 

    End Sub

End Class

 

 

6.     Membuat Menu Utama

 

 

 

7.     Membuat Form User

 

 

Imports System.Data.SqlClient

 

Public Class User

 

    Sub Kosongkan()

        TextBox1.Clear()

        TextBox2.Clear()

        ComboBox1.Text = ""

        TextBox3.Clear()

        TextBox5.Clear()

        TextBox1.Focus()

    End Sub

 

    Sub DataBaru()

        TextBox2.Clear()

        ComboBox1.Text = ""

        TextBox3.Clear()

        TextBox5.Clear()

        TextBox2.Focus()

    End Sub

 

    Sub Ketemu()

        On Error Resume Next

        TextBox2.Text = DR.Item("nama_User")

        ComboBox1.Text = DR.Item(2)

        TextBox3.Text = DR.Item(3)

        TextBox2.Focus()

    End Sub

 

    Sub TampilStatus_user()

        Call Koneksi()

        CMD = New SqlCommand("select distinct Status_user from tblUser", CONN)

        DR = CMD.ExecuteReader

        ComboBox1.Items.Clear()

        Do While DR.Read

            ComboBox1.Items.Add(DR.Item("Status_user"))

        Loop

    End Sub

 

    Sub TampilGrid()

        Call Koneksi()

        DA = New SqlDataAdapter("select * from tblUser", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

    End Sub

 

    Sub CariKode()

        Call Koneksi()

        CMD = New SqlCommand("select * from tblUser where kode_User='" & TextBox1.Text & "'", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

    End Sub

 

    Private Sub User_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Call Koneksi()

        Call Kosongkan()

        Call TampilStatus_user()

        Call TampilGrid()

    End Sub

 

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        TextBox1.MaxLength = 5

        If e.KeyChar = Chr(13) Then

            Call CariKode()

            If DR.HasRows Then

                Call Ketemu()

            Else

                Call DataBaru()

            End If

        End If

    End Sub

 

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "" Or TextBox2.Text = "" Or ComboBox1.Text = "" Or TextBox3.Text = "" Then

            MsgBox("data belum lengkap")

            Exit Sub

        Else

            Try

                Call CariKode()

                If Not DR.HasRows Then

                    Call Koneksi()

                    Dim simpan As String = "insert into tblUser values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & ComboBox1.Text & "','" & TextBox3.Text & "')"

                    CMD = New SqlCommand(simpan, CONN)

                    CMD.ExecuteNonQuery()

                Else

                    Call Koneksi()

                    Dim edit As String = "update tblUser set nama_User='" & TextBox2.Text & "',Status_user='" & ComboBox1.Text & "',PWD_user='" & TextBox3.Text & "' where kode_User='" & TextBox1.Text & "'"

                    CMD = New SqlCommand(edit, CONN)

                    CMD.ExecuteNonQuery()

                End If

                Call Kosongkan()

                Call TampilGrid()

                Call TampilStatus_user()

            Catch ex As Exception

                MsgBox(ex.Message) ' jelaskan salahnya karena apa...?

            End Try

        End If

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If TextBox1.Text = "" Then

            MsgBox("Kode harus diisi")

            TextBox1.Focus()

            Exit Sub

        End If

 

        Call CariKode()

        If Not DR.HasRows Then

            MsgBox("Kode User tidak terdaftar")

            TextBox1.Focus()

            Exit Sub

        End If

 

        If MessageBox.Show("Yakin akan dihapus...?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

            Call Koneksi()

            Dim hapus As String = "delete  from tblUser where kode_User='" & TextBox1.Text & "'"

            CMD = New SqlCommand(hapus, CONN)

            CMD.ExecuteNonQuery()

            Call Kosongkan()

            Call TampilGrid()

            Call TampilStatus_user()

        Else

            Call Kosongkan()

        End If

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

 

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged

        Call Koneksi()

        DA = New SqlDataAdapter("select * from tblUser where nama_User like '%" & TextBox5.Text & "%'", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

    End Sub

 

    Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick

        On Error Resume Next

        TextBox1.Text = DGV.Rows(e.RowIndex).Cells(0).Value

        Call CariKode()

        If DR.HasRows Then

            Call Ketemu()

        End If

    End Sub

 

End Class

 

 

8.     Membuat Form Barang

 

 

9.     Membuat Form Supplier

 

 

 

10.                       Membuat Form Pembelian

 

Cara melakukan transakasi penjualan :

a.       Ketik nomor nota lalu tekan enter

b.      Pilih supplier

c.       Pilih barang dari datagrid sebelah kanan

d.      Isi pembayaran

e.       Jika data barang sudah sangat banyak, maka pencarian dapat dilakukan melalui textbox bagian bawah sebelah kanan

 

 

Imports System.Data.SqlClient

 

Public Class Pembelian

 

    Sub Bersihkan()

        txtNota.Clear()

        LBLTotalHarga.Text = 0

        TxtDibayar.Text = 0

        LBLKembali.Text = 0

        DGV.Rows.Clear()

        txtNota.Focus()

    End Sub

 

    Sub TampilBarang()

        Call Koneksi()

        DA = New SqlDataAdapter("select * from tblbarang", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.ReadOnly = True

        DGV1.Columns(2).Visible = False

    End Sub

 

    Sub TampilSupplier()

        Call Koneksi()

        CMD = New SqlCommand("select * from tblSupplier", CONN)

        DR = CMD.ExecuteReader

        ListBox1.Items.Clear()

        Do While DR.Read

            ListBox1.Items.Add(DR.Item(0) & Space(2) & DR.Item(1))

        Loop

    End Sub

 

    Private Sub Transaksi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Bersihkan()

        Call TampilBarang()

        Call TampilSupplier()

        TanggalBeli.Text = Format(Today, "dd-MMMM-yyyy")

    End Sub

 

 

    Sub HitungHarga()

        Dim Hitung As Integer = 0

        For Baris As Integer = 0 To DGV.RowCount - 1

            Hitung = Hitung + DGV.Rows(Baris).Cells(4).Value

        Next

        LBLTotalHarga.Text = Hitung

    End Sub

 

    Sub FormatGrid()

        DGV.Columns(2).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(3).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(4).DefaultCellStyle.Format = "###,###,###"

 

        DGV.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        DGV.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

        DGV.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

    End Sub

 

    Private Sub BTNBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNBatal.Click

        Call Bersihkan()

    End Sub

 

    Private Sub BTNTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNTutup.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 'ESC

            DGV.Rows.Remove(DGV.CurrentRow)

            Call HitungHarga()

        End If

 

        If e.KeyChar = Chr(13) Then

            TxtDibayar.Focus()

        End If

    End Sub

 

    Private Sub TxtDibayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtDibayar.KeyPress

        'On Error Resume Next

 

        If e.KeyChar = Chr(13) Then

 

            If Val(TxtDibayar.Text) < Val(LBLTotalHarga.Text) Then

                LBLKembali.Text = Val(TxtDibayar.Text) - Val(LBLTotalHarga.Text)

                MsgBox("Pembayaran kurang")

                BTNSimpan.Enabled = False

                Exit Sub

            ElseIf Val(TxtDibayar.Text) >= Val(LBLTotalHarga.Text) Then

                LBLKembali.Text = Val(TxtDibayar.Text) - Val(LBLTotalHarga.Text)

                BTNSimpan.Enabled = True

                BTNSimpan.Focus()

            End If

        End If

 

        If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or e.KeyChar = vbBack) Then

            e.Handled = True

        End If

    End Sub

 

 

    Private Sub DGV1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV1.CellMouseClick

 

        Dim baris As Integer = DGV.RowCount - 1

 

        DGV.Rows.Add(DGV1.Rows(e.RowIndex).Cells(0).Value, DGV1.Rows(e.RowIndex).Cells(1).Value)

        DGV.Focus()

        DGV.CurrentCell = DGV(2, DGV.CurrentCell.RowIndex)

        SendKeys.Send("{UP}")

 

        TextBox1.Clear()

        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()

                    Exit Sub

                End If

            Next

        Next

 

        Call FormatGrid()

        Call HitungHarga()

        TextBox1.Clear()

    End Sub

 

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Call Koneksi()

        DA = New SqlDataAdapter("select * from tblbarang where nama_barang like '%" & TextBox1.Text & "%'", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.ReadOnly = True

 

    End Sub

 

    Private Sub txtNota_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNota.KeyDown

        If e.KeyCode = Keys.Enter Then

            Call Koneksi()

            CMD = New SqlCommand("SELECT nota from tblpembelian where nota='" & txtNota.Text & "'", CONN)

            DR = CMD.ExecuteReader

            DR.Read()

            If DR.HasRows Then

                MsgBox("nomor nota sudah ada")

                txtNota.Focus()

                Exit Sub

            Else

                ListBox1.Focus()

            End If

        End If

    End Sub

 

End Class

 

11.                       Membuat Form Histori Pembelian

 

 

Imports System.Data.SqlClient

 

Public Class HistoriPembelian

 

    Private Sub HistoriPembelian_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Kosongkan()

        Call Koneksi()

        CMD = New SqlCommand("select Nota from tblPembelian", CONN)

        DR = CMD.ExecuteReader

        Do While DR.Read

            ComboBox1.Items.Add(DR.Item("Nota"))

        Loop

    End Sub

 

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Call Koneksi()

        CMD = New SqlCommand("select * from tblPembelian where Nota='" & ComboBox1.Text & "'", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            LBLTanggal.Text = Format(DR.Item("tanggalbeli"), "dd-MMMM-yyyy")

            LBLTotalHarga.Text = DR.Item("Total_harga_beli")

            TxtDibayar.Text = DR.Item("pembayaran")

            LBLKembali.Text = DR.Item("kembalian")

        End If

 

        Call Koneksi()

        DA = New SqlDataAdapter("select tblbarang.Nama_Barang,tbldetailbeli.Harga_Beli,Jumlah_Beli,Total_Beli from tblbarang,tbldetailbeli where tblbarang.kode_barang=tbldetailbeli.kode_barang and tbldetailbeli.Nota='" & ComboBox1.Text & "'", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

 

        DGV.Columns(0).Width = 250

        DGV.Columns(1).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(2).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(3).DefaultCellStyle.Format = "###,###,###"

 

        DGV.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        DGV.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

        DGV.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        LBLTotalHarga.Text = FormatNumber(LBLTotalHarga.Text, 0)

        TxtDibayar.Text = FormatNumber(TxtDibayar.Text, 0)

        LBLKembali.Text = FormatNumber(LBLKembali.Text, 0)

 

    End Sub

 

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Cetak.Show()

        Cetak.CRV.SelectionFormula = "{tblPembelian.Nota}='" & ComboBox1.Text & "'"

        Cetak.CRV.ReportSource = "nota pembelian.rpt"

        Cetak.CRV.RefreshReport()

    End Sub

 

    Sub Kosongkan()

        ComboBox1.Text = ""

        LBLTanggal.Text = ""

        LBLTotalHarga.Text = ""

        TxtDibayar.Clear()

        LBLKembali.Text = ""

        DGV.Columns.Clear()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

End Class

 

12.                       Membuat Form Penjualan

 

Cara melakukan transaksi penjualan

a.       Pilih data barang dari grid sebelak kanan

b.      Jika data dikilik 2x maka akan terjadi penambahan jumlah jual

c.       Pencarian data barang dialkukan dari texbox bagian bawah data barang

d.      Lakukan pembayaran

e.       Simpan data pembuatan

f.        Cetak struk penjualan

 

 

Imports System.Data.SqlClient

 

Public Class Transaksi

 

    Sub Bersihkan()

        LBLTotalHarga.Text = 0

        TxtDibayar.Text = 0

        LBLKembali.Text = 0

        DGV.Rows.Clear()

    End Sub

 

    Sub TampilBarang()

        Call Koneksi()

        DA = New SqlDataAdapter("select Kode_Barang,Nama_Barang,Harga_Jual from tblbarang where stok>0", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.ReadOnly = True

        DGV1.Columns(2).Visible = False

    End Sub

 

    Sub FakturOtomatis()

        Call Koneksi()

        CMD = New SqlCommand("select faktur from tblpenjualan order by faktur desc", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

        If Not DR.HasRows Then

            LBLFaktur.Text = Format(Today, "yyMMdd") + "0001"

        Else

            If Microsoft.VisualBasic.Left(DR.Item("faktur"), 6) = Format(Today, "yyMMdd") Then

                LBLFaktur.Text = DR.Item("faktur") + 1

            Else

                LBLFaktur.Text = Format(Today, "yyMMdd") + "0001"

            End If

        End If

    End Sub

 

    Private Sub Transaksi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Bersihkan()

        Call FakturOtomatis()

        Call TampilBarang()

        TanggalJual.Text = Format(Today, "dd-MMMM-yyyy")

    End Sub

 

 

    Sub HitungHarga()

        Dim Hitung As Integer = 0

        For Baris As Integer = 0 To DGV.RowCount - 1

            Hitung = Hitung + DGV.Rows(Baris).Cells(4).Value

        Next

       LBLTotalHarga.Text = Hitung

    End Sub

 

    Sub FormatGrid()

        DGV.Columns(2).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(3).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(4).DefaultCellStyle.Format = "###,###,###"

 

        DGV.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        DGV.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

        DGV.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

    End Sub

    Private Sub BTNBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNBatal.Click

        Call Bersihkan()

    End Sub

 

    Private Sub BTNTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNTutup.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 'ESC

            DGV.Rows.Remove(DGV.CurrentRow)

            Call HitungHarga()

        End If

 

        If e.KeyChar = Chr(13) Then

            TxtDibayar.Focus()

        End If

    End Sub

 

    Private Sub TxtDibayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtDibayar.KeyPress

        'On Error Resume Next

 

        If e.KeyChar = Chr(13) Then

 

            If Val(TxtDibayar.Text) < Val(LBLTotalHarga.Text) Then

                LBLKembali.Text = Val(TxtDibayar.Text) - Val(LBLTotalHarga.Text)

                MsgBox("Pembayaran kurang")

                BTNSimpan.Enabled = False

                Exit Sub

            ElseIf Val(TxtDibayar.Text) >= Val(LBLTotalHarga.Text) Then

                LBLKembali.Text = Val(TxtDibayar.Text) - Val(LBLTotalHarga.Text)

                BTNSimpan.Enabled = True

                BTNSimpan.Focus()

            End If

        End If

 

        If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or e.KeyChar = vbBack) Then

            e.Handled = True

        End If

    End Sub

 

    Private Sub DGV1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV1.CellMouseClick

 

        Dim baris As Integer = DGV.RowCount - 1

        DGV.Rows.Add(DGV1.Rows(e.RowIndex).Cells(0).Value, DGV1.Rows(e.RowIndex).Cells(1).Value, DGV1.Rows(e.RowIndex).Cells(2).Value, 1)

 

        DGV.Rows(baris).Cells(4).Value = DGV.Rows(baris).Cells(2).Value * DGV.Rows(baris).Cells(3).Value

        TextBox1.Clear()

        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()

                    Exit Sub

                End If

            Next

        Next

 

        Call FormatGrid()

        Call HitungHarga()

        TextBox1.Clear()

    End Sub

 

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        Call Koneksi()

        DA = New SqlDataAdapter("select Kode_Barang,Nama_Barang,Harga_Jual from tblbarang where stok>0 and nama_barang like '%" & TextBox1.Text & "%'", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.ReadOnly = True

 

    End Sub

End Class

 

 

13.                       Membuat Form Biaya

           

            Cara melakukan transaksi dalam form buata ini adalah sebagai berikut :

  1. Pilih tanggal pengeluaran biaya
  2. Ketik uraian biaya lalu tekan enter
  3. Isi jumlah biaya lalu tekan enter
  4. Setela itu klik tombol simpan

 

 

14.                       Membuat Form Histori Penjualan

 

 

 

Imports System.Data.SqlClient

 

Public Class HistoriPenjualan

 

    Private Sub HistoriPenjualan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Kosongkan()

        Call Koneksi()

        CMD = New SqlCommand("select faktur from tblpenjualan", CONN)

        DR = CMD.ExecuteReader

        Do While DR.Read

            ComboBox1.Items.Add(DR.Item("faktur"))

        Loop

    End Sub

 

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Call Koneksi()

        CMD = New SqlCommand("select * from tblpenjualan where faktur='" & ComboBox1.Text & "'", CONN)

        DR = CMD.ExecuteReader

        DR.Read()

        If DR.HasRows Then

            LBLTanggal.Text = Format(DR.Item("tanggal"), "dd-MMMM-yyyy")

            LBLTotalHarga.Text = DR.Item("Total_harga")

            TxtDibayar.Text = DR.Item("dibayar")

            LBLKembali.Text = DR.Item("kembali")

        End If

 

        Call Koneksi()

        DA = New SqlDataAdapter("select Nama_Barang,Harga,Jumlah,Total from tblbarang,tbldetailjual where tblbarang.kode_barang=tbldetailjual.kode_barang and tbldetailjual.faktur='" & ComboBox1.Text & "'", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV.DataSource = DS.Tables(0)

        DGV.ReadOnly = True

 

        DGV.Columns(0).Width = 250

        DGV.Columns(1).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(2).DefaultCellStyle.Format = "###,###,###"

        DGV.Columns(3).DefaultCellStyle.Format = "###,###,###"

 

        DGV.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        DGV.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

        DGV.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        LBLTotalHarga.Text = FormatNumber(LBLTotalHarga.Text, 0)

        TxtDibayar.Text = FormatNumber(TxtDibayar.Text, 0)

        LBLKembali.Text = FormatNumber(LBLKembali.Text, 0)

 

    End Sub

 

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Cetak.Show()

        Cetak.CRV.SelectionFormula = "{tblpenjualan.faktur}='" & ComboBox1.Text & "'"

        Cetak.CRV.ReportSource = "faktur.rpt"

        Cetak.CRV.RefreshReport()

    End Sub

 

    Sub Kosongkan()

        ComboBox1.Text = ""

        LBLTanggal.Text = ""

        LBLTotalHarga.Text = ""

        TxtDibayar.Clear()

        LBLKembali.Text = ""

        DGV.Columns.Clear()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Call Kosongkan()

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Me.Close()

    End Sub

End Class

 

15.                       Membuat Form Laporan Pembelian

 

 

 

  1. Membuat form laporan penjualan

 

 

 

17.                       Membuat Form Laporan Laba Rugi

 

 

Imports System.Data.SqlClient

 

Public Class LaporanLabaRugi

 

 

    Private Sub LaporanLabaRugi_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Call Koneksi()

        CMD = New SqlCommand("select distinct TGL from tblLABARUGI", CONN)

        DR = CMD.ExecuteReader

        Do While DR.Read

            ListBox1.Items.Add(DR.Item(0))

        Loop

 

        LBLPendapatan.Text = 0

        LBLBiaya.Text = 0

        LBLSaldo.Text = 0

        LBLKeterangan.Text = "-"

    End Sub

 

    Sub HitungTransaksi()

 

        LBLPendapatan.Text = 0

        LBLBiaya.Text = 0

        LBLSaldo.Text = 0

 

        Dim hitung1 As Double

        For baris1 As Integer = 0 To DGV1.RowCount - 1

            hitung1 = hitung1 + DGV1.Rows(baris1).Cells(2).Value

        Next

        LBLPendapatan.Text = FormatNumber(hitung1, 0)

 

        Dim hitung2 As Double

        For baris2 As Integer = 0 To DGV2.RowCount - 1

            hitung2 = hitung2 + DGV2.Rows(baris2).Cells(3).Value

        Next

        LBLBiaya.Text = FormatNumber(hitung2, 0)

 

 

        LBLSaldo.Text = Val(Microsoft.VisualBasic.Str(LBLPendapatan.Text)) - Val(Microsoft.VisualBasic.Str(LBLBiaya.Text))

        LBLSaldo.Text = FormatNumber(LBLSaldo.Text, 0)

        If Val(LBLSaldo.Text) < 0 Then

            LBLKeterangan.Text = "RUGI"

        Else

            LBLKeterangan.Text = "LABA"

        End If

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        'tampilkan rincian pendapatan di dgv1

        Call Koneksi()

        DA = New SqlDataAdapter("Select * FROM tblLABARUGI where month(tbllabarugi.tgl)='" & Month(BulanTahun.Text) & "' and year(tbllabarugi.tgl)='" & Year(BulanTahun.Text) & "' and keteraNgan=' PENJUALAN' order by tgl", CONN)

 

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.Columns(4).Visible = False

        DGV1.Columns("TGL").DefaultCellStyle.Format = "dd-MMMM-yyyy"

        DGV1.Columns(2).DefaultCellStyle.Format = "#,###"

        DGV1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        DGV1.Columns(3).DefaultCellStyle.Format = "#,###"

        DGV1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        'tampilkan rincian biaya di dgv2

        Call Koneksi()

        DA = New SqlDataAdapter("Select * FROM tblLABARUGI where month(tbllabarugi.tgl)='" & Month(BulanTahun.Text) & "' and year(tbllabarugi.tgl)='" & Year(BulanTahun.Text) & "' and keteraNgan<> ' PENJUALAN' order by tgl", CONN)

 

        DS = New DataSet

        DA.Fill(DS)

        DGV2.DataSource = DS.Tables(0)

        DGV2.Columns(4).Visible = False

        DGV2.Columns("TGL").DefaultCellStyle.Format = "dd-MMMM-yyyy"

        DGV2.Columns(2).DefaultCellStyle.Format = "#,###"

        DGV2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        DGV2.Columns(3).DefaultCellStyle.Format = "#,###"

        DGV2.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        Call HitungTransaksi()

 

        CRV.ReportSource = Nothing

        CRV.SelectionFormula = "month({tblLABARUGI.tGL})=(" & Month(BulanTahun.Text) & ") and year({tblLABARUGI.TGL})=(" & Year(BulanTahun.Text) & ")"

        CRV.ReportSource = "laba rugi BULANAN OK.rpt"

        CRV.RefreshReport()

    End Sub

 

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

 

        'tampilkan rincian pendapatan di dgv1

        Call Koneksi()

        DA = New SqlDataAdapter("Select * from tblLABARUGI where TGL='" & Format(DateValue(ListBox1.Text), "yyyy-MM-dd") & "' AND KETERANGAN=' PENJUALAN' order by TGL", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV1.DataSource = DS.Tables(0)

        DGV1.Columns(4).Visible = False

        DGV1.Columns("tgl").DefaultCellStyle.Format = "dd-MMMM-yyyy"

        DGV1.Columns(2).DefaultCellStyle.Format = "#,###"

        DGV1.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        DGV1.Columns(3).DefaultCellStyle.Format = "#,###"

        DGV1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

 

        'tampilkan rincian biaya dalam dgv2

        Call Koneksi()

        DA = New SqlDataAdapter("Select * from tblLABARUGI where TGL='" & Format(DateValue(ListBox1.Text), "yyyy-MM-dd") & "' AND KETERaNGAN<>' PENJUALAN' order by tgl", CONN)

        DS = New DataSet

        DA.Fill(DS)

        DGV2.DataSource = DS.Tables(0)

        DGV2.Columns(4).Visible = False

        DGV2.Columns("tgl").DefaultCellStyle.Format = "dd-MMMM-yyyy"

 

        DGV2.Columns(2).DefaultCellStyle.Format = "#,###"

        DGV2.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        DGV2.Columns(3).DefaultCellStyle.Format = "#,###"

        DGV2.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

 

        Call HitungTransaksi()

        CRV.SelectionFormula = "totext({tblLABARUGI.TGL})='" & ListBox1.Text & "'"

        CRV.ReportSource = "laba rugi pertanggal OK.rpt"

        CRV.RefreshReport()

    End Sub

 

    Private Sub LBLKeterangan_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LBLKeterangan.TextChanged

        If LBLKeterangan.Text = "LABA" Then

            LBLKeterangan.ForeColor = Color.Blue

        Else

            LBLKeterangan.ForeColor = Color.Red

        End If

    End Sub

End Class