Kamis, 25 Mei 2017

UAS LAB SMBD

Aplikasi ini digunakan untuk pihak management hotel untuk menyimpan data dari konsumennya. dalam aplikasi ini hotel dapat insert, delete,update,view, dan search





Imports System.Data
Imports System.Data.OleDb

Public Class WebForm1
    Inherits System.Web.UI.Page
    Public constring As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    Public oConn As New OleDbConnection(constring)
    Public oTbl As New DataTable
    Public xReader As OleDbDataReader







    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sql As String = "INSERT INTO Table_Konsumen VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
        Dim oCmd As New OleDbCommand
        oConn.Open()
        oCmd.Connection = oConn
        oCmd.CommandText = sql
        oCmd.ExecuteNonQuery()
    End Sub


    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim hapus = MsgBox("Authentication", MsgBoxStyle.YesNo, "Delete")


        If hapus = vbYes Then
            oConn.Close()
            oConn.Open()
            Dim delet As String = "DELETE FROM Table_Konsumen where IDKonsumen ='" + TextBox1.Text + "'"
            Dim oCmd As New OleDbCommand
            oConn.Close()
            oConn.Open()
            oCmd.Connection = oConn
            oCmd.CommandText = delet
            oCmd.ExecuteNonQuery()
            MsgBox("Sudah terhapus", vbArchive)


            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""


        End If


    End Sub

    Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Response.Redirect("WebForm2.aspx")


    End Sub

    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim sql As String = " UPDATE Table_Hotel set KodeHotel ='" & TextBox1.Text & "', KodeKamar = '" & TextBox2.Text & "', NamaKonsumen = '" & TextBox4.Text & "', Status = '" & TextBox5.Text & "' where IDKonsumen = '" & TextBox1.Text & "' "

        Dim oCmd As New OleDbCommand
        oConn.Close()
        oConn.Open()
        oCmd.Connection = oConn
        oCmd.CommandText = sql

        oCmd.ExecuteNonQuery()


    End Sub

    Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        oConn.Close()
        oConn.Open()
        Dim Cmd As New OleDbCommand("SELECT * FROM Table_Konsumen where IDKonsumen ='" + TextBox1.Text + "'", oConn)
        xReader = Cmd.ExecuteReader
        If xReader.HasRows Then
            xReader.Read()
            TextBox2.Text = xReader("KodeHotel")
            TextBox3.Text = xReader("KodeKamar")
            TextBox4.Text = xReader("NamaKonsumen")
            TextBox5.Text = xReader("Status")




        Else
            MsgBox("Consumer Not Found")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
            TextBox4.Text = ""
            TextBox5.Text = ""


            Exit Sub
        End If
        xReader.Close()

    End Sub
End Class