cursosr

Blogger Widgets

Kamis, 17 Juli 2014

Membuat login dengan database access

Langkah 1 : siapkan database nya , seperti berikut ini


Langkah 2 : Membuat form Login menggunakan vbnet 2010 , formnya seperti berikut
Langkah 3 : membuat form mainform , designnya seperti berikut
 
Langkah 4 : Membuat form Manager User , designnya seperti berikut 
tuliskan koding ini pada form Login
Public Class Frmlogin
    Dim conString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\ΔTugas KampusΔ\©SEMESTER 4©\PEMROGRAMAN VISUAL II\BarangBarcode\BarangBarcode\bin\Debug\barcode.accdb"

    Dim kon As New OleDb.OleDbConnection(ConString)
    Dim cmd As New OleDb.OleDbCommand
    Dim dr As OleDb.OleDbDataReader
    Private Sub btCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCard.Click
        txtcard.Focus()
    End Sub

    Private Sub txtpin_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpin.TextChanged
        txtpin.Focus()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim idcard As String = txtcard.Text.Trim
        Dim pin As String = txtpin.Text.Trim

        Dim sql As String = "SELECT*FROM Login " & _
                            "WHERE idKasir ='" & idcard & "' AND " & _
                            "pin='" & pin & "'"
        kon.Open()
        cmd.CommandText = sql
        cmd.Connection = kon
        dr = cmd.ExecuteReader
        Dim nama As String = Nothing
        Dim user As Byte = 0


        If dr.HasRows Then
            While dr.Read

                nama = dr.Item("nama").ToString.Trim
                user = dr.Item(3).ToString
            End While

            Mainform.Show()
            Mainform.btnpos.Enabled = False
            Mainform.btnReport.Enabled = False
            Mainform.btnmanager.Enabled = False

            Select Case user
                Case 0
                    Mainform.btnmanager.Enabled = True
                Case 1
                    Mainform.btnpos.Enabled = True
                Case 2
                    Mainform.btnReport.Enabled = True

            End Select
            Mainform.lbllogged.Text = "Log in as : " & nama
            Mainform.lbltime.Text = "Time Log in : " & Now


            Me.Close()


        Else
            MsgBox("Your card or pin is incalid, please try again !")

        End If
        kon.Close()
    End Sub

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

    End Sub
End Class

Setelah itu Ketikan koding ini pada form mainform
Private Sub btnmanager_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmanager.Click
        manageruser.ShowDialog()
    End Sub
Setelah itu ketikan koding ini pada form MenuUser
Public Class manageruser

    Dim conString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\ΔTugas KampusΔ\©SEMESTER 4©\PEMROGRAMAN VISUAL II\BarangBarcode\BarangBarcode\bin\Debug\barcode.accdb"

    Dim kon As New OleDb.OleDbConnection(conString)
    Dim cmd As New OleDb.OleDbCommand
    Dim dr As OleDb.OleDbDataReader



    Private Sub lblclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblclose.Click
        Me.Close()

    End Sub

    Private Sub btnback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnback.Click
        Me.Close()

    End Sub
    Private Sub simpanuser()
        Dim sql As String = "INSERT INTO login VALUES('" & _
            txtuser.Text.Trim & "', '" & _
            txtname.Text.Trim & "','" & _
            txtpin.Text.Trim & "','" & _
            cmbprivilages.SelectedIndex & "')"
        kon.Open()
        cmd.CommandText = sql
        cmd.Connection = kon
        cmd.ExecuteNonQuery()
        kon.Close()
        Call bersih()



    End Sub
    Private Sub bersih()
        txtuser.Clear()
        txtname.Clear()
        txtpin.Clear()
        cmbprivilages.SelectedIndex = 0


    End Sub
    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Call simpanuser()

    End Sub

    Private Sub manageruser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmbprivilages.Items.AddRange({"Power User ", " Kasir", "User"})



    End Sub

    Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnedit.Click

        Dim sql As String = "UPDATE  login SET nama('" & _
           txtuser.Text.Trim & "', '" & _
           txtname.Text.Trim & "','" & _
           txtpin.Text.Trim & "','" & _
           cmbprivilages.SelectedIndex & "')"
       kon.Open()
        cmd.CommandText = sql
        cmd.Connection = kon
        cmd.ExecuteNonQuery()
        kon.Close()
        Call bersih()



    End Sub

    Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
        Dim sqlquery As New OleDb.OleDbCommand
        sqlquery.Connection = kon
        sqlquery.CommandType = CommandType.Text
        sqlquery.CommandText = "Delete from Login where idKasir  = '" &
        txtuser.Text & "'"
        sqlquery.ExecuteNonQuery()
        MsgBox("Data Dihapus")
        Call bersih()



    End Sub

    Private Sub cmbprivilages_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbprivilages.SelectedIndexChanged

    End Sub

    Private Sub txtuser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtuser.TextChanged

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class














Aplikasi Kalkulator


 sebelumnya buat form nya sebagai berikut :


Public Class Form1

    Dim operandi1 As Double
    Dim [operator] As String
    Dim baru As Boolean = True
    Dim temp As Double
    Dim operand2 As Double
    Dim OPH As Boolean = False

    Private Property operand1 As Double



    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "0"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "0"
        End If


           


    End Sub

    Private Sub btntambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntambah.Click
        If baru = True Then
            operandi1 = Val(TextBox1.Text)
            TextBox1.Text = ""
            TextBox1.Focus()
            [operator] = "+"
        ElseIf baru = False Then
            If [operator] = "+" Then
                temp = operandi1 + Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "+"
            ElseIf [operator] = "-" Then
                temp = operandi1 - Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "+"
            ElseIf [operator] = "x" Then
                temp = operandi1 * Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "+"
            ElseIf [operator] = ":" Then
                temp = operandi1 / Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "+"
            End If

        End If

        baru = False

    End Sub

    Private Sub btnkurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkurang.Click
        If baru = True Then
            operandi1 = Val(TextBox1.Text)
            TextBox1.Text = ""
            TextBox1.Focus()
            [operator] = "-"
        ElseIf baru = False Then
            If [operator] = "+" Then
                temp = operandi1 + Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "-"
            ElseIf [operator] = "-" Then
                temp = operandi1 - Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "-"
            ElseIf [operator] = "x" Then
                temp = operandi1 * Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "-"
            ElseIf [operator] = ":" Then
                temp = operandi1 / Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "-"
            End If

        End If

        baru = False



    End Sub

    Private Sub btnkali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkali.Click
        If baru = True Then
            operandi1 = Val(TextBox1.Text)
            TextBox1.Text = ""
            TextBox1.Focus()
            [operator] = "x"
        ElseIf baru = False Then

            If [operator] = "+" Then
                temp = operandi1 + Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "x"
            ElseIf [operator] = "-" Then
                temp = operandi1 - Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "x"
            ElseIf [operator] = ";" Then
                temp = operand1() / Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "x"
            ElseIf [operator] = "x" Then
                temp = operand1() * Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = "x"
            End If

        End If

        baru = False

    End Sub

    Private Sub btnbagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbagi.Click
        If baru = True Then
            operandi1 = Val(TextBox1.Text)
            TextBox1.Text = ""
            TextBox1.Focus()
            [operator] = ":"
        ElseIf baru = False Then
            If [operator] = "+" Then
                temp = operand1() + Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = ":"
            ElseIf [operator] = "-" Then
                temp = operand1() - Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = ":"
            ElseIf [operator] = "x" Then
                temp = operand1() * Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = ":"
            ElseIf [operator] = ":" Then
                temp = operand1() / Val(TextBox1.Text)
                operandi1 = temp
                TextBox1.Text = ""
                [operator] = ":"
            End If

        End If

        baru = False
    End Sub

    Private Sub btnsamadengan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsamadengan.Click
        Dim hasil As Double
        operand2 = Val(TextBox1.Text)

        Select Case [operator]

            Case "+"
                hasil = operandi1 + operand2
                TextBox1.Text = hasil.ToString
                baru = True
            Case "-"
                hasil = operandi1 - operand2
                TextBox1.Text = hasil.ToString
            Case ":"
                hasil = operandi1 / operand2
                TextBox1.Text = hasil.ToString
            Case "x"
                hasil = operandi1 * operand2
                TextBox1.Text = hasil.ToString
                baru = True
        End Select

        TextBox1.Text = hasil.ToString

    End Sub

   

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        TextBox1.Text = ""
        operandi1 = 0
        temp = 0
        baru = True

    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "1"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "1"
        End If
    End Sub


    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "2"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "2"
        End If
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "3"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "3"
        End If
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "4"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "4"
        End If
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "5"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "5"
        End If
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "6"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "6"
        End If
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "7"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "7"
        End If
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "8"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "8"
        End If
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        If OPH = True Or TextBox1.Text = "0" Then
            TextBox1.Text = "9"
            OPH = False
        Else
            TextBox1.Text = TextBox1.Text + "9"
        End If
    End Sub

   

    Private Sub btntitik_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntitik.Click
        If InStr(TextBox1.Text, ".") > 0 Then
            Exit Sub
        Else
            TextBox1.Text = TextBox1.Text & "."
        End If
    End Sub

   

End Class