Sabtu, 07 Maret 2015

Membuat Aplikasi Input Data Barang

Penjelasan :
Aplikasi ini bertujuan untuk menyimpan data barang dalam suatu gudang.

Screen Shoot :



Source Code :

Script koneksi.vb
Imports System.Data.OleDb
Module koneksi
    Public conn As New OleDbConnection
    Public sql As String
    Public dttable As New DataTable
    Public dtadapter As New OleDbDataAdapter
    Public cmd As New OleDbCommand
    Public reader As OleDbDataReader
    Public ds As DataSet
    Public dc As DataColumn
    Sub koneksiData()
        sql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\bin\Debug\DataBarang.mdb"
        conn = New OleDbConnection(sql)
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
    End Sub

End Module
 
 
Script Form1.vb
Imports System.Data.OleDb
Public Class Form1
    Dim Akses As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        koneksiData()
        Call data()
        Call kode()
        Akses = "Add"
        Call tombol()
    End Sub
    Sub tombol()
        If Akses = "Add" Then
            btnAdd.Enabled = True
            btnEdit.Enabled = False
            btnDelete.Enabled = False
        ElseIf Akses = "Edit" Then
            btnAdd.Enabled = False
            btnEdit.Enabled = True
            btnDelete.Enabled = True
        End If
    End Sub
    Sub data()
        koneksiData()
        cmd = New OleDbCommand("select * from barang", conn)
        ds = New DataSet
        ds.Clear()
        dtadapter.Fill(ds, "temporer")
        dgvBarang.DataSource = (ds.Tables("temporer"))
        dgvBarang.ReadOnly = True
        cmd.Dispose()
        conn.Close()

    End Sub
    Sub kode()
        koneksiData()
        cmd = New OleDbCommand("select top(1) kodebarang from barang order by kodebarang desc", conn)
        reader = cmd.ExecuteReader
        reader.Read()
        If reader.HasRows Then
            lblKode.Text = reader.Item(0) + 1
        End If
        reader.Close()
        cmd.Dispose()
        conn.Close()

    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        koneksiData()
        cmd = New OleDbCommand("insert into barang values('" & txtNama.Text & "', '" & cmbSatuan.Text & "','" & txtStok.Text & "')", conn)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
        MsgBox("Data berhasil ditambahkan", MsgBoxStyle.Information, "Data Barang")
        Call kosong()
        Akses = "Add"
        Call tombol()
        Call data()
    End Sub
    Sub kosong()
        Call kode()
        txtNama.Text = ""
        cmbSatuan.Text = ""
        txtStok.Text = ""
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        koneksiData()
        cmd = New OleDbCommand("update barang set namabarang = '" & txtNama.Text & "', satuan = '" & cmbSatuan.Text & "', stokbarang ='" & txtStok.Text & "' where kodebarang = '" & lblKode.Text & "'", conn)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
        MsgBox("Data Barang dengan kode '" & lblKode.Text & "' berhasil diubah", MsgBoxStyle.Information, "Data Barang")
        Call kosong()
        Akses = "Add"
        Call tombol()
        Call data()
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        koneksiData()
        cmd = New OleDbCommand("delete barang where kodebarang = '" & lblKode.Text & "'", conn)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
        MsgBox("Data Barang dengan kode '" & lblKode.Text & "' berhasil dihapus", MsgBoxStyle.Information, "Data Barang")
        Call kosong()
        Akses = "Add"
        Call tombol()
        Call data()
    End Sub

    Private Sub dgvBarang_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvBarang.CellDoubleClick
        Akses = "Edit"

        cmd = New OleDbCommand("select * from barang where kodebarang = '" & dgvBarang.SelectedCells.Item(0).Value & "'", conn)
        reader = cmd.ExecuteReader
        reader.Read()
        If reader.HasRows Then
            lblKode.Text = reader.Item(0)
            txtNama.Text = reader.Item(1)
            cmbSatuan.Text = reader.Item(2)
            txtStok.Text = reader.Item(3)
        End If
        reader.Close()
        cmd.Dispose()
        conn.Close()

    End Sub
End Class
 

Senin, 08 Desember 2014

Membuat Aplikasi Administrasi Pembayaran Rumah Sakit

Penjelasan :
Aplikasi ini bertujuan untuk mempermudah kasir untuk menghitung total biaya yang harus dibayar oleh anggota keluarga pasien.

Fitur yang terdapat pada aplikasi ini adalah :
1. Ketentuan harga per kamar.
2. Tombol Proses, untuk menghitung total biaya yang harus dibayar oleh para anggota keluarga pasien.
3. Tombol Batal, untuk membatalkan proses pembayaran.
4. Tombol Keluar, untuk keluar dari aplikasi ini.

Screen Shoot :




Source Code :
Form1.vb
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cbTK.Items.Add("Anggrek")
        cbTK.Items.Add("Mawar")
        cbTK.Items.Add("Melati")

        For tagor As Integer = 1 To 3
            cbR.Items.Add(tagor)
        Next

        tbHargaPerHari.Enabled = False
        tbTotalHarga.Enabled = False
    End Sub

    Private Sub proses()
        Dim hitung As kelasna = New kelasna
        If cbTK.SelectedItem = "Anggrek" Then
            Select Case cbR.Text
                Case Is = "1"
                    tbHargaPerHari.Text = "90000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "2"
                    tbHargaPerHari.Text = "80000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "3"
                    tbHargaPerHari.Text = "70000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
            End Select
        ElseIf cbTK.SelectedItem = "Mawar" Then
            Select Case cbR.Text
                Case Is = "1"
                    tbHargaPerHari.Text = "60000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "2"
                    tbHargaPerHari.Text = "50000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "3"
                    tbHargaPerHari.Text = "40000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
            End Select
        ElseIf cbTK.SelectedItem = "Melati" Then
            Select Case cbR.Text
                Case Is = "1"
                    tbHargaPerHari.Text = "30000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "2"
                    tbHargaPerHari.Text = "20000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
                Case Is = "3"
                    tbHargaPerHari.Text = "10000"
                    tbHargaPerHari.Text = FormatNumber(tbHargaPerHari.Text)
            End Select
        End If
        tbTotalHarga.Text = hitung.perkalian(tbTotalHari.Text, tbHargaPerHari.Text)
        tbTotalHarga.Text = FormatNumber(tbTotalHarga.Text)
    End Sub

    Private Sub batal()
        cbTK.SelectedIndex = 0
        cbR.SelectedIndex = 0
        DTPtm.Text = Date.Now
        DTPtk.Text = Date.Now
        tbTotalHari.Text = 0
        tbHargaPerHari.Text = 0
        tbTotalHarga.Text = 0
    End Sub

    Private Sub keluar()
        Dim message As String
        message = MsgBox("Apakah anda yakin akan keluar dari aplikasi ini?", MsgBoxStyle.YesNo, "Konfirmasi!")
        If message = vbYes Then
            Me.Close()
        End If
    End Sub

    Private Sub btnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProses.Click
        proses()
    End Sub

    Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
        batal()
    End Sub

    Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
        keluar()
    End Sub
End Class

Class1.vb
Public Class kelasna
    Public Function perkalian(ByVal nilai1 As Integer, ByVal nilai2 As Double)
        Dim hasil As Double
        hasil = nilai1 * nilai2
        Return hasil
    End Function
End Class