Program Maintainance Barang(VB.NET , Sql Database)

Posted: November 24, 2011 in Pemrograman Basis Data ( PBD )

Imports System.Data.SqlClient
Public Class Form1
Dim cs As String = “Data Source = FIFIFARISTIA\SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = true”
Dim ocs As New SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ocs = New SqlConnection(cs)
ocs.Open()
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Product()
Supplier()
Category()
End Sub

Sub Product()
cmd = New SqlCommand(“select productid from products”, ocs)
dr = cmd.ExecuteReader()
While dr.Read()
Me.ComboBox1.Items.Add(dr.Item(0))
End While
dr.Close()
End Sub

Sub Supplier()
cmd = New SqlCommand(“select supplierid from suppliers”, ocs)
dr = cmd.ExecuteReader()
While dr.Read()
Me.ComboBox2.Items.Add(dr.Item(0))
End While
dr.Close()
End Sub

Sub Category()
cmd = New SqlCommand(“select categoryid from categories”, ocs)
dr = cmd.ExecuteReader()
While dr.Read()
Me.ComboBox3.Items.Add(dr.Item(0))
End While
dr.Close()
End Sub

Sub clear()
ComboBox1.Text = “”
ComboBox2.Text = “”
ComboBox3.Text = “”
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
End Sub

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

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tampil As String = ComboBox1.Text
cmd = New SqlCommand(“select ProductName, suppliers.SupplierID, categories.CategoryID” & _
“, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel” & _
“, Discontinued from Products inner join suppliers on products.[SupplierID] =” & _
” suppliers.[SupplierID] join Categories on products.categoryid =” & _
” categories.categoryid where ProductID = ‘” & tampil & “‘”, ocs)
dr = cmd.ExecuteReader()
If dr.HasRows = True Then
While (dr.Read())
TextBox1.Text = (dr.Item(0))
ComboBox2.Text = (dr.Item(1))
ComboBox3.Text = (dr.Item(2))
TextBox2.Text = (dr.Item(3))
TextBox3.Text = (dr.Item(4))
TextBox4.Text = (dr.Item(5))
TextBox5.Text = (dr.Item(6))
TextBox6.Text = (dr.Item(7))
TextBox7.Text = (dr.Item(8))
End While
End If
dr.Close()
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
cmd = New SqlCommand(“select count(productID)+1 from products”, ocs)
dr = cmd.ExecuteReader()
If dr.HasRows = True Then
While (dr.Read())
Button1.Text = (dr.Item(0))
End While
End If
dr.Close()
cmd = New SqlCommand(“insert into products values(‘” & ComboBox1.Text & “‘,'” & TextBox1.Text & _
“‘,'” & ComboBox2.Text & “‘,'” & ComboBox3.Text & “‘,'” & _
TextBox2.Text & “‘,'” & TextBox3.Text & “‘,'” & TextBox4.Text & _
“‘,'” & TextBox5.Text & “‘,'” & TextBox6.Text & “‘,'” & _
TextBox7.Text & “‘)”, ocs)
cmd.ExecuteNonQuery()
MsgBox(“Telah tersimpan”)
clear()
Product()
Supplier()
Category()
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
End Sub

Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim edit As Integer = ComboBox1.Text
cmd = New SqlCommand(“update products set productname = ‘” & TextBox1.Text & “‘, SupplierID = ‘” & ComboBox2.Text & _
“‘,CategoryID = ‘” & ComboBox3.Text & “‘,QuantityPerUnit='” & TextBox2.Text & _
“‘,UnitPrice='” & TextBox3.Text & “‘,UnitsInStock='” & TextBox4.Text & _
“‘,UnitsOnOrder='” & TextBox5.Text & “‘,ReorderLevel='” & TextBox6.Text & _
“‘,Discontinued='” & TextBox7.Text & “‘where (ProductID='” & edit & “‘)”, ocs)
cmd.ExecuteNonQuery()
MsgBox(“telah terupdate”)
clear()
Product()
Supplier()
Category()
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
End Sub

Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim delete As Integer = ComboBox1.Text
cmd = New SqlCommand(“delete from Products where ProductID = ‘” & delete & “‘”, ocs)
cmd.ExecuteNonQuery()
MsgBox(“telah terhapus”)
clear()
Product()
Supplier()
Category()
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
End Sub
End Class


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s