Kamis, 06 Juni 2013

SISTEM INFORMASI DATA GURU



1.       FROM MENU
Public Class Form1

    Private Sub DataGuruToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGuruToolStripMenuItem.Click
        data_guru.Show()
    End Sub

    Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
        End
    End Sub
End Class

2.FROM MENU


Imports MySql.Data.MySqlClient
Public Class data_guru
    Public db As New MySql.Data.MySqlClient.MySqlConnection
    Public sql As String
    Public cmd As MySqlCommand
    Public rs As MySqlDataReader
    Sub opendb()
        sql = "server=localhost;uid=root;pwd;database=guru"
        Try
            db.ConnectionString = sql
            db.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Sub bersih()
        NIP.Text = ""
        Nama_Guru.Text = ""
        kd_mata_pelajaran.Text = ""
        Mata_pelajaran.Text = ""
        rubahbutton(True, False, False, False, False, True)
        NIP.Enabled = True
    End Sub
    Sub rubahbutton(ByVal btn1 As Boolean, ByVal btn2 As Boolean, ByVal btn3 As Boolean, ByVal btn4 As Boolean, ByVal btn5 As Boolean, ByVal btn6 As Boolean)
        btnbaru.Enabled = btn1
        btnsimpan.Enabled = btn2
        btnedit.Enabled = btn3
        btnhapus.Enabled = btn4
        btnbatal.Enabled = btn5
        btnkeluar.Enabled = btn6
    End Sub

    Sub buattable()
        lv.Columns.Add("NIP", 80, HorizontalAlignment.Center)
        lv.Columns.Add("NAMA GURU", 180, HorizontalAlignment.Left)
        lv.Columns.Add("kode mata pelajaran", 80, HorizontalAlignment.Left)
        lv.Columns.Add("mata pelajaran", 100, HorizontalAlignment.Left)
        lv.GridLines = True
        lv.FullRowSelect = True
        lv.View = View.Details
    End Sub
    Sub isitable()
        lv.Items.Clear()
        sql = "select * from guru"
        cmd = New MySqlCommand(sql, db)
        rs = cmd.ExecuteReader
        Try
            While rs.Read
                Dim lst As New ListViewItem
                lst.Text = rs("NIP")
                lst.SubItems.Add(rs("nama_guru"))
                lst.SubItems.Add(rs("kd_mata_pelajaran"))
                lst.SubItems.Add(rs("mata_pelajaran"))
                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 NIP(NIP,nama_guru,kd_mata_pelajaran,mata_pelajaran)" & _
                "values('" & NIP.Text & _
                "','" & Nama_Guru.Text & _
                "','" & kd_mata_pelajaran.Text & _
                "','" & Mata_pelajaran.Text & "')"
                pesan = "data telah tersimpan"
            Case 1
                sql = "update NIP set nama_guru='" & Nama_Guru.Text & "'," & _
                "kd_mata_pelajaran='" & kd_mata_pelajaran.Text & "'," & _
                "mata_pelajaran='" & Mata_pelajaran.Text & "'," & _
                "where NIP='" & NIP.Text & "'"
                pesan = "data telah terupdate"
            Case 2
                sql = "delete from guru where NIP='" & NIP.Text & "'"
                pesan = "data telah dihapus"
        End Select
        Try
            cmd = New MySqlCommand(sql, db)
            cmd.ExecuteNonQuery()
            MsgBox(pesan, MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "konfirmsi")
            Call bersih()
            Call isitable()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    Sub showdb()
        rs.Read()
        NIP.Text = rs("NIP")
        Nama_Guru.Text = rs("nama_guru")
        kd_mata_pelajaran.Text = rs("kd_mata_pelajaran")
        Mata_pelajaran.Text = rs("mata_pelajaran")
        rubahbutton(False, False, True, True, True, False)
        btnsimpan.text = "edit"
        NIP.Enabled = False
    End Sub
    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call opendb()
        Call bersih()
        Call buattable()
        Call isitable()
    End Sub

    Private Sub baru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbaru.Click
        Call bersih()
        NIP.Focus()
    End Sub

    Private Sub batal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        Call bersih()
        NIP.Focus()
    End Sub

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

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        Dim x As String
        x = MsgBox("anda yakin akan menghapus", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "hapus")
        If x = vbYes Then
            Call prosesdb(2)
        End If
    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        If btnsimpan.text = "simpan" Then prosesdb(0) Else prosesdb(1)
    End Sub

    Private Sub NIP_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NIP.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        If tombol = 13 Then
            Dim x As String
            If NIP.Text = "" Then
                MsgBox("isi NIP terlebih dahulu")
            Else
                sql = "select * from guru where NIP='" & NIP.Text & "'"
                cmd = New MySqlCommand(sql, db)
                rs = cmd.ExecuteReader
                Try
                    Call showdb()
                Catch ex As Exception
                    x = NIP.Text
                    bersih()
                    NIP.Text = x
                    rubahbutton(False, True, False, False, True, False)
                    btnsimpan.Text = "simpan"
                End Try
                Nama_Guru.Focus()
                rs.Close()
            End If
        End If
    End Sub
End Class

3.TAMPILAN FROM CETAK LAPORAN


DEMIKIANLAH HASIL POSTINGAN SAYA
NAMA: PALAR WIRANTA LUMBAN GAOL
NPM:1102391

Tidak ada komentar:

Posting Komentar