Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'I have this code to run
- 'But this require a lot of time if there is a lot of data
- Private Sub getAllItem()
- Try
- pnlAllItem.Controls.Clear()
- Dim jumlah As Integer = 0
- Dim left As Integer = 0
- Dim top As Integer = 0
- Dim total As Integer = 1
- left = 10
- top = 10
- conn.Close()
- conn.Open()
- Dim cmd As New MySqlCommand("SELECT * FROM tb_item", conn)
- Dim dr As MySqlDataReader = cmd.ExecuteReader()
- If dr.HasRows Then
- While dr.Read()
- 'Create dynamic object
- 'Picture
- Dim pic As New PictureBox
- If dr.GetValue(2).ToString = "" Then
- pic.Image = My.Resources.an
- pic.Size = New Size(120, 120)
- Else
- Using Mem As New IO.MemoryStream(dr.GetValue(2), True)
- pic.Image = CType(Image.FromStream(Mem).Clone(), Image)
- pic.Size = New Size(120, 120)
- End Using
- End If
- pic.Name = dr.GetValue(0).ToString
- pic.SizeMode = PictureBoxSizeMode.StretchImage
- pic.Cursor = Cursors.Hand
- pic.Location = New Point(left, top)
- pnlAllItem.Controls.Add(pic)
- 'Label for Product Name
- Dim lbl As New Label
- lbl.Name = "lbl" & dr.GetValue(0).ToString
- lbl.Size = New Size(290, 18)
- lbl.Font = New Drawing.Font("Maiandra GD", 12, FontStyle.Bold)
- lbl.Text = dr.GetValue(1).ToString
- lbl.Location = New Point(left + pic.Width + 10, top)
- pnlAllItem.Controls.Add(lbl)
- 'Label for Description
- Dim lbl2 As New Label
- lbl2.Name = "lbl2" & dr.GetValue(0).ToString
- lbl2.Size = New Size(290, 70)
- lbl2.Font = New Drawing.Font("Microsoft Sans Serif", 8)
- lbl2.Text = dr.GetValue(3).ToString
- lbl2.Location = New Point(left + pic.Width + 10, top + lbl.Height + 6)
- pnlAllItem.Controls.Add(lbl2)
- 'Label for Price and discon
- Dim diskon As Double = dr.GetValue(8)
- Dim harga As Double = dr.GetValue(5)
- Dim hasil As Double
- hasil = harga - (harga * (diskon / 100))
- Dim lbl3 As New Label
- lbl3.Name = "lbl3" & dr.GetValue(0).ToString
- lbl3.Size = New Size(290, 18)
- lbl3.Font = New Drawing.Font("Microsoft Sans Serif", 9, FontStyle.Italic)
- If Not dr.GetValue(8) = 0 Then
- lbl3.Text = dr.GetValue(4).ToString & dr.GetValue(5).ToString & " Diskon " & dr.GetValue(8).ToString & "% => " & dr.GetValue(4).ToString & hasil.ToString
- Else
- lbl3.Text = dr.GetValue(4).ToString & dr.GetValue(5).ToString
- End If
- lbl3.Location = New Point(left + pic.Width + 10, lbl2.Top + 80)
- pnlAllItem.Controls.Add(lbl3)
- 'handler
- AddHandler pic.Click, AddressOf HandlerDynamicObjectClick
- jumlah += 1
- If total = 1 Then
- left += 500
- total += 1
- ElseIf total = 2 Then
- top += 180
- left -= 500
- total = 1
- End If
- End While
- End If
- Catch ex As Exception
- 'MsgBox(ex.Message)
- End Try
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement