Kamis, 06 Juni 2013

Yuk…!! Belajar Pemrograman Visual Basik Dot Net Di Mesran.net




1      1. Form  Menu

Listing Program Menu
Public Class Form1
   
    Private Sub DokterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DokterToolStripMenuItem.Click
        dokter.Show()
    End Sub

    Private Sub KeluarProgramToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarProgramToolStripMenuItem.Click
        End
    End Sub

    Private Sub LaaporanDokterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LaaporanDokterToolStripMenuItem.Click
        laporan_dokter.Show()
    End Sub
End Class

        2. Form Input

Listing Program Input
Imports MySql.Data.MySqlClient
Public Class dokter
    Public db As New MySql.Data.MySqlClient.MySqlConnection
    Public sql As String
    Public cmd As MySqlCommand
    Public rs As MySqlDataReader

    Public Sub opendb()
        sql = "server=localhost;uid=root;pwd;database=dokter"
        Try
            db.ConnectionString = sql
            db.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Sub bersih()
        kode_dokter.Text = ""
        nama_dokter.Text = ""
        jenis_kelamin.Text = ""
        telepon.Text = ""
        spesialis.Text = ""
        tarif.Text = ""
        rubahtombol(True, False, False, False, True)
        kode_dokter.Enabled = True
    End Sub

    Sub rubahtombol(ByRef btn1 As Boolean, ByVal btn2 As Boolean, ByVal btn3 As Boolean, ByVal btn4 As Boolean, ByVal btn5 As Boolean)
        BR.Enabled = btn1
        SMPN.Enabled = btn2
        HPS.Enabled = btn3
        BTL.Enabled = btn4
        KLR.Enabled = btn5
    End Sub
    Sub buattabel()
        lv.Columns.Add("kode_dokter", 80, HorizontalAlignment.Center)
        lv.Columns.Add("nama_dokter", 180, HorizontalAlignment.Left)
        lv.Columns.Add("jenis_kelamin", 80, HorizontalAlignment.Left)
        lv.Columns.Add("telepon", 100, HorizontalAlignment.Left)
        lv.Columns.Add("spesialis", 100, HorizontalAlignment.Left)
        lv.Columns.Add("tarif", 100, HorizontalAlignment.Left)
        LV.GridLines = True
        LV.FullRowSelect = True
        LV.View = View.Details
    End Sub
    Sub isitabel()
        LV.Items.Clear()
        sql = "select*from dokter"
        cmd = New MySqlCommand(sql, db)
        rs = cmd.ExecuteReader
        Try
            While rs.Read
                Dim lst As New ListViewItem
                lst.Text = rs("kode_dokter")
                lst.SubItems.Add(rs("nama_dokter"))
                lst.SubItems.Add(rs("jenis_kelamin"))
                lst.SubItems.Add(rs("telepon"))
                lst.SubItems.Add(rs("spesialis"))
                lst.SubItems.Add(rs("tarif"))
                LV.Items.Add(lst)

            End While
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        rs.Close()
    End Sub
    Sub prosesdb(ByVal log As Integer)
        Dim pesan As String = ""
        Select Case log
            Case 0
                sql = "insert into dokter(kode_dokter,nama_dokter,jenis_kelamin,telepon,spesialis,tarif)" & _
                     "values('" & kode_dokter.Text & _
                     "','" & nama_dokter.Text & _
                     "','" & jenis_kelamin.Text & _
                     "','" & telepon.Text & _
                     "','" & spesialis.Text & _
                     "','" & tarif.Text & "')"
                pesan = "data telah tersimpan"
            Case 1
                sql = "update dokter set nama_dokter='" & nama_dokter.Text & "', " & _
                    "jenis_kelamin='" & jenis_kelamin.Text & "'," & _
                    "telepon='" & telepon.Text & "'," & _
                    "spesialis='" & spesialis.Text & "'," & _
                    "tarif='" & tarif.Text & "' " & _
                    "where kode_dokter='" & kode_dokter.Text & "'"
                pesan = "data telah terupdate"
            Case 2
                sql = "delete from dokter where kode_dokter='" & kode_dokter.Text & "'"
                pesan = "data telah dihapus"
        End Select
        Try
            cmd = New MySqlCommand(sql, db)
            cmd.ExecuteNonQuery()
            MsgBox(pesan, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "konfirmasi")
            Call bersih()
            Call isitabel()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Sub showdb()
        rs.Read()
        kode_dokter.Text = rs("kode_dokter")
        nama_dokter.Text = rs("nama_dokter")
        jenis_kelamin.Text = rs("jenis_kelamin")
        telepon.Text = rs("telepon")
        spesialis.Text = rs("spesialis")
        tarif.Text = rs("tarif")
        rubahtombol(False, True, True, True, True)
        SMPN.Text = "EDIT"
        kode_dokter.Enabled = False
    End Sub

    Private Sub dokter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call opendb()
        Call bersih()
        Call buattabel()
        Call isitabel()
        jenis_kelamin.Items.Add("laki-laki")
        jenis_kelamin.Items.Add("perempuan")
        spesialis.Items.Add("jantung")
        spesialis.Items.Add("paru-paru")
        spesialis.Items.Add("kandungan")
        spesialis.Items.Add("hati")
        spesialis.Items.Add("bedah")
        spesialis.Items.Add("THT")
    End Sub

    Private Sub BR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BR.Click
        Call bersih()
        kode_dokter.Focus()
    End Sub

    Private Sub BTL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTL.Click
        Call bersih()
        kode_dokter.Focus()
    End Sub

    Private Sub KLR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KLR.Click
        End
    End Sub

    Private Sub HPS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HPS.Click
        Dim x As String
        x = MsgBox("anda yakin akan dihapus", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "hapus")

        If x = vbYes Then
            Call prosesdb(2)
        End If
    End Sub

    Private Sub SMPN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMPN.Click
        If SMPN.Text = "SIMPAN" Then prosesdb(0) Else prosesdb(1)
    End Sub

    Private Sub kode_dokter_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles kode_dokter.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)

        If tombol = 13 Then
            Dim x As String

            If kode_dokter.Text = "" Then
                MsgBox("isi kode terlebih dahulu")
            Else
                sql = "select * from dokter where kode_dokter='" & kode_dokter.Text & "'"
                cmd = New MySqlCommand(sql, db)
                rs = cmd.ExecuteReader
                Try
                    Call showdb()
                Catch ex As Exception
                    x = kode_dokter.Text
                    bersih()
                    kode_dokter.Text = x
                    rubahtombol(False, True, False, True, False)
                    SMPN.Text = "SIMPAN"
                End Try
                nama_dokter.Focus()
                rs.Close()
            End If
        End If
    End Sub

    Private Sub spesialis_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles spesialis.SelectedIndexChanged
        If spesialis.Text = "jantung" Then tarif.Text = 100000000
        If spesialis.Text = "paru-paru" Then tarif.Text = 200000000
        If spesialis.Text = "kandungan" Then tarif.Text = 1000000
        If spesialis.Text = "hati" Then tarif.Text = 150000000
        If spesialis.Text = "bedah" Then tarif.Text = 2000000
        If spesialis.Text = "THT" Then tarif.Text = 100000
    End Sub
End Class



3. Desain Form Cetak Laporan

Listing Program Cetak Laporan
Public Class laporan_dokter

    Private Sub crv_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Laporan As New rptdokter
        With Me.crv
            .DisplayGroupTree = False
            .ReportSource = Laporan
            .Refresh()
        End With
    End Sub
End Class

Tampilan Form Cetak Laporan



  Demikianlah Postingan Saya NAMA: KIKI PERTIWI NPM: 1102126
 Selamat Belajar VB Net








Tidak ada komentar:

Posting Komentar