Program Penjualan Pulsa Sederhana~Seberkas Coretan

Tuesday, March 11, 2014

Program Penjualan Pulsa Sederhana

Belajar VB.Net 2008Express
Koneksi acess dengan vb2008
siapkan file ms acces yang sudah terdapat data table di dalamnya ok. Berikut Tampilan Form dan Source Kodenya. dan Jika Ingin Mencoba Terlebih dahulu Silahkan DOWLOAD diSiNi

Buka VB
Buat Modul Ketikkan Atau Kopi Paste Code Berikut
Modul

Imports System.Data
Imports System.Data.Odbc.OdbcConnection
Module ModulInputData
    Public DataPulsa As Data.OleDb.OleDbConnection
    Public Sub KoneksiDataPulsa()
        Try
            DataPulsa = New OleDb.OleDbConnection(My.Settings.PulsaConnectionString)
            DataPulsa.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Module



Calss/ Klik 2Kali pada Form
Public Class InputData
    Dim DA As OleDb.OleDbDataAdapter
    Dim DS As DataSet
    Dim BSC As New BindingSource
    Sub Koneksi()
        KoneksiDataPulsa()
        DA = New OleDb.OleDbDataAdapter("Select * from pulsa", DataPulsa)
        DS = New DataSet
        DA.Fill(DS)
        BSC.DataSource = DS
        BSC.DataMember = DS.Tables(0).ToString()
        DataGridView1.DataSource = BSC
    End Sub
    Private Sub SisaSaldo()
        Try
            Dim DataGrid As Integer
            DataGrid = DataGridView1.CurrentRow.Index
            TextBox3.Text = DataGridView1.Item(9, DataGrid).Value
            BSC.MoveLast()
        Catch ex As Exception
        End Try
    End Sub
    Sub HapusDataInput()
        TextBox1.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        TextBox10.Text = ""
        Koneksi()
        SisaSaldo()
        BSC.MoveLast()
    End Sub
    Sub combo()
        ComboBox1.Text = "Indosat"
        ComboBox1.Items.Add("Indosat")
        ComboBox1.Items.Add("XL")
        ComboBox1.Items.Add("Axis")
        ComboBox1.Items.Add("Telkomsel/ Simpati")
        ComboBox1.Items.Add("Telkomsel/ AS")
        ComboBox1.Items.Add("Esia")
        ComboBox1.Items.Add("SmartFren")
        ComboBox1.Items.Add("PLN")
    End Sub
    Private Sub InputData_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Koneksi()
        SisaSaldo()
        combo()
        TextBox10.BackColor = Color.Black
        TextBox9.ReadOnly = True
        TextBox10.ReadOnly = True
        DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aquamarine
        DataGridView1.AutoResizeColumns()
        DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
        DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
        DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue
        DataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Sunken
        HapusDataInput()
        MaximizeBox = False
        datagride()
        TextBox2.Text = Format(Now, "hh:mm:ss")
    End Sub
    Private Sub bSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bSimpan.Click
        If TextBox1.Text = "" Then
            MsgBox("ID Masih Kosong", vbCritical, "ERROR BOSS")
        Else
            Try
                Dim CMMD As New OleDb.OleDbCommand
                CMMD.Connection = DataPulsa
                CMMD.CommandType = CommandType.Text
                CMMD.CommandText = "insert into pulsa values('" & TextBox1.Text & "','" & DateTimePicker1.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & ComboBox1.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox7.Text & "','" & TextBox9.Text & "')"
                CMMD.ExecuteNonQuery()
                MsgBox("Input Data Berhasil Disimpan", vbOKOnly, "Input Data Pulsa")
                HapusDataInput()
            Catch ex As Exception
                MsgBox("Gagal, Priksa Kembali, Data Input Harus Lengkap!!!", vbCritical, "ERROR BOSS")
            End Try
        End If
        Try
            TextBox9.Text = TextBox3.Text - TextBox6.Text
        Catch ex As Exception
        End Try
        HapusDataInput()
    End Sub
    Private Sub bHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bHapus.Click
        If TextBox1.Text = "" Then
            MsgBox("Masukkan ID Data Yang Akan DiHapus", vbCritical, "ERROR BOSS")
        Else
            Dim Konfirmasi
            Konfirmasi = MsgBox("Yakin Nih DiHapus", vbYesNo, "Konfirmasi Penghapusan")
            If Konfirmasi = vbYes Then
                Try
                    Dim CMMD As New OleDb.OleDbCommand
                    CMMD.Connection = DataPulsa
                    CMMD.CommandType = CommandType.Text
                    CMMD.CommandText = "Delete from pulsa where ID='" & TextBox1.Text & "'"
                    CMMD.ExecuteScalar()
                    MsgBox("Data DiHapus", vbOKOnly, "Konfirmasi Penghapusan")
                    HapusDataInput()
                Catch ex As Exception
                    MsgBox("Data Gagal DiHapus, Periksa Kembali ID", vbCritical, "ERROR")
                End Try
                If Konfirmasi = vbNo Then Exit Sub
            End If
            End If
    End Sub
    Private Sub bCari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCari.Click
        If TextBox1.Text = "" Then
            MsgBox("Ketikkan ID Data Yang Akan DiCari", vbCritical, "ERROR")
        Else
            Try
                DS.Tables(0).PrimaryKey = New DataColumn() {DS.Tables(0).Columns("ID")}
                Dim BarisData As DataRow
                BarisData = DS.Tables(0).Rows.Find(TextBox1.Text)
                TextBox1.Text = BarisData("ID")
                DateTimePicker1.Text = BarisData("Tanggal_Pembelian")
                TextBox3.Text = BarisData("Saldo")
                TextBox4.Text = BarisData("Nama")
                TextBox5.Text = BarisData("Nomor_HP")
                ComboBox1.Text = BarisData("Operator")
                TextBox6.Text = BarisData("Harga_Operator")
                TextBox7.Text = BarisData("Harga_Jual")
                TextBox8.Text = BarisData("Bayar")
                TextBox9.Text = BarisData("Sisa_Saldo")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub
    Private Sub bEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bEdit.Click
        If TextBox1.Text = "" Then
            MsgBox("Gunakan Button Pencarian Untuk Mencari Data Yang Akan DiEdit", vbCritical, "ERROR BOSS")
        Else
            Try
                Call KoneksiDataPulsa()
                Dim CMD As New OleDb.OleDbCommand
                CMD.Connection = DataPulsa
                CMD.CommandType = CommandType.Text
                CMD.CommandText = "Update pulsa set Tanggal_Pembelian= '" & DateTimePicker1.Text & "',Saldo='" & TextBox3.Text & "',Nama='" & TextBox4.Text & "',Nomor_HP='" & TextBox5.Text & "',Operator='" & ComboBox1.Text & "',Harga_Operator='" & TextBox6.Text & "',Harga_Jual='" & TextBox7.Text & "', Bayar='" & TextBox8.Text & "', Sisa_Saldo='" & TextBox9.Text & "' where ID='" & TextBox1.Text & "'"
                CMD.ExecuteNonQuery()
                MsgBox("Data  Sudah Di Update")
                Call HapusDataInput()
            Catch ex As Exception
                MsgBox("Gagal", vbCritical, "ERROR BOSS")
            End Try
        End If
    End Sub
    Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim DataGrid As Integer
        Try
            DataGrid = DataGridView1.CurrentRow.Index
            TextBox1.Text = DataGridView1.Item(0, DataGrid).Value
            DateTimePicker1.Text = DataGridView1.Item(1, DataGrid).Value
            TextBox3.Text = DataGridView1.Item(2, DataGrid).Value
            TextBox4.Text = DataGridView1.Item(3, DataGrid).Value
            TextBox5.Text = DataGridView1.Item(4, DataGrid).Value
            ComboBox1.Text = DataGridView1.Item(5, DataGrid).Value
            TextBox6.Text = DataGridView1.Item(6, DataGrid).Value
            TextBox7.Text = DataGridView1.Item(7, DataGrid).Value
            TextBox8.Text = DataGridView1.Item(8, DataGrid).Value
            TextBox9.Text = DataGridView1.Item(9, DataGrid).Value
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Hitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hitung.Click
        Try
            TextBox10.Text = TextBox8.Text - TextBox7.Text
        Catch ex As Exception
            MsgBox("Gagal Hitung", vbCritical, "ERROR")
        End Try
        Try
            TextBox9.Text = TextBox3.Text - TextBox6.Text
        Catch ex As Exception
        End Try
        Try
            Dim Format2 As Long
            Format2 = TextBox10.Text
            TextBox10.Text = Format(Format2, "Rp, #,##0")
        Catch ex As Exception
        End Try
    End Sub
    Private Sub TextBox8_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged
        Try
            TextBox9.Text = TextBox3.Text - TextBox6.Text
        Catch ex As Exception
        End Try
        Dim Format2 As Long
        If TextBox8.Text = "" Or Not IsNumeric(TextBox6.Text) Then
            Exit Sub
        End If
        Format2 = TextBox8.Text
        TextBox8.Text = Format(Format2, "Rp, #,##0")
        TextBox8.SelectionStart = Len(TextBox8.Text)
    End Sub
    Private Sub Segarkan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Segarkan.Click
        DataGridView1.RefreshEdit()
        DataGridView1.Refresh()
        HapusDataInput()
        SisaSaldo()
    End Sub
    Private Sub bKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bKeluar.Click
        Dim Keluar
        Keluar = MsgBox("Beneran Tah BOSS Arep Metu???", vbYesNo, "Konfirmasi")
        If Keluar = vbYes Then
            Close()
        End If
        If Keluar = vbNo Then Exit Sub
    End Sub
    Sub datagride()
        Dim Format1
        Format1 = Format("Rp 0,0")
        DataGridView1.Columns.Item(2).DefaultCellStyle.Format = Format1
        DataGridView1.Columns.Item(6).DefaultCellStyle.Format = Format1
        DataGridView1.Columns.Item(7).DefaultCellStyle.Format = Format1
        DataGridView1.Columns.Item(8).DefaultCellStyle.Format = Format1
        DataGridView1.Columns.Item(9).DefaultCellStyle.Format = Format1
        DataGridView1.Columns.Item(9).DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight
    End Sub
    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        Dim Format2 As Long
        If TextBox3.Text = "" Or Not IsNumeric(TextBox3.Text) Then
            Exit Sub
        End If
        Format2 = TextBox3.Text
        TextBox3.Text = Format(Format2, "Rp, #,##0")
        TextBox3.SelectionStart = Len(TextBox3.Text)
    End Sub
    Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged
        Dim Format2 As Long
        If TextBox6.Text = "" Or Not IsNumeric(TextBox6.Text) Then
            Exit Sub
        End If
        Format2 = TextBox6.Text
        TextBox6.Text = Format(Format2, "Rp, #,##0")
        TextBox6.SelectionStart = Len(TextBox6.Text)
    End Sub
    Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged
        Dim Format2 As Long
        If TextBox7.Text = "" Or Not IsNumeric(TextBox7.Text) Then
            Exit Sub
        End If
        Format2 = TextBox7.Text
        TextBox7.Text = Format(Format2, "Rp, #,##0")
        TextBox7.SelectionStart = Len(TextBox7.Text)
    End Sub
    Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged
        Dim Format2 As Long
        If TextBox9.Text = "" Or Not IsNumeric(TextBox9.Text) Then
            Exit Sub
        End If
        Format2 = TextBox9.Text
        TextBox9.Text = Format(Format2, "Rp, #,##0")
        TextBox9.SelectionStart = Len(TextBox9.Text)
    End Sub
    Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Format2 As Long
        If TextBox10.Text = "" Or Not IsNumeric(TextBox10.Text) Then
            Exit Sub
        End If
        Format2 = TextBox10.Text
        TextBox10.Text = Format(Format2, "Rp, #,##0")
        TextBox10.SelectionStart = Len(TextBox10.Text)
    End Sub
    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        TextBox4.CharacterCasing = CharacterCasing.Upper
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        TextBox2.Text = Format(Now, "hh:mm:ss")
    End Sub
    Sub suara()
    End Sub
End Class


NB. Masih Pemula

0 komentar: