"TEKNIK INFORMATIKA-09"

.
Diberdayakan oleh Blogger.

Tugas UAS VB.Net Koneksi SQL Server


Aplikasi Cuti Mahasiswa

1.Form Login

Public Class Form_Login
    Public database As New OleDb.OleDbConnection
    Public a As New OleDb.OleDbCommand
    Public b As OleDb.OleDbDataReader
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.Focus()
    End Sub
    Sub netral()
        Button1.Text = "LOGIN"
        Button2.Text = "BATAL"
        Button1.Enabled = True
        Button2.Enabled = True
        TextBox1.Enabled = True
    End Sub
  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call koneksi()
        Try
            Tampil.Connection = database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormLogin where Kode_Petugas = '" & TextBox1.Text & "'and Password='" & TextBox2.Text & "'"
            Tampilkan = Tampil.ExecuteReader
            If Tampilkan.HasRows = True Then
                Form_Aplikasi.Show()
                Me.Visible = False

            Else
                MsgBox("Kode_Petugas dan Password anda salah")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub
    Private Sub koneksi()
        Try
            database.Close()
            database.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Login;Data Source=."
            database.Open()
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        If Button2.Text = "BATAL" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub
End Class

2.Form Aplikasi

 
Public Class Form_Aplikasi
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form_Cuti_Mahasiswa.Show()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form_Jurusan.Show()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Form_Pembayaran_Cuti.Show()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form_Petugas.Show()
    End Sub
End Class

3.Form Petugas

Public Class Form_Petugas
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox1.Focus()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call SIMPAN()
    End Sub
    Sub SIMPAN()
        If Button1.Text = "INSERT" Then
            TextBox1.Text = ""
            Button1.Text = "ADD"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()

                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into FormPetugas (Kode_Petugas,Nama_Petugas,Password,Status,Ket)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call Kosong()
                Else
                    MsgBox("Cek data yang di input", MsgBoxStyle.Critical, "Input data")
                    TextBox1.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from FormPetugas where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader

        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then

            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormPetugas where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader

            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Petugas")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Nama_Petugas")
                        TextBox3.Text = Tampilkan("Password")
                        TextBox4.Text = Tampilkan("Status")
                        TextBox5.Text = Tampilkan("Ket")

                    End If
                End While
            Else
                MsgBox("DATA TIDAK ADA DI DATABASE", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ADD DATA")
            End If
        Else
        End If
    End Sub
    Sub netral()
        Button1.Text = "INSERT"
        Button2.Text = "UPDATE"
        Button3.Text = "DELETE"
        Button4.Text = "EXIT"
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call EDIT()
    End Sub
    Sub EDIT()
        If Button2.Text = "UPDATE" Then
            TextBox1.Text = ""
            Button2.Text = "OK BOSS"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Update FormPetugas set Nama_Petugas ='" & Trim(TextBox2.Text) & "',Password ='" & TextBox3.Text & "',Status='" & TextBox4.Text & "',Ket='" & TextBox5.Text & " '" & " where Kode_Jurusan='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call HAPUS()
    End Sub
    Sub HAPUS()
        If Button3.Text = "DELETE" Then
            TextBox1.Text = ""
            Button3.Text = "YAKIN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text

                Tampil.CommandText = "Delete from FormPetugas where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()

                Call Kosong()
                TextBox1.Focus()

            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "EXIT" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub
End Class

4.Form Jurusan

 
Public Class Form_Jurusan
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.Focus()
    End Sub
    Sub netral()
        Button1.Text = "INSERT"
        Button2.Text = "UPDATE"
        Button3.Text = "DELETE"
        Button4.Text = "EXIT"
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call SIMPAN()
    End Sub
    Sub SIMPAN()
        If Button1.Text = "INSERT" Then
            TextBox1.Text = ""
            Button1.Text = "SIAP COY"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()

                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into FormJurusan (Kode_Jurusan,Jurusan)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call Kosong()
                Else
                    MsgBox("Cek data yang di input", MsgBoxStyle.Critical, "Input data")
                    TextBox1.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from FormJurusan where Kode_Jurusan='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader

        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then

            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormJurusan where Kode_Jurusan='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader

            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Jurusan")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Jurusan")

                    End If
                End While
            Else
                MsgBox("DATA TIDAK ADA DI DATABASE", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ADD DATA")
            End If
        Else
        End If
    End Sub
    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call EDIT()
    End Sub
    Sub EDIT()
        If Button2.Text = "UPDATE" Then
            TextBox1.Text = ""
            Button2.Text = "OK BOSS"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Update FormJurusan set Jurusan ='" & Trim(TextBox2.Text) & "' where Kode_Jurusan='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "EXIT" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call HAPUS()
    End Sub
    Sub HAPUS()
        If Button3.Text = "DELETE" Then
            TextBox1.Text = ""
            Button3.Text = "YAKIN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text

                Tampil.CommandText = "Delete from FormJurusan where Kode_Jurusan='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()

                Call Kosong()
                TextBox1.Focus()

            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
End Class

5.Form Cuti Mahasiswa

 
Public Class Form_Cuti_Mahasiswa
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox1.Focus()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call SIMPAN()
    End Sub
    Sub SIMPAN()
        If Button1.Text = "INSERT" Then
            TextBox1.Text = ""
            Button1.Text = "ADD"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()

                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into FormCuti (NPM,NAMA,JURUSAN,KELAS,CUTISMTR,THNAKADEMIK,ALASANCUTI,TANGGAL)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call Kosong()
                Else
                    MsgBox("Cek data yang di input", MsgBoxStyle.Critical, "Input data")
                    TextBox1.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from FormCuti where NPM='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader

        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then

            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormCuti where NPM='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader

            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("NPM")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("NAMA")
                        TextBox3.Text = Tampilkan("JURUSAN")
                        TextBox4.Text = Tampilkan("KELAS")
                        TextBox5.Text = Tampilkan("CUTISMTR")
                        TextBox6.Text = Tampilkan("THNAKADEMIK")
                        TextBox7.Text = Tampilkan("ALASANCUTI")
                        TextBox8.Text = Tampilkan("TANGGAL")

                    End If
                End While
            Else
                MsgBox("DATA TIDAK ADA DI DATABASE", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ADD DATA")
            End If
        Else
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "EXIT" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub
    Sub netral()
        Button1.Text = "INSERT"
        Button2.Text = "UPDATE"
        Button3.Text = "DELETE"
        Button4.Text = "EXIT"
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call EDIT()
    End Sub
    Sub EDIT()
        If Button2.Text = "UPDATE" Then
            TextBox1.Text = ""
            Button2.Text = "OK BOSS"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Update FormCuti set NAMA ='" & Trim(TextBox2.Text) & "',JURUSAN ='" & TextBox3.Text & "',KELAS='" & TextBox4.Text & "',CUTISMTR='" & TextBox5.Text & "',THNAKADEMIK='" & TextBox6.Text & "',ALASANCUTI='" & TextBox7.Text & "',TANGGAL='" & TextBox8.Text & " '" & " where NPM='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call HAPUS()
    End Sub
    Sub HAPUS()
        If Button3.Text = "DELETE" Then
            TextBox1.Text = ""
            Button3.Text = "YAKIN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text

                Tampil.CommandText = "Delete from FormCuti where NPM='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()

                Call Kosong()
                TextBox1.Focus()

            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
End Class
 
6.Form Pembayaran Cuti

 
Public Class Form_Pembayaran_Cuti
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        TextBox10.Text = ""
        TextBox11.Text = ""
        TextBox12.Text = ""
        TextBox1.Focus()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call SIMPAN()
    End Sub
    Sub SIMPAN()
        If Button1.Text = "INSERT" Then
            TextBox1.Text = ""
            Button1.Text = "ADD"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()

                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into FormPembayaran (NOKWITANSI,NPM,NAMA,JURUSAN,KELAS,WAKTUKULIAH,TGLBAYAR,SMTCUTI,THNAKADEMIK,BIAYACUTI,TERBILANG,KODEPETUGAS)values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox11.Text & "','" & TextBox12.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call Kosong()
                Else
                    MsgBox("Cek data yang di input", MsgBoxStyle.Critical, "Input data")
                    TextBox1.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from FormPembayaran where NOKWITANSI='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader

        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then

            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormPembayaran where NOKWITANSI='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader

            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("NOKWITANSI")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("NPM")
                        TextBox3.Text = Tampilkan("NAMA")
                        TextBox4.Text = Tampilkan("JURUSAN")
                        TextBox5.Text = Tampilkan("KELAS")
                        TextBox6.Text = Tampilkan("WAKTUKULIAH")
                        TextBox7.Text = Tampilkan("TGLBAYAR")
                        TextBox8.Text = Tampilkan("SMTCUTI")
                        TextBox9.Text = Tampilkan("THNAKADEMIK")
                        TextBox10.Text = Tampilkan("BIAYACUTI")
                        TextBox11.Text = Tampilkan("TERBILANG")
                        TextBox12.Text = Tampilkan("KODEPETUGAS")

                    End If
                End While
            Else
                MsgBox("DATA TIDAK ADA DI DATABASE", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ADD DATA")
            End If
        Else
        End If
    End Sub
    Sub netral()
        Button1.Text = "INSERT"
        Button2.Text = "UPDATE"
        Button3.Text = "DELETE"
        Button4.Text = "EXIT"
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call HAPUS()
    End Sub
    Sub HAPUS()
        If Button3.Text = "DELETE" Then
            TextBox1.Text = ""
            Button3.Text = "YAKIN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Delete from FormPembayaran where NOKWITANSI='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "EXIT" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call EDIT()
    End Sub
    Sub EDIT()
        If Button2.Text = "UPDATE" Then
            TextBox1.Text = ""
            Button2.Text = "OK BOSS"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()
                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "update FormPembayaran set NOKWITANSI ='" & Trim(TextBox2.Text) & "',NAMA ='" & TextBox3.Text & "',JURUSAN='" & TextBox4.Text & "',KELAS='" & TextBox5.Text & "',WAKTUKULIAH='" & TextBox6.Text & "',TGLBAYAR='" & TextBox7.Text & "',SMTCUTI='" & TextBox8.Text & "',THNAKADEMIK='" & TextBox9.Text & "',BIAYACUTI='" & TextBox10.Text & "',TERBILANG='" & TextBox11.Text & "',KODEPETUGAS='" & TextBox12.Text & " '" & " where NOKWITANSI='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
End Class

7.Form User

Public Class Form_User
    Sub Kosong()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.Focus()
    End Sub
    Sub netral()
        Button1.Text = "SAVE"
        Button2.Text = "UPDATE"
        Button3.Text = "DELETE"
        Button4.Text = "EXIT"
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        TextBox1.Enabled = True
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call SIMPAN()
    End Sub
    Sub SIMPAN()
        If Button1.Text = "SAVE" Then
            TextBox1.Text = ""
            Button1.Text = "OK"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            'TextBox1.Enabled = False
            TextBox1.Focus()
        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Call cekrecord()
            Try
                If hasilcek = "False" Then
                    Call Koneksi()

                    Tampil.Connection = Database
                    Tampil.CommandType = CommandType.Text
                    Tampil.CommandText = "Insert into FormUser (Kode_Petugas,Password)values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
                    Tampil.ExecuteNonQuery()
                    Call Kosong()
                Else
                    MsgBox("Cek data yang di input", MsgBoxStyle.Critical, "Input data")
                    TextBox1.Focus()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
    Sub cekrecord()
        Call Koneksi()
        Tampil.Connection = Database
        Tampil.CommandType = CommandType.Text
        Tampil.CommandText = "select * from FormUser where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
        Tampilkan = Tampil.ExecuteReader

        If Tampilkan.HasRows = True Then
            hasilcek = True
        Else
            hasilcek = False
        End If
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then

            Call cekrecord()
            Call Koneksi()
            Tampil.Connection = Database
            Tampil.CommandType = CommandType.Text
            Tampil.CommandText = "select * from FormUser where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
            Tampilkan = Tampil.ExecuteReader

            If Tampilkan.HasRows = True Then
                While Tampilkan.Read()
                    If IsDBNull(Tampilkan("Kode_Petugas")) Then
                        TextBox1.Focus()
                    Else
                        TextBox2.Text = Tampilkan("Password")

                    End If
                End While
            Else
                MsgBox("DATA TIDAK ADA DI DATABASE", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "ADD DATA")
            End If
        Else
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "EXIT" Then
            Me.Close()
        Else
            Call Kosong()
            Call netral()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call HAPUS()
    End Sub
    Sub HAPUS()
        If Button3.Text = "DELETE" Then
            TextBox1.Text = ""
            Button3.Text = "YAKIN"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text

                Tampil.CommandText = "Delete from FormUser where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()

                Call Kosong()
                TextBox1.Focus()

            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call EDIT()
    End Sub
    Sub EDIT()
        If Button2.Text = "UPDATE" Then
            TextBox1.Text = ""
            Button2.Text = "OK BOSS"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "BATAL"
            TextBox1.Focus()

        Else
            If TextBox1.Text = "" Then Exit Sub
            If TextBox2.Text = "" Then Exit Sub
            Try
                Call Koneksi()

                Tampil.Connection = Database
                Tampil.CommandType = CommandType.Text
                Tampil.CommandText = "Update FormUser set Password ='" & Trim(TextBox2.Text) & "' where Kode_Petugas='" & Trim(TextBox1.Text) & "'"
                Tampil.ExecuteNonQuery()
                Call Kosong()
                TextBox1.Focus()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End If
    End Sub
End Class

0 komentar

Posting Komentar